geomc 1.0
A c++ linear algebra template library
|
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... | |
Linear algebra functions and classes.
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.
T | The element type of the matrix. |
RowMajor | Whether the layout of the matrix is row-major (true ) or column-major (false ). |
lu | An n × n LU-decomposed matrix. |
n | The number of rows and columns in the matrix. |
m | The number of columns in x to solve for. |
x | The solution vector of n elements. This must be initialized to the value of B , and will be rewritten to contain the solution x . |
skip | How many variables, in order from the first, to skip solving for. If greater than 0, the corresponding variables within x will contain nonsense values. |
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
.
T | The element type of the matrix. |
RowMajor | Whether the layout of the matrix is row-major (true ) or column-major (false ). |
plu | An n × n PLU-decomposed matrix. |
p | The permutation array of row-sources filled by decomp_plu() . |
n | The number of rows and columns in the matrix. |
m | The number of solution columns. |
x | The solution matrix of n × m elements, having the same row- or column-major layout as m . |
b | A matrix of n × m elements, having the same layout as x . |
skip | How 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. |
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 * M
T) = A
.
T | Element type of the matrix. |
M | Number of rows in the matrix. Must either match N or be dynamic (0). |
N | Number of columns in the matrix. Must either match M or be dynamic (0). |
m | A square positive-definite matrix. |
true
if the decomposition was completed successfully. 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 * M
T) = A
.
T | Element type. |
RowMajor | Whether the elements in m are arranged in row-major (true) or column-major (false) order. |
m | The elements of the matrix to be decomposed. |
n | The number of rows/columns in the matrix to be decomposed. |
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.
T | The element type of the matrix. |
RowMajor | Whether the layout of the matrix is row-major (true ) or column-major (false ). |
m | Array of elements to decompose. |
rows | Number of rows in m . |
cols | Number of columns in m . |
reorder | Array with space for cols elements to be filled with the column source indexes. May be null . |
parity | Whether an odd number of column-swaps was performed. |
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.
T | The element type of the matrix. |
RowMajor | Whether the layout of the matrix is row-major (true ) or column-major (false ). |
m | Array of elements to decompose. |
rows | Number of rows in m . |
cols | Number of columns in m . |
reorder | Array with space for rows elements to be filled with the row source indexes. May be null . |
parity | Whether an odd number of row-swaps was performed. |
|
inline |
Solve the matrix equation AX = B
for the matrix X
, given matrices A
and B
.
T | The element type of the matrix. |
RowMajor | Whether the layout of the matrix is row-major (true ) or column-major (false ). |
a | A 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. |
n | The number of rows in the matrix. |
m | The number of columns in X and B . |
x | The matrix of n × m initially containing b , which is to be filled with the solution vector x . |
skip | How 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. |
true
if a solution could be found; false
if the system is degenerate.
|
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
.
bases | An 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. |
m | The number of vectors in x to solve for. |
x | An array of m vectors b_j , to be overwritten with the x_j solutions. |
skip | How 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. |
true
if a solution could be found; false
if the system is degenerate. 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.
bases | Array of n linearly independent basis vectors. |
n | Number of basis vectors in the array. |
null_basis | Array with space to receive N - n output bases, whose dot products with the inputs will all be zero. |
Ray multiple.
(r.origin + s * r.direction)
. Ray multiple.
(r.origin + s * r.direction)
. 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.
v | Array of N-1 basis vectors. |
v
. 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.
basis | Set of n bases vectors. |
n | Number of basis vectors, between 0 and N inclusive. |
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.
basis | Set of n bases vectors. |
n | Number of basis vectors between 0 and N inclusive. |