rsLQR  0.1
matrix.h
Go to the documentation of this file.
1 
13 #pragma once
14 
15 #include <stdbool.h>
16 
71 typedef struct {
72  int rows;
73  int cols;
74  double* data;
75 } Matrix;
76 
87 Matrix NewMatrix(int rows, int cols);
88 
96 int MatrixSetConst(Matrix* mat, double val);
97 
108 int FreeMatrix(Matrix* mat);
109 
116 int MatrixNumElements(const Matrix* mat);
117 
130 int MatrixGetLinearIndex(const Matrix* mat, int row, int col);
131 
145 double* MatrixGetElementTranspose(const Matrix* mat, int row, int col, bool istranposed);
146 
156 int MatrixSetElement(Matrix* mat, int row, int col, double val);
157 
166 double* MatrixGetElement(const Matrix* mat, int row, int col);
167 
175 int MatrixCopyTranspose(Matrix* dest, Matrix* src);
176 
184 int MatrixCopy(Matrix* dest, Matrix* src);
192 int MatrixScaleByConst(Matrix* mat, double alpha);
193 
203 double MatrixNormedDifference(Matrix* A, Matrix* B);
204 
214 int MatrixFlatten(Matrix* mat);
215 
225 int MatrixFlattenToRow(Matrix* mat);
226 
235 int PrintMatrix(const Matrix* mat);
236 
245 int PrintRowVector(const Matrix* mat);
246 
MatrixScaleByConst
int MatrixScaleByConst(Matrix *mat, double alpha)
Scale a matrix by a constant factor.
Definition: matrix.c:101
PrintMatrix
int PrintMatrix(const Matrix *mat)
Print the elements of a matrix to stdout.
Definition: matrix.c:141
NewMatrix
Matrix NewMatrix(int rows, int cols)
Allocate a new matrix on the heap.
Definition: matrix.c:13
MatrixSetElement
int MatrixSetElement(Matrix *mat, int row, int col, double val)
The a matrix element to a given value.
Definition: matrix.c:62
MatrixGetLinearIndex
int MatrixGetLinearIndex(const Matrix *mat, int row, int col)
Get the linear index for a given row and column in the matrix.
Definition: matrix.c:43
MatrixCopyTranspose
int MatrixCopyTranspose(Matrix *dest, Matrix *src)
Copy a matrix to another matrix, transposed.
Definition: matrix.c:83
MatrixNumElements
int MatrixNumElements(const Matrix *mat)
Get the number of elements in a matrix, i.e. m * n.
Definition: matrix.c:38
PrintRowVector
int PrintRowVector(const Matrix *mat)
Print the entire matrix as a row vector.
Definition: matrix.c:152
Matrix
Represents a matrix of double-precision data.
Definition: matrix.h:71
MatrixCopy
int MatrixCopy(Matrix *dest, Matrix *src)
Copy a matrix to another matrix.
Definition: matrix.c:73
MatrixNormedDifference
double MatrixNormedDifference(Matrix *A, Matrix *B)
Return the normed difference between 2 matrices of the same size.
Definition: matrix.c:109
MatrixSetConst
int MatrixSetConst(Matrix *mat, double val)
Sets all of the elements in a matrix to a single value.
Definition: matrix.c:19
MatrixGetElement
double * MatrixGetElement(const Matrix *mat, int row, int col)
Get the element of a matrix given row, column indices.
Definition: matrix.c:49
FreeMatrix
int FreeMatrix(Matrix *mat)
Free the data for a matrix.
Definition: matrix.c:27
MatrixGetElementTranspose
double * MatrixGetElementTranspose(const Matrix *mat, int row, int col, bool istranposed)
Get the element of a matrix or its transpose.
Definition: matrix.c:54
MatrixFlatten
int MatrixFlatten(Matrix *mat)
Flatten a 2D matrix to a column vector.
Definition: matrix.c:125
MatrixFlattenToRow
int MatrixFlattenToRow(Matrix *mat)
Flatten a 2D matrix to a row vector.
Definition: matrix.c:133