ulqr
0.1.0
|
Data Structures | |
struct | Matrix |
Represents a matrix of double-precision data. More... | |
Functions | |
Matrix | slap_NewMatrix (int rows, int cols) |
Allocate a new matrix on the heap. More... | |
Matrix | slap_NewMatrixZeros (int rows, int cols) |
Allocate a new matrix on the heap, initialized with zeros. More... | |
int | slap_MatrixSetConst (Matrix *mat, double val) |
Sets all of the elements in a matrix to a single value. More... | |
int | slap_FreeMatrix (Matrix *mat) |
Free the data for a matrix. More... | |
int | slap_MatrixNumElements (const Matrix *mat) |
Get the number of elements in a matrix, i.e. m * n . More... | |
int | slap_MatrixGetLinearIndex (const Matrix *mat, int row, int col) |
Get the linear index for a given row and column in the matrix. More... | |
double * | slap_MatrixGetElementTranspose (const Matrix *mat, int row, int col, bool istranposed) |
Get the element of a matrix or its transpose. More... | |
int | slap_MatrixSetElement (Matrix *mat, int row, int col, double val) |
The a matrix element to a given value. More... | |
double * | slap_MatrixGetElement (const Matrix *mat, int row, int col) |
Get the element of a matrix given row, column indices. More... | |
int | slap_MatrixCopyTranspose (Matrix *dest, Matrix *src) |
Copy a matrix to another matrix, transposed. More... | |
int | slap_MatrixCopy (Matrix *dest, Matrix *src) |
Copy a matrix to another matrix. More... | |
int | slap_MatrixCopyFromArray (Matrix *mat, const double *data) |
Copy the data from an array into the matrix, columnwise. More... | |
int | slap_MatrixScaleByConst (Matrix *mat, double alpha) |
Scale a matrix by a constant factor. More... | |
double | slap_MatrixNormedDifference (Matrix *A, Matrix *B) |
Return the normed difference between 2 matrices of the same size. More... | |
int | slap_MatrixFlatten (Matrix *mat) |
Flatten a 2D matrix to a column vector. More... | |
int | slap_MatrixFlattenToRow (Matrix *mat) |
Flatten a 2D matrix to a row vector. More... | |
int | slap_PrintMatrix (const Matrix *mat) |
Print the elements of a matrix to stdout. More... | |
int | slap_PrintRowVector (const Matrix *mat) |
Print the entire matrix as a row vector. More... | |
int | slap_SetMatrixSize (Matrix *mat, int rows, int cols) |
Set the dimensions of the matrix. More... | |
int slap_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
. Copy a matrix to another matrix.
dest | a matrix of size (m,n) |
src | a matrix of size (n,m) |
int slap_MatrixCopyFromArray | ( | Matrix * | mat, |
const double * | data | ||
) |
Copy the data from an array into the matrix, columnwise.
mat | Matrix with nonzero size |
data | Data to be copied into the array. Must have length of at least mat.rows * mat.cols. |
Copy a matrix to another matrix, transposed.
dest | a matrix of size (m,n) |
src | a matrix of size (n,m) |
int slap_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 slap_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* slap_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* slap_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? |
int slap_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. 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 slap_MatrixNumElements | ( | const Matrix * | mat | ) |
Get the number of elements in a matrix, i.e. m * n
.
mat | Any matrix |
int slap_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 slap_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 slap_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 slap_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 |
Matrix slap_NewMatrixZeros | ( | int | rows, |
int | cols | ||
) |
Allocate a new matrix on the heap, initialized with zeros.
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 slap_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 slap_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 |