![]() |
ModelSpace
|
Matrix math implementation. More...
#include <Matrix.hpp>
Public Member Functions | |
Matrix () | |
Default constructor to initialize a matrix to all zeroes for ease of use. | |
Matrix (T elements) | |
Constructor to initialize a matrix with all the same element. | |
Matrix (const T(&initial)[R][C]) | |
Constructor for Matrix class with initialization. Initializes matrix to values passed in via array. | |
Matrix (const Matrix< T, R, C > &initial) | |
Copy constructor for Matrix class. Copies data from matrix object to the current instance. | |
Matrix (const std::array< std::array< T, C >, R > &initial) | |
Array constructor for the matrix class. Initializes from std::array. | |
~Matrix () | |
Destructor – doesn't do anything because we don't dynamically allocate. | |
void | dump () const |
Function to dump information on matrix. | |
std::string | str () const |
Function to dump information on matrix to string. | |
int | set (const unsigned int &row, const unsigned int &col, const T &value) |
Function to set a single value in the matrix. | |
int | get (const unsigned int &row, const unsigned int &col, T &result) const |
Function to get a single value in the matrix. | |
void | setFromArray (const T *start_ptr) |
Function to set the values of the matrix row-wise. | |
void | getAsArray (T *start_ptr) const |
Function to get the values of the matrix row-wise. | |
T | get (const unsigned int &row, const unsigned int &col) const |
Function to get a single value in the matrix. | |
void | getCopy (Matrix< T, R, C > &result) const |
Function to get a copy of the matrix. | |
Matrix< T, R, C > & | operator= (const Matrix< T, R, C > &other) |
Equals operator overload for matrix. | |
T * | operator[] (unsigned int idx) |
Function to return a matrix row or vector value. | |
std::pair< unsigned int, unsigned int > | size () |
Function to get the size of the matrix. | |
void | max (T &result, std::pair< unsigned int, unsigned int > &index) const |
Function to return the maximum value in the matrix. | |
void | min (T &result, std::pair< unsigned int, unsigned int > &index) const |
Function to return the minimum value in the matrix. | |
int | det (T &result) const |
Function to return the determinant of the matrix. | |
int | inverse (Matrix< T, R, C > &result) const |
Function to return the inverse of the matrix. | |
Matrix< T, R, C > | inverse () const |
void | transpose (Matrix< T, C, R > &result) const |
Function to return the transpose of the matrix. | |
Matrix< T, C, R > | transpose () const |
int | trace (T &result) const |
Function to return the trace of the matrix. | |
void | setToZeros () |
Function to set all elements of the matrix to zero. | |
int | identity () |
Function to set matrix to identity, if it is a square matrix. | |
int | eye () |
Public Attributes | |
std::array< std::array< T, C >, R > | values |
The actual values held by the matrix – a two dimensional array of values indexed as (row, column). NOTE: Public for ease of access and speed (no need to use setter/getter), and functions in Matrix and Safemath libraries are tested safe. Behavior using matrices outside of clockwerk libraries should use setter/getter, rather than direct access, for safety. | |
Protected Member Functions | |
int | _checkLookupBoundaries (const unsigned int &start_r, const unsigned int &end_r, const unsigned int &start_c, const unsigned int &end_c) const |
Function to check, given a set of submatrix boundaries, that those boundaries are valid for the current matrix. | |
int | _LUPDecompose (T *A[R], unsigned int P[R+1]) const |
Function to take a 2-d matrix represented by A and decompose it into LU form. | |
Matrix math implementation.
This file defines a base class for computational matrix math. It is designed for use in real-time, embedded mode or with simulation. As such, it contains certain limitations on dynamic allocation to make it real-time compliant.
Note: The naming convention observed for matrix math is as follows:
Important: The matrix class is templated such that it can be used with a generic type T, but should only be used on native types, as other implementations could result in undefined behavior.
TODO: Flattening and flattened constructor
Function to take a 2-d matrix represented by A and decompose it into LU form.
A | A 2-d matrix represented as a double pointer After ops A contains a copy of both matrices L-E and U as A=(L-E)+U such that P*A=L*U. |
P | The permutation matrix to hold info on matrix changes |
int clockwerk::Matrix< T, R, C >::det | ( | T & | result | ) | const |
Function to get a single value in the matrix.
row | The row index |
col | The column index |
int clockwerk::Matrix< T, R, C >::get | ( | const unsigned int & | row, |
const unsigned int & | col, | ||
T & | result | ||
) | const |
Function to get a single value in the matrix.
row | The row index |
col | The column index |
value | PBR return of the value in the matrix |
void clockwerk::Matrix< T, R, C >::getAsArray | ( | T * | start_ptr | ) | const |
Function to get the values of the matrix row-wise.
start_ptr | The data address at which write should begin. |
Function to get a copy of the matrix.
result | PBR return of a copy of this matrix |
int clockwerk::Matrix< T, R, C >::identity | ( | ) |
Function to set matrix to identity, if it is a square matrix.
Function to return the inverse of the matrix.
result | PBR return of matrix inverse |
void clockwerk::Matrix< T, R, C >::max | ( | T & | result, |
std::pair< unsigned int, unsigned int > & | index | ||
) | const |
Function to return the maximum value in the matrix.
result | PBR return of maximum value |
void clockwerk::Matrix< T, R, C >::min | ( | T & | result, |
std::pair< unsigned int, unsigned int > & | index | ||
) | const |
Function to return the minimum value in the matrix.
result | PBR return of minimum value |
Function to return a matrix row or vector value.
idx | The row index to return |
Function to set the values of the matrix row-wise.
start_ptr | The data address at which read should begin. |
int clockwerk::Matrix< T, R, C >::trace | ( | T & | result | ) | const |
Function to return the trace of the matrix.
result | PBR return of matrix trace |
Function to return the transpose of the matrix.
result | PBR return of matrix transpose |