|
rsLQR
0.1
|
Files | |
| file | linalg_custom.h |
| Simple linear algebra routines. | |
Data Structures | |
| struct | CholeskyInfo |
| Stores info about a Cholesky decomposition. More... | |
| struct | Matrix |
| Represents a matrix of double-precision data. More... | |
Enumerations | |
| enum | MatrixLinearAlgebraLibrary { libBLAS = 0, libMKL = 1, libEigen = 2, libInternal = 3 } |
| List of supported linear algebra libraries. More... | |
Functions | |
| CholeskyInfo | DefaultCholeskyInfo () |
| Construct a default CholeskyInfo object. More... | |
| void | FreeFactorization (CholeskyInfo *cholinfo) |
| Frees any data stored by the external library. More... | |
| int | MatrixAddition (Matrix *A, Matrix *B, double alpha) |
Add two matrices of the same size, storing the result in B. More... | |
| int | MatrixCholeskyFactorize (Matrix *mat) |
Compute the Cholesky decomposition on the matrix A. More... | |
| int | MatrixCholeskyFactorizeWithInfo (Matrix *mat, CholeskyInfo *cholinfo) |
Compute the Cholesky decomposition on the matrix A. More... | |
| int | MatrixCholeskySolve (Matrix *A, Matrix *b) |
| Solve a linear system using a precomputed Cholesky factorization. More... | |
| int | MatrixCholeskySolveWithInfo (Matrix *A, Matrix *b, CholeskyInfo *cholinfo) |
| Solve a linear system using a precomputed Cholesky factorization. More... | |
| void | MatrixMultiply (Matrix *A, Matrix *B, Matrix *C, bool tA, bool tB, double alpha, double beta) |
| Matrix multiplication with scaling. More... | |
| void | MatrixSymmetricMultiply (Matrix *Asym, Matrix *B, Matrix *C, double alpha, double beta) |
| Matrix multiplication with a symmetric matrix A. More... | |
| void | MatrixCopyDiagonal (Matrix *dest, Matrix *src) |
Copy just the diagonal element of src to the diagonal of dest. More... | |
| enum MatrixLinearAlgebraLibrary | MatrixGetLinearAlgebraLibrary () |
| Get the linear algebra library currently being used. More... | |
| void | MatrixPrintLinearAlgebraLibrary () |
| Prints which linear algebra library is being used to stdout. More... | |
| void | MatrixLinAlgTimeStart () |
| void | MatrixLinAlgTimeStop () |
| void | MatrixLinAlgTimeReset () |
| double | MatrixGetLinAlgTimeMilliseconds () |
| Matrix | NewMatrix (int rows, int cols) |
| Allocate a new matrix on the heap. More... | |
| int | MatrixSetConst (Matrix *mat, double val) |
| Sets all of the elements in a matrix to a single value. More... | |
| int | FreeMatrix (Matrix *mat) |
| Free the data for a matrix. More... | |
| int | MatrixNumElements (const Matrix *mat) |
Get the number of elements in a matrix, i.e. m * n. More... | |
| int | MatrixGetLinearIndex (const Matrix *mat, int row, int col) |
| Get the linear index for a given row and column in the matrix. More... | |
| double * | MatrixGetElementTranspose (const Matrix *mat, int row, int col, bool istranposed) |
| Get the element of a matrix or its transpose. More... | |
| int | MatrixSetElement (Matrix *mat, int row, int col, double val) |
| The a matrix element to a given value. More... | |
| double * | MatrixGetElement (const Matrix *mat, int row, int col) |
| Get the element of a matrix given row, column indices. More... | |
| int | MatrixCopyTranspose (Matrix *dest, Matrix *src) |
| Copy a matrix to another matrix, transposed. More... | |
| int | MatrixCopy (Matrix *dest, Matrix *src) |
| Copy a matrix to another matrix. More... | |
| int | MatrixScaleByConst (Matrix *mat, double alpha) |
| Scale a matrix by a constant factor. More... | |
| double | MatrixNormedDifference (Matrix *A, Matrix *B) |
| Return the normed difference between 2 matrices of the same size. More... | |
| int | MatrixFlatten (Matrix *mat) |
| Flatten a 2D matrix to a column vector. More... | |
| int | MatrixFlattenToRow (Matrix *mat) |
| Flatten a 2D matrix to a row vector. More... | |
| int | PrintMatrix (const Matrix *mat) |
| Print the elements of a matrix to stdout. More... | |
| int | PrintRowVector (const Matrix *mat) |
| Print the entire matrix as a row vector. More... | |
List of supported linear algebra libraries.
| CholeskyInfo DefaultCholeskyInfo | ( | ) |
Construct a default CholeskyInfo object.
| void FreeFactorization | ( | CholeskyInfo * | cholinfo | ) |
Frees any data stored by the external library.
This should be called prior to creating a new factorization, which will allocate new memory for the factorization.
| cholinfo |
| int FreeMatrix | ( | Matrix * | mat | ) |
Free the data for a matrix.
Note this does NOT attempt to free the matrix object itself, only the data it wraps.
| mat |
NULL. Add two matrices of the same size, storing the result in B.
Performs the following operation:
\[ B = B + \alpha A \]
| [in] | A | any matrix of size (m,n) |
| [in,out] | B | any matrix of size (m,n) |
| [in] | alpha | scalar factor on A |
| int MatrixCholeskyFactorize | ( | Matrix * | mat | ) |
Compute the Cholesky decomposition on the matrix A.
Not supported by all libraries. Prefer to use MatrixCholeskyFactorizeWithInfo().
| mat | A square, positive-definite matrix |
| int MatrixCholeskyFactorizeWithInfo | ( | Matrix * | mat, |
| CholeskyInfo * | cholinfo | ||
| ) |
Compute the Cholesky decomposition on the matrix A.
| [in,out] | mat | A square, positive-definite matrix |
| cholinfo | CholeskyInfo object for storing info about the factorization |
cholinfo.success can be checked to see if the factorization was successful Solve a linear system using a precomputed Cholesky factorization.
Overwrite the input vector b. Prefer to use the more robust MatrixCholeskySolveWithInfo().
| [in] | A | A square matrix whose Cholesky decomposition has already been computed. |
| [in,out] | b | The right-hand-side vector. Stores the solution vector. |
| int MatrixCholeskySolveWithInfo | ( | Matrix * | A, |
| Matrix * | b, | ||
| CholeskyInfo * | cholinfo | ||
| ) |
Solve a linear system using a precomputed Cholesky factorization.
| [in] | A | A square matrix whose Cholesky decomposition has already been computed. |
| [in,out] | b | The right-hand-side vector. Stores the solution vector. |
| cholinfo | Information about the precomputed Cholesky factorization in A. |
Copy a matrix to another matrix.
| dest | a matrix of size (m,n) |
| src | a matrix of size (n,m) |
Copy just the diagonal element of src to the diagonal of dest.
| dest | Destination matrix |
| src | Source matrix |
Copy a matrix to another matrix, transposed.
| dest | a matrix of size (m,n) |
| src | a matrix of size (n,m) |
| int MatrixFlatten | ( | Matrix * | mat | ) |
Flatten a 2D matrix to a column vector.
Changes the row and column data so that the matrix is now a column vector. The underlying data is unchanged.
| mat | Matrix to be flattened. |
| int MatrixFlattenToRow | ( | Matrix * | mat | ) |
Flatten a 2D matrix to a row vector.
Changes the row and column data so that the matrix is now a row vector. The underlying data is unchanged.
| mat | Matrix to be flattened |
| double* MatrixGetElement | ( | const Matrix * | mat, |
| int | row, | ||
| int | col | ||
| ) |
Get the element of a matrix given row, column indices.
| mat | Matrix of nonzero size |
| row | Row index |
| col | Column index |
| double* MatrixGetElementTranspose | ( | const Matrix * | mat, |
| int | row, | ||
| int | col, | ||
| bool | istranposed | ||
| ) |
Get the element of a matrix or its transpose.
If istransposed is false, then this method acts just like MatrixGetElement(). Otherwise, it is equalivalent to flipping the row and col arguments to MatrixGetElement().
| mat | Matrix with nonzero size and initialized data |
| row | Row index |
| col | Column index |
| istranposed | Are the indicies for the transpose of A? |
| enum MatrixLinearAlgebraLibrary MatrixGetLinearAlgebraLibrary | ( | ) |
Get the linear algebra library currently being used.
Its value is determined by the build system and cannot be changed at runtime.
| int MatrixGetLinearIndex | ( | const Matrix * | mat, |
| int | row, | ||
| int | col | ||
| ) |
Get the linear index for a given row and column in the matrix.
Converts a cartesian index of row and column into a linear index for accessing an element of the underlying data.
| mat | Matrix with nonzero size and initialized data |
| row | Row index |
| col | Column index |
row and col. Returns -1 for a bad input. | void MatrixMultiply | ( | Matrix * | A, |
| Matrix * | B, | ||
| Matrix * | C, | ||
| bool | tA, | ||
| bool | tB, | ||
| double | alpha, | ||
| double | beta | ||
| ) |
Return the normed difference between 2 matrices of the same size.
Returns \( \sqrt{\sum_{i=0}^{m-1} \sum_{j=0}^{n-1} (A_{ij} - B_{ij})^2 } \)
| A | A matrix of dimension (m,n) |
| B | A matrix of dimension (m,n) |
| int MatrixNumElements | ( | const Matrix * | mat | ) |
Get the number of elements in a matrix, i.e. m * n.
| mat | Any matrix |
| void MatrixPrintLinearAlgebraLibrary | ( | ) |
Prints which linear algebra library is being used to stdout.
| int MatrixScaleByConst | ( | Matrix * | mat, |
| double | alpha | ||
| ) |
Scale a matrix by a constant factor.
| mat | Fully initialized matrix of non-zero size. Values will be modified. |
| alpha | scalar by which to multiply the matrix |
| int MatrixSetConst | ( | Matrix * | mat, |
| double | val | ||
| ) |
Sets all of the elements in a matrix to a single value.
| mat | Matrix to be modified |
| val | Value to which each element will be set |
| int MatrixSetElement | ( | Matrix * | mat, |
| int | row, | ||
| int | col, | ||
| double | val | ||
| ) |
The a matrix element to a given value.
| mat | Matrix with nonzero size and initialized data |
| row | Row index |
| col | Column index |
| val | Value to which the element should be set |
Matrix multiplication with a symmetric matrix A.
Perform the following computation
\[ C = \alpha A B + \beta C \]
For a symmetric matrix \( A \).
| [in] | Asym | |
| [in] | B | |
| [in,out] | C | |
| [in] | alpha | |
| [in] | beta |
| Matrix NewMatrix | ( | int | rows, |
| int | cols | ||
| ) |
Allocate a new matrix on the heap.
Data will not be initialized. Wrapper around a call to malloc. Must be followed by a call to FreeMatrix.
| rows | number of rows in the matrix |
| cols | number of columns in the matrix |
| int PrintMatrix | ( | const Matrix * | mat | ) |
Print the elements of a matrix to stdout.
Precision of the printing can be controlled by the global variable PRECISION.
| mat | Matrix to be printed |
| int PrintRowVector | ( | const Matrix * | mat | ) |
Print the entire matrix as a row vector.
Same result as calling PrintMatrix() after a call to MatrixFlattenToRow().
| mat | Matrix to be printed |