ddg.math.linalg module

Linear algebra utils

ddg.math.linalg.rank(A, atol=1e-13, rtol=None)[source]

Estimate the rank (i.e. the dimension of the nullspace) of a matrix.

The algorithm used by this function is based on the singular value decomposition of A.

Parameters:
Andarray

A should be at most 2-D. A 1-D array with length n will be treated as a 2-D with shape (1, n)

atolfloat

The absolute tolerance for a zero singular value. Singular values smaller than atol are considered to be zero.

rtolfloat

The relative tolerance. Singular values less than rtol*smax are considered to be zero, where smax is the largest singular value.

If both atol and rtol are positive, the combined tolerance is the maximum of the two; that is:

tol = max(atol, rtol * smax)

Singular values smaller than tol are considered to be zero.

Returns:
rint

The estimated rank of the matrix.

See also

numpy.linalg.matrix_rank

matrix_rank is basically the same as this function, but it does not provide the option of the absolute tolerance.

Notes

This function uses the global tolerance defaults if atol or rtol are set to None. See ddg.abc.NonExact for details.

ddg.math.linalg.nullspace(A, atol=1e-13, rtol=None)[source]

Compute an approximate basis for the nullspace of A.

The algorithm used by this function is based on the singular value decomposition of A.

Parameters:
Andarray

A should be at most 2-D. A 1-D array with length k will be treated as a 2-D with shape (1, k)

atolfloat

The absolute tolerance for a zero singular value. Singular values smaller than atol are considered to be zero.

rtolfloat

The relative tolerance. Singular values less than rtol*smax are considered to be zero, where smax is the largest singular value.

If both `atol` and `rtol` are positive, the combined tolerance is the
maximum of the two; that is::

tol = max(atol, rtol * smax)

Singular values smaller than `tol` are considered to be zero.
Returns:
nsndarray

If A is an array with shape (m, k), then ns will be an array with shape (k, n), where n is the estimated dimension of the nullspace of A. The columns of ns are a basis for the nullspace; each element in numpy.dot(A, ns) will be approximately zero.

Notes

This function uses the global tolerance defaults if atol or rtol are set to None. See ddg.abc.NonExact for details.

ddg.math.linalg.row_basis(A, atol=1e-13, rtol=None)[source]

Notes

This function uses the global tolerance defaults if atol or rtol are set to None. See ddg.abc.NonExact for details.

ddg.math.linalg.col_basis(A, atol=1e-13, rtol=None)[source]

Notes

This function uses the global tolerance defaults if atol or rtol are set to None. See ddg.abc.NonExact for details.

ddg.math.linalg.arrays_to_matrix(arrays)[source]

Converts a list of arrays to a matrix.

The arrays will be the columns (!) of the matrix.

Parameters:
arrayslist

List of lists, tuples or numpy.ndarray with equal dimensions.

Returns:
matrixnumpy.ndarray

Matrix whose columns are the given arrays.

ddg.math.linalg.matrix_to_arrays(matrix)[source]

Converts the columns (!) of a (m x n)-matrix to a list of arrays.

Parameters:
matrixnumpy.ndarray of shape (m, n)
Returns:
arrayslist

List of n numpy.ndarray, each of shape (m,)

ddg.math.linalg.e(i, N)[source]

i-th canonical basis vector of size N

ddg.math.linalg.permutation_matrix(i, j, N)[source]

Projective transformation that permutes homogeneous coordinates i and j

ddg.math.linalg.extend_to_basis(v, i=-1)[source]

Complete one vector into a basis.

Parameters:
vndarray

Vector you want to complete into a basis

iint

Position you want v to be in the returned basis

Returns:
bndarray

If v is a vector of size N, then b will be a matrix of shape (N,N) where the columns are the basis vectors and b[:,i] == v.

ddg.math.linalg.coordinates(vectors, basis, atol=1e-13, rtol=None)[source]

Compute coordinates of vectors in a basis of whole space or subspace.

Parameters:
vectorsnumpy.ndarray of shape (n,k) or (n,)

A matrix whose columns are vectors in the space

basisnumpy.ndarray of shape (n,m)

Matrix whose linearly independent columns are the basis of the space

Returns:
coordinatesnumpy.ndarray of shape (m,k) or (m,)

coordinate matrix such that basis @ coordinates == vectors.

Raises:
ValueError

If a vector does not lie in the subspace.

ddg.math.linalg.linear_dependence(points, atol=0.0001, rtol=None)[source]

Computes the coefficients of a linear dependence of points.

Parameters:
pointslist

List of vectors

Returns:
coefficients of linear dependence of points

Notes

This function uses the global tolerance defaults if atol or rtol are set to None. See ddg.abc.NonExact for details.