37#ifndef CORE_MATRIXMATH_HPP
38#define CORE_MATRIXMATH_HPP
57 template<u
int32 R1, u
int32 C1R2, u
int32 C2>
68 if(
static_cast<const void*
>(&A) ==
static_cast<const void*
>(&result)) {
71 for(i = 0; i < R1; i++) {
72 for(j = 0; j < C2; j++) {
74 for(k = 0; k < C1R2; k++) {
83 if(
static_cast<const void*
>(&B) ==
static_cast<const void*
>(&result)) {
86 for(i = 0; i < R1; i++) {
87 for(j = 0; j < C2; j++) {
89 for(k = 0; k < C1R2; k++) {
104 for(i = 0; i < R1; i++) {
105 for(j = 0; j < C2; j++) {
106 result.
values[i][j] = 0.0;
107 for(k = 0; k < C1R2; k++) {
120 template<u
int32 R, u
int32 C>
133 for(i = 0; i < R; i++) {
134 for(j = 0; j < C; j++) {
145 template<u
int32 R, u
int32 C>
158 for(i = 0; i < R; i++) {
159 for(j = 0; j < C; j++) {
170 template<u
int32 R, u
int32 C>
183 for(i = 0; i < R; i++) {
184 for(j = 0; j < C; j++) {
195 template<u
int32 R, u
int32 C>
208 for(i = 0; i < R; i++) {
209 for(j = 0; j < C; j++) {
220 template<u
int32 R, u
int32 C>
233 for(i = 0; i < R; i++) {
234 for(j = 0; j < C; j++) {
246 template<u
int32 R1, u
int32 C1R2, u
int32 C2>
256 template<u
int32 R, u
int32 C>
263 template<u
int32 R, u
int32 C>
273 template<u
int32 R, u
int32 C>
283 template<u
int32 R, u
int32 C>
290 template<u
int32 R, u
int32 C>
299 template<u
int32 R, u
int32 C>
314 template <u
int32 M, u
int32 K>
318 int16 err = A.
chol(R);
319 if (err) {
return err; }
324 for (uint32 col = 0; col < K; col++) {
326 for (uint32 i = 0; i < M; i++) {
327 floating_point sum = B.
get(i, col);
328 for (uint32 k = 0; k < i; k++) {
329 sum -= R.
get(k, i) * Y[k];
332 if(err) {
return err;}
336 for (int32 i = M - 1; i >= 0; i--) {
337 floating_point sum = Y[i];
338 for (uint32 k = i + 1; k < M; k++) {
339 sum -= R.
get(i, k) * X.
get(k, col);
343 if(err) {
return err;}
Matrix math implementation.
Definition Matrix.hpp:55
std::array< std::array< floating_point, C >, R > values
Definition Matrix.hpp:213
int16 get(uint32 row, uint32 col, floating_point &result) const
Function to get a single value in the matrix.
Definition Matrix.hpp:394
int16 set(uint32 row, uint32 col, const floating_point &value)
Function to set a single value in the matrix.
Definition Matrix.hpp:381
int16 chol(Matrix< R, C > &retval) const
Take the cholesky decomposition of this matrix.
Definition Matrix.hpp:569
#define NO_ERROR
Error code in the case where matrix math executed successfully.
Definition clockwerkerrors.h:34
Definition CircularBuffer.hpp:28
void eSubtract(Matrix< R, C > A, Matrix< R, C > B, Matrix< R, C > &result)
Function to subtract B from A, element-wise.
Definition matrixmath.hpp:221
Matrix< R, C > operator+(const Matrix< R, C > &A, const Matrix< R, C > &B)
Overload of matrix addition - Two matrices.
Definition matrixmath.hpp:274
Matrix< R1, C2 > operator*(const Matrix< R1, C1R2 > &A, const Matrix< C1R2, C2 > &B)
Overload of matrix multiplication - Two matrices.
Definition matrixmath.hpp:247
void eAdd(const Matrix< R, C > &A, const Matrix< R, C > &B, Matrix< R, C > &result)
Function to add two matrices element-wise.
Definition matrixmath.hpp:196
void eMultiply(const Matrix< R, C > &A, const Matrix< R, C > &B, Matrix< R, C > &result)
Function to multiply two matrices element-wise.
Definition matrixmath.hpp:146
Matrix< R, C > operator-(const Matrix< R, C > &A, const Matrix< R, C > &B)
Returns value – less efficient in some cases.
Definition matrixmath.hpp:300
void add(const floating_point &a, const Matrix< R, C > &A, Matrix< R, C > &result)
Function to add a scalar to a matrix.
Definition matrixmath.hpp:171
int16 cholSolve(const Matrix< M, M > &A, const Matrix< M, K > &B, Matrix< M, K > &X)
Perform cholesky solve Ax=b on square, posdef matrix A and put the solution in X.
Definition matrixmath.hpp:315
int16 safeDivide(float a, float b, float &result)
Overloaded functions to perform safe division.
Definition safemath.cpp:24
void multiply(const Matrix< R1, C1R2 > &A, const Matrix< C1R2, C2 > &B, Matrix< R1, C2 > &result)
Function to multiply two matrices.
Definition matrixmath.hpp:58