ddg.math.inner_product module

Utility module for inner products.

An inner product is a real (or complex) valued bilinear function over some vector space with the signature inner_product(v, w). Note that we do not require inner products to be positive-definite.

Some of the utility functions require the given inner product to be able to handle matrices for its arguments v and w, i.e. for two matrices V, W of shape (n,m) and (n,l), and with columns v_i and w_j respectively, inner_product(V,W) would return a matrix VW of shape (m,l) with VW[i][j] = inner_product(v_i, w_j). We call inner products which satisfy this condition vectorized.

Others do not strictly require this, but will assume this property, if a matrix is passed instead of a vector for one of its arguments. Refer for the Notes sections of the utility functions for more.

ddg.math.inner_product.col_complement(A, inner_product=None)[source]

Returns the orthogonal complement of the columns of a given array with respect to the given inner product.

Parameters:
Anumpy.ndarray of shape (n,m)

Array for which to return the column complement

inner_productCallable (optional, default=None)

Inner product to be used. When the argument is None, the standard inner product will be used.

Returns:
numpy.ndarray of shape (n, k)

Column complement of the given array

Notes

If the columns of the given matrix A span the whole space, a vector of shape (n, 0) is returned

ddg.math.inner_product.col_complement_oriented(A, inner_product=None)[source]

Returns the oriented orthogonal complement of the columns of a given array with respect to the given inner product.

Parameters:
Anumpy.ndarray of shape (n, m)

Array for which to return the column complement

inner_productCallable (optional, default=None)

Inner product to be used. When the argument is None, the standard inner product will be used.

Returns:
numpy.ndarray of shape (n, k)

Column complement of the given array

Notes

If the columns of the given matrix A span the whole space, a vector of shape (n, 0) is returned

ddg.math.inner_product.row_complement(A, inner_product=None)[source]

Returns the orthogonal complement of the rows of a given array with respect to the given inner product.

Parameters:
Anumpy.ndarray of shape (m, n)

Array for which to return the column complement

inner_productCallable (optional, default=None)

Inner product to be used. When the argument is None, the standard inner product will be used.

Returns:
numpy.ndarray

Column complement of the given array

Notes

If the rows of the given matrix A span the whole space, a vector of shape (0, n) is returned

ddg.math.inner_product.row_complement_oriented(A, inner_product=None)[source]

Returns the oriented orthogonal complement of the rows of a given array with respect to the given inner product.

Parameters:
Anumpy.ndarray of shape (m, n)

Array for which to return the column complement

inner_productCallable (optional, default=None)

Inner product to be used. When the argument is None, the standard inner product will be used.

Returns:
numpy.ndarray

Column complement of the given array

Notes

If the rows of the given matrix A span the whole space, a vector of shape (0, n) is returned

ddg.math.inner_product.orthonormalize(U, inner_product, atol=None)[source]

Orthonormalize columns of matrix.

Parameters:
Unumpy.ndarray of shape (n, m)

Matrix of vectors to orthonormalize

inner_productCallable

Inner product to orthonormalize for

atolfloat (default=None)

If None is given, the global defaults are used. See ddg.abc.NonExact for details.

Returns:
numpy.ndarray of shape (n, m)

Matrix of orthonormal vectors

ddg.math.inner_product.normalize(v, inner_product, atol=None)[source]

Normalize vector with respect to inner_product.

Parameters:
varray_like of shape (n,m) or (n,)

Matrix of m n-vectors to normalize

inner_product: Callable

Inner product to normalize for

atolfloat (default=None)

Tolerance to determine vectors of zero length If None is given, the global defaults are used. See ddg.abc.NonExact for details.

Returns:
numpy.ndarray of shape (n,m) or (n,)

Normalized vector(s)

Notes

This function requires the inner product to be vectorized to handle 2-dimensional inputs.

ddg.math.inner_product.vectorize_inner_product(inner_product, n)[source]

Vectorize a given inner product for dimension n.

Parameters:
inner_productCallable

Inner product to vectorize. The function should have the signature inner_product(v, w), and support numpy.ndarrays of shape (n,)

