geomc 1.0
A c++ linear algebra template library
Modules | Namespaces | Classes | Functions
Linalg

Linear algebra functions and classes. More...

Modules

 Matrix
 Matrix-related functions and classes.
 

Namespaces

namespace  geom
 Namespace of all geomc functions and classes.
 

Classes

class  AffineTransform< T, N >
 Affine transformation class. More...
 
class  Quat< T >
 Quaternion class. More...
 
class  Ray< T, N >
 Ray class. More...
 
class  Vec< T, N >
 A tuple of N elements of type T. More...
 
class  Vec< T, 2 >
 2D specialization of vector class. More...
 
class  Vec< T, 3 >
 3D specialization of vector class. More...
 
class  Vec< T, 4 >
 4D specialization of vector class. More...
 

Functions

template<typename T , index_t N>
Vec< T, N > orthogonal (const Vec< T, N > v[N-1])
 Return a vector orthogonal to the given N-1 vectors. More...
 
template<typename T >
Vec< T, 3 > orthogonal (const Vec< T, 3 > v[2])
 
template<typename T >
Vec< T, 2 > orthogonal (const Vec< T, 2 > v[1])
 
template<typename T , index_t N>
void nullspace (const Vec< T, N > bases[], index_t n, Vec< T, N > null_basis[])
 Compute the null space of a vector basis. More...
 
template<typename T , index_t N>
void orthogonalize (Vec< T, N > basis[], index_t n)
 Use the Gram-Schmidt process to orthogonalize a set of basis vectors. More...
 
template<typename T >
void orthogonalize (Vec< T, 2 > basis[2], index_t _n=2)
 
template<typename T , index_t N>
void orthonormalize (Vec< T, N > basis[], index_t n)
 Use the Gram-Schmidt process to orthonormalize a set of basis vectors. More...
 
template<typename T , index_t N>
PointType< T, N >::point_t operator* (const Ray< T, N > r, T s)
 
template<typename T , index_t N>
PointType< T, N >::point_t operator* (T s, const Ray< T, N > r)
 
template<typename T , bool RowMajor>
bool cholesky (T *m, index_t n)
 Perform a Cholesky decomposition on a bare array. More...
 
template<typename T , index_t M, index_t N>
bool cholesky (SimpleMatrix< T, M, N > *m)
 Perform a Cholesky decomposition on a Matrix. More...
 
template<typename T , bool RowMajor = true>
index_t decomp_lup (T *m, index_t rows, index_t cols, index_t *reorder, bool *parity)
 LU decomposition, pivoting columns. More...
 
template<typename T , bool RowMajor = true>
index_t decomp_plu (T *m, index_t rows, index_t cols, index_t *reorder, bool *parity)
 LU decomposition, pivoting rows. More...
 
template<typename T , bool RowMajor = true>
void backsolve_plu (const T *plu, const index_t *p, index_t n, index_t m, T *x, const T *b, index_t skip=0)
 Solve the decomposed matrix equation LUX = PB for X, given LU and B. More...
 
template<typename T , bool RowMajor = true>
void backsolve_lu (const T *lu, index_t n, index_t m, T *x, index_t skip=0)
 Solve a decomposed system of linear equations LUX = B, without a permutation map. More...
 
template<typename T , bool RowMajor = true>
bool linear_solve (T *a, index_t n, index_t m, T *x, index_t skip=0)
 Solve the matrix equation AX = B for the matrix X, given matrices A and B. More...
 
template<typename T , index_t N>
bool linear_solve (Vec< T, N > bases[N], index_t m, Vec< T, N > *x, index_t skip=0)
 Write each vector in b in terms of the basis vectors in bases. More...
 

Detailed Description

Linear algebra functions and classes.

Function Documentation

◆ backsolve_lu()

void geom::backsolve_lu ( const T *  lu,
index_t  n,
index_t  m,
T *  x,
index_t  skip = 0 
)

Solve a decomposed system of linear equations LUX = B, without a permutation map.

X and B are n × m matrices.

