ulqr  0.1.0
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 slap_NewMatrix(int rows, int cols);
88 
99 Matrix slap_NewMatrixZeros(int rows, int cols);
100 
108 int slap_MatrixSetConst(Matrix* mat, double val);
109 
120 int slap_FreeMatrix(Matrix* mat);
121 
128 int slap_MatrixNumElements(const Matrix* mat);
129 
142 int slap_MatrixGetLinearIndex(const Matrix* mat, int row, int col);
143 
157 double* slap_MatrixGetElementTranspose(const Matrix* mat, int row, int col, bool istranposed);
158 
168 int slap_MatrixSetElement(Matrix* mat, int row, int col, double val);
169 
178 double* slap_MatrixGetElement(const Matrix* mat, int row, int col);
179 
187 int slap_MatrixCopyTranspose(Matrix* dest, Matrix* src);
188 
196 int slap_MatrixCopy(Matrix* dest, Matrix* src);
197 
206 int slap_MatrixCopyFromArray(Matrix* mat, const double* data);
207 
215 int slap_MatrixScaleByConst(Matrix* mat, double alpha);
216 
227 
237 int slap_MatrixFlatten(Matrix* mat);
238 
249 
258 int slap_PrintMatrix(const Matrix* mat);
259 
268 int slap_PrintRowVector(const Matrix* mat);
269 
280 int slap_SetMatrixSize(Matrix* mat, int rows, int cols);
281 
slap_MatrixNormedDifference
double slap_MatrixNormedDifference(Matrix *A, Matrix *B)
Return the normed difference between 2 matrices of the same size.
Definition: matrix.c:147
slap_FreeMatrix
int slap_FreeMatrix(Matrix *mat)
Free the data for a matrix.
Definition: matrix.c:35
slap_MatrixScaleByConst
int slap_MatrixScaleByConst(Matrix *mat, double alpha)
Scale a matrix by a constant factor.
Definition: matrix.c:137
slap_MatrixGetLinearIndex
int slap_MatrixGetLinearIndex(const Matrix *mat, int row, int col)
Get the linear index for a given row and column in the matrix.
Definition: matrix.c:53
slap_MatrixCopyFromArray
int slap_MatrixCopyFromArray(Matrix *mat, const double *data)
Copy the data from an array into the matrix, columnwise.
Definition: matrix.c:107
slap_NewMatrixZeros
Matrix slap_NewMatrixZeros(int rows, int cols)
Allocate a new matrix on the heap, initialized with zeros.
Definition: matrix.c:19
slap_MatrixNumElements
int slap_MatrixNumElements(const Matrix *mat)
Get the number of elements in a matrix, i.e. m * n.
Definition: matrix.c:46
slap_MatrixGetElementTranspose
double * slap_MatrixGetElementTranspose(const Matrix *mat, int row, int col, bool istranposed)
Get the element of a matrix or its transpose.
Definition: matrix.c:70
slap_PrintRowVector
int slap_PrintRowVector(const Matrix *mat)
Print the entire matrix as a row vector.
Definition: matrix.c:198
slap_SetMatrixSize
int slap_SetMatrixSize(Matrix *mat, int rows, int cols)
Set the dimensions of the matrix.
Definition: matrix.c:210
slap_MatrixFlattenToRow
int slap_MatrixFlattenToRow(Matrix *mat)
Flatten a 2D matrix to a row vector.
Definition: matrix.c:175
Matrix
Represents a matrix of double-precision data.
Definition: matrix.h:71
slap_MatrixFlatten
int slap_MatrixFlatten(Matrix *mat)
Flatten a 2D matrix to a column vector.
Definition: matrix.c:165
slap_MatrixSetConst
int slap_MatrixSetConst(Matrix *mat, double val)
Sets all of the elements in a matrix to a single value.
Definition: matrix.c:25
slap_MatrixSetElement
int slap_MatrixSetElement(Matrix *mat, int row, int col, double val)
The a matrix element to a given value.
Definition: matrix.c:82
slap_NewMatrix
Matrix slap_NewMatrix(int rows, int cols)
Allocate a new matrix on the heap.
Definition: matrix.c:13
slap_MatrixGetElement
double * slap_MatrixGetElement(const Matrix *mat, int row, int col)
Get the element of a matrix given row, column indices.
Definition: matrix.c:63
slap_MatrixCopyTranspose
int slap_MatrixCopyTranspose(Matrix *dest, Matrix *src)
Copy a matrix to another matrix, transposed.
Definition: matrix.c:118
slap_PrintMatrix
int slap_PrintMatrix(const Matrix *mat)
Print the elements of a matrix to stdout.
Definition: matrix.c:185
slap_MatrixCopy
int slap_MatrixCopy(Matrix *dest, Matrix *src)
Copy a matrix to another matrix.
Definition: matrix.c:95