nint

Dimension

Returns:
Callable

vectorized inner product. See module description for its signature.

ddg.math.inner_product.gram_matrix(inner_product, M)[source]

Calculate Gram-Matrix for column vectors of M with respect to inner_product.

Parameters:
Marray_like of shape (n,m)

Matrix of vectors.

inner_productCallable

Inner product to use. The function should have the signature inner_product(v, w), and support numpy.ndarrays of shape (n,)

Returns:
numpy.ndarray of shape (m,m)

Gram-Matrix for the vectors.

ddg.math.inner_product.signature(inner_product, M)[source]

Signature of matrix with respect to inner_product.

Parameters:
inner_productCallable

Inner product to use

Marray_like of shape (n,m)

Matrix to calculate the signature for

Returns:
numpy.ndarray

Signature of matrix with respect to inner product

Notes

This function requires the given inner product to be vectorized and will give unexpected results if it is not.

ddg.math.inner_product.reflect(normal, source, inner_product, atol=None)[source]

Reflect source on hyperplane.

The reflection x_ref of a vector x in a hyperplane given by its normal n with respect to an inner product g is given by x_ref = x - 2 * g(x, n) * n.

Parameters:
normalarray_like of shape (n,)

Vector defining the hyperplane

sourcearray_like of shape (n, m) or (n,)

Vectors to reflect

inner_productCallable

Inner product to use for reflection

atolfloat (default=None)

Tolerance used to determine whether normal is of non-zero length If None is given, the global defaults are used. See ddg.abc.NonExact for details.

Returns:
numpy.ndarray of shape (n, m) or (n,)

Reflected vector(s)

Notes

This function requires the inner product to be vectorized to handle 2-dimensional inputs for the argument source.

ddg.math.inner_product.project_onto_complement(normal, source, inner_product, atol=None)[source]

Project source onto hyperplane given by its normal.

The projection x_proj of a vector x onto a hyperplane given by its normal n with respect to an inner product g is given by x_proj = x - g(x, n) * n.

Parameters:
normalarray_like of shape (n,)

Vector defining the hyperplane

sourcearray_like of shape (n, m) or (n,)

Vectors to project

inner_productCallable

inner_product to use

atolfloat (default=None)

Tolerance used to determine whether normal is of non-zero length If None is given, the global defaults are used. See ddg.abc.NonExact for details.

Returns:
numpy.ndarray of shape (n, m) or (n,)

Projected vector(s)

See also

reflect

Notes

This function requires the inner product to be vectorized to handle 2-dimensional inputs for the argument source.

ddg.math.inner_product.get_matrix(inner_product, n)[source]

Get representative matrix of inner_product for dimension n.

Parameters:
inner_productCallable

Inner product

nint

Dimension

Returns:
numpy.ndarray of shape (n,n)

Matrix representation of inner product

ddg.math.inner_product.polarity_matrix(inner_product, n)[source]

Polarity matrix of inner_product of dimension n.

This corresponds to the transpose of the representative matrix of the inner product.

Parameters:
inner_productCallable

Inner Product to use

nint

Dimension

Returns:
numpy.ndarray of shape (n,n)

Polarity matrix of the inner product

ddg.math.inner_product.light_like_vectors_from_onb(onb, inner_product, atol=None)[source]

Compute possible points on the quadric from an orthonormal basis by suitable linear combinations of space- and time-like vectors. Light-like vectors will be appended to the list.

Parameters:
onbnumpy.ndarray of shape (n, m)

Rows of the matrix form an orthonormal basis with respect to the given inner product

inner_productCallable

Inner product to use

atolfloat (default=None)

Tolerance used to determine whether vectors are space/time/light-like. If None is given, the global defaults are used. See ddg.abc.NonExact for details.

Returns:
numpy.array (k,m)

All possible sums and differences of the space- and time-like vectors of the orthonormal basis, with the light-like vectors appended, as rows of a matrix. This means that k = k_space * k_time * 2 + k_light, where k_space, k_time and k_light are the numbers of space-like, time-like and light-like vectors of the onb respectively.