Template Parameters
TThe element type of the matrix.
RowMajorWhether the layout of the matrix is row-major (true) or column-major (false).
Parameters
luAn n × n LU-decomposed matrix.
nThe number of rows and columns in the matrix.
mThe number of columns in x to solve for.
xThe solution vector of n elements. This must be initialized to the value of B, and will be rewritten to contain the solution x.
skipHow many variables, in order from the first, to skip solving for. If greater than 0, the corresponding variables within x will contain nonsense values.

◆ backsolve_plu()

void geom::backsolve_plu ( const T *  plu,
const index_t *  p,
index_t  n,
index_t  m,
T *  x,
const T *  b,
index_t  skip = 0 
)

Solve the decomposed matrix equation LUX = PB for X, given LU and B.

Template Parameters
TThe element type of the matrix.
RowMajorWhether the layout of the matrix is row-major (true) or column-major (false).
Parameters
pluAn n × n PLU-decomposed matrix.
pThe permutation array of row-sources filled by decomp_plu().
nThe number of rows and columns in the matrix.
mThe number of solution columns.
xThe solution matrix of n × m elements, having the same row- or column-major layout as m.
bA matrix of n × m elements, having the same layout as x.
skipHow many rows in X, in order from the first, to skip solving for. If greater than 0, the corresponding rows within X will contain nonsense values.

◆ cholesky() [1/2]

bool geom::cholesky ( SimpleMatrix< T, M, N > *  m)

Perform a Cholesky decomposition on a Matrix.

Perform an in-place Cholesky decomposition on the given square positive-definite matrix A, producing a lower-triangular matrix M such that (M * MT) = A.

Template Parameters
TElement type of the matrix.
MNumber of rows in the matrix. Must either match N or be dynamic (0).
NNumber of columns in the matrix. Must either match M or be dynamic (0).
Parameters
mA square positive-definite matrix.
Returns
False if the matrix is not square, not positive-definite, or could not be decomposed due to ill-conditioning; true if the decomposition was completed successfully.

◆ cholesky() [2/2]

bool geom::cholesky ( T *  m,
index_t  n 
)

Perform a Cholesky decomposition on a bare array.

Perform an in-place Cholesky decomposition on the given square positive-definite matrix A, producing a lower-triangular matrix M such that (M * MT) = A.

Template Parameters
TElement type.
RowMajorWhether the elements in m are arranged in row-major (true) or column-major (false) order.
Parameters
mThe elements of the matrix to be decomposed.
nThe number of rows/columns in the matrix to be decomposed.
Returns
True if the decomposition could be completed; false if the matrix was not positive-definite or ill-conditioned.

◆ decomp_lup()

index_t geom::decomp_lup ( T *  m,
index_t  rows,
index_t  cols,
index_t *  reorder,
bool *  parity 
)

LU decomposition, pivoting columns.

Solve LU = MP for the lower- and upper-triangular matrices L and U and a permutation matrix P. The diagonal of the decomposed matrix belongs to U and has arbitrary elements. The diagonals of L are implicitly ones.

Template Parameters
TThe element type of the matrix.
RowMajorWhether the layout of the matrix is row-major (true) or column-major (false).
Parameters
mArray of elements to decompose.
rowsNumber of rows in m.
colsNumber of columns in m.
reorderArray with space for cols elements to be filled with the column source indexes. May be null.
parityWhether an odd number of column-swaps was performed.
Returns
The number of degenerate columns discovered.

◆ decomp_plu()

index_t geom::decomp_plu ( T *  m,
index_t  rows,
index_t  cols,
index_t *  reorder,
bool *  parity 
)

LU decomposition, pivoting rows.

Solve LU = PM for the lower- and upper-triangular matrices L and U and a permutation matrix P. The diagonal of the decomposed matrix belongs to U and has arbitrary elements. The diagonals of L are implicitly ones.

Template Parameters
TThe element type of the matrix.
RowMajorWhether the layout of the matrix is row-major (true) or column-major (false).
Parameters
mArray of elements to decompose.
rowsNumber of rows in m.
colsNumber of columns in m.
reorderArray with space for rows elements to be filled with the row source indexes. May be null.
parityWhether an odd number of row-swaps was performed.
Returns
The number of degenerate rows discovered.

◆ linear_solve() [1/2]

bool geom::linear_solve ( T *  a,
index_t  n,
index_t  m,
T *  x,
index_t  skip = 0 
)
inline

Solve the matrix equation AX = B for the matrix X, given matrices A and B.

Template Parameters
TThe element type of the matrix.
RowMajorWhether the layout of the matrix is row-major (true) or column-major (false).
Parameters
aA buffer of elements in the n × n matrix A. This array will be altered during the solution process, so pass a copy if the original needs to remain unchanged.
nThe number of rows in the matrix.
mThe number of columns in X and B.
xThe matrix of n × m initially containing b, which is to be filled with the solution vector x.
skipHow many rows in X, in order from the first, to skip solving for. If greater than 0, the corresponding rows within X will contain nonsense values.
Returns
true if a solution could be found; false if the system is degenerate.

◆ linear_solve() [2/2]

bool geom::linear_solve ( Vec< T, N >  bases[N],
index_t  m,
Vec< T, N > *  x,
index_t  skip = 0 
)
inline

Write each vector in b in terms of the basis vectors in bases.

Return an x_j for each such b_j that sum(bases[i] * x_j[i]) = b_j.

Parameters
basesAn array of N basis vectors. The contents of this array will be altered during the solution process, so pass a copy if the original array needs to remain unchanged.
mThe number of vectors in x to solve for.
xAn array of m vectors b_j, to be overwritten with the x_j solutions.
skipHow many rows, in order from the first, to skip solving for. If greater than 0, the corresponding variables within each x will contain nonsense values.
Returns
true if a solution could be found; false if the system is degenerate.

◆ nullspace()

void geom::nullspace ( const Vec< T, N >  bases[],
index_t  n,
Vec< T, N >  null_basis[] 
)

Compute the null space of a vector basis.

The computed null bases will not necessarily be orthogonal to each other. Use orthogonalize() after computing nullspace() if an orthogonal basis is needed.

bases and null_basis may alias each other.

If any of the bases are linearly dependent, null_basis will be filled with N - n zero vectors.

Parameters
basesArray of n linearly independent basis vectors.
nNumber of basis vectors in the array.
null_basisArray with space to receive N - n output bases, whose dot products with the inputs will all be zero.

◆ operator*() [1/2]

PointType< T, N >::point_t operator* ( const Ray< T, N >  r,
s 
)
related

Ray multiple.

Returns
(r.origin + s * r.direction).

◆ operator*() [2/2]

PointType< T, N >::point_t operator* ( s,
const Ray< T, N >  r 
)
related

Ray multiple.

Returns
(r.origin + s * r.direction).

◆ orthogonal()

Vec< T, N > geom::orthogonal ( const Vec< T, N >  v[N-1])

Return a vector orthogonal to the given N-1 vectors.

If any of the given basis vectors are linearly dependent, the function returns the 0 vector.

Parameters
vArray of N-1 basis vectors.
Returns
A vector normal to all the members of v.

◆ orthogonalize()

void geom::orthogonalize ( Vec< T, N >  basis[],
index_t  n 
)

Use the Gram-Schmidt process to orthogonalize a set of basis vectors.

The first basis vector will not change. The remaining vectors may be of arbitrary magnitude, but will be mutually orthogonal to each other and to the first vector.

Parameters
basisSet of n bases vectors.
nNumber of basis vectors, between 0 and N inclusive.

◆ orthonormalize()

void geom::orthonormalize ( Vec< T, N >  basis[],
index_t  n 
)

Use the Gram-Schmidt process to orthonormalize a set of basis vectors.

The first basis vector will not change direction. All vectors will be made mutually orthogonal and unit length.

Parameters
basisSet of n bases vectors.
nNumber of basis vectors between 0 and N inclusive.