Jet
v1.3.3
|
M x N matrix class. More...
#include <jet/matrix_mxn.h>
Public Types | |
typedef Array2< T > | ContainerType |
typedef ContainerType::Iterator | Iterator |
typedef ContainerType::ConstIterator | ConstIterator |
Public Member Functions | |
MatrixMxN () | |
Constructs an empty matrix. More... | |
MatrixMxN (size_t m, size_t n, const T &s=T(0)) | |
Constructs m x n constant value matrix. More... | |
MatrixMxN (const std::initializer_list< std::initializer_list< T >> &lst) | |
Constructs a matrix with given initializer list lst . More... | |
template<typename E > | |
MatrixMxN (const MatrixExpression< T, E > &other) | |
Constructs a matrix with expression template. More... | |
MatrixMxN (size_t m, size_t n, const T *arr) | |
MatrixMxN (const MatrixMxN &other) | |
Copy constructor. More... | |
MatrixMxN (MatrixMxN &&other) | |
Move constructor. More... | |
void | resize (size_t m, size_t n, const T &s=T(0)) |
Resizes to m x n matrix with initial value s . More... | |
void | set (const T &s) |
Sets whole matrix with input scalar. More... | |
void | set (const std::initializer_list< std::initializer_list< T >> &lst) |
Sets a matrix with given initializer list lst . More... | |
template<typename E > | |
void | set (const MatrixExpression< T, E > &other) |
Copies from input matrix expression. More... | |
void | set (size_t m, size_t n, const T *arr) |
void | setDiagonal (const T &s) |
Sets diagonal elements with input scalar. More... | |
void | setOffDiagonal (const T &s) |
Sets off-diagonal elements with input scalar. More... | |
template<typename E > | |
void | setRow (size_t i, const VectorExpression< T, E > &row) |
Sets i-th row with input vector. More... | |
template<typename E > | |
void | setColumn (size_t j, const VectorExpression< T, E > &col) |
Sets j-th column with input vector. More... | |
template<typename E > | |
bool | isEqual (const MatrixExpression< T, E > &other) const |
template<typename E > | |
bool | isSimilar (const MatrixExpression< T, E > &other, double tol=std::numeric_limits< double >::epsilon()) const |
bool | isSquare () const |
Returns true if this matrix is a square matrix. More... | |
Size2 | size () const |
Returns the size of this matrix. More... | |
size_t | rows () const |
Returns number of rows of this matrix. More... | |
size_t | cols () const |
Returns number of columns of this matrix. More... | |
T * | data () |
Returns data pointer of this matrix. More... | |
const T *const | data () const |
Returns constant pointer of this matrix. More... | |
Iterator | begin () |
Returns the begin iterator of the matrix. More... | |
ConstIterator | begin () const |
Returns the begin const iterator of the matrix. More... | |
Iterator | end () |
Returns the end iterator of the matrix. More... | |
ConstIterator | end () const |
Returns the end const iterator of the matrix. More... | |
MatrixScalarAdd< T, MatrixMxN > | add (const T &s) const |
Returns this matrix + input scalar. More... | |
template<typename E > | |
MatrixAdd< T, MatrixMxN, E > | add (const E &m) const |
Returns this matrix + input matrix (element-wise). More... | |
MatrixScalarSub< T, MatrixMxN > | sub (const T &s) const |
Returns this matrix - input scalar. More... | |
template<typename E > | |
MatrixSub< T, MatrixMxN, E > | sub (const E &m) const |
Returns this matrix - input matrix (element-wise). More... | |
MatrixScalarMul< T, MatrixMxN > | mul (const T &s) const |
Returns this matrix * input scalar. More... | |
template<typename VE > | |
MatrixVectorMul< T, MatrixMxN, VE > | mul (const VectorExpression< T, VE > &v) const |
Returns this matrix * input vector. More... | |
template<typename E > | |
MatrixMul< T, MatrixMxN, E > | mul (const E &m) const |
Returns this matrix * input matrix. More... | |
MatrixScalarDiv< T, MatrixMxN > | div (const T &s) const |
Returns this matrix / input scalar. More... | |
MatrixScalarAdd< T, MatrixMxN > | radd (const T &s) const |
Returns input scalar + this matrix. More... | |
template<typename E > | |
MatrixAdd< T, MatrixMxN, E > | radd (const E &m) const |
Returns input matrix + this matrix (element-wise). More... | |
MatrixScalarRSub< T, MatrixMxN > | rsub (const T &s) const |
Returns input scalar - this matrix. More... | |
template<typename E > | |
MatrixSub< T, MatrixMxN, E > | rsub (const E &m) const |
Returns input matrix - this matrix (element-wise). More... | |
MatrixScalarMul< T, MatrixMxN > | rmul (const T &s) const |
Returns input scalar * this matrix. More... | |
template<typename E > | |
MatrixMul< T, E, MatrixMxN > | rmul (const E &m) const |
Returns input matrix * this matrix. More... | |
MatrixScalarRDiv< T, MatrixMxN > | rdiv (const T &s) const |
Returns input matrix / this scalar. More... | |
void | iadd (const T &s) |
Adds input scalar to this matrix. More... | |
template<typename E > | |
void | iadd (const E &m) |
Adds input matrix to this matrix (element-wise). More... | |
void | isub (const T &s) |
Subtracts input scalar from this matrix. More... | |
template<typename E > | |
void | isub (const E &m) |
Subtracts input matrix from this matrix (element-wise). More... | |
void | imul (const T &s) |
Multiplies input scalar to this matrix. More... | |
template<typename E > | |
void | imul (const E &m) |
Multiplies input matrix to this matrix. More... | |
void | idiv (const T &s) |
Divides this matrix with input scalar. More... | |
void | transpose () |
Transposes this matrix. More... | |
void | invert () |
Inverts this matrix. More... | |
T | sum () const |
Returns sum of all elements. More... | |
T | avg () const |
Returns average of all elements. More... | |
T | min () const |
Returns minimum among all elements. More... | |
T | max () const |
Returns maximum among all elements. More... | |
T | absmin () const |
Returns absolute minimum among all elements. More... | |
T | absmax () const |
Returns absolute maximum among all elements. More... | |
T | trace () const |
T | determinant () const |
Returns determinant of this matrix. More... | |
MatrixDiagonal< T, MatrixMxN > | diagonal () const |
Returns diagonal part of this matrix. More... | |
MatrixDiagonal< T, MatrixMxN > | offDiagonal () const |
Returns off-diagonal part of this matrix. More... | |
MatrixTriangular< T, MatrixMxN > | strictLowerTri () const |
Returns strictly lower triangle part of this matrix. More... | |
MatrixTriangular< T, MatrixMxN > | strictUpperTri () const |
Returns strictly upper triangle part of this matrix. More... | |
MatrixTriangular< T, MatrixMxN > | lowerTri () const |
Returns lower triangle part of this matrix (including the diagonal). More... | |
MatrixTriangular< T, MatrixMxN > | upperTri () const |
Returns upper triangle part of this matrix (including the diagonal). More... | |
MatrixMxN | transposed () const |
Returns transposed matrix. More... | |
MatrixMxN | inverse () const |
Returns inverse matrix. More... | |
template<typename U > | |
MatrixTypeCast< U, MatrixMxN, T > | castTo () const |
Type-casts to different value-typed matrix. More... | |
template<typename E > | |
MatrixMxN & | operator= (const E &m) |
Assigns input matrix. More... | |
MatrixMxN & | operator= (const MatrixMxN &other) |
Copies to this matrix. More... | |
MatrixMxN & | operator= (MatrixMxN &&other) |
Moves to this matrix. More... | |
MatrixMxN & | operator+= (const T &s) |
Addition assignment with input scalar. More... | |
template<typename E > | |
MatrixMxN & | operator+= (const E &m) |
Addition assignment with input matrix (element-wise). More... | |
MatrixMxN & | operator-= (const T &s) |
Subtraction assignment with input scalar. More... | |
template<typename E > | |
MatrixMxN & | operator-= (const E &m) |
Subtraction assignment with input matrix (element-wise). More... | |
MatrixMxN & | operator*= (const T &s) |
Multiplication assignment with input scalar. More... | |
template<typename E > | |
MatrixMxN & | operator*= (const E &m) |
Multiplication assignment with input matrix. More... | |
MatrixMxN & | operator/= (const T &s) |
Division assignment with input scalar. More... | |
T & | operator[] (size_t i) |
Returns reference of i-th element. More... | |
const T & | operator[] (size_t i) const |
Returns constant reference of i-th element. More... | |
T & | operator() (size_t i, size_t j) |
Returns reference of (i,j) element. More... | |
const T & | operator() (size_t i, size_t j) const |
Returns constant reference of (i,j) element. More... | |
template<typename E > | |
bool | operator== (const MatrixExpression< T, E > &m) const |
Returns true if is equal to m. More... | |
template<typename E > | |
bool | operator!= (const MatrixExpression< T, E > &m) const |
Returns true if is not equal to m. More... | |
template<typename Callback > | |
void | forEach (Callback func) const |
Iterates the matrix and invoke given func for each index. More... | |
template<typename Callback > | |
void | forEachIndex (Callback func) const |
Iterates the matrix and invoke given func for each index. More... | |
template<typename Callback > | |
void | parallelForEach (Callback func) |
Iterates the matrix and invoke given func for each index in parallel. More... | |
template<typename Callback > | |
void | parallelForEachIndex (Callback func) const |
Iterates the matrix and invoke given func for each index in parallel using multi-threading. More... | |
![]() | |
Size2 | size () const |
Size of the matrix. More... | |
size_t | rows () const |
Number of rows. More... | |
size_t | cols () const |
Number of columns. More... | |
const MatrixMxN< T > & | operator() () const |
Returns actual implementation (the subclass). More... | |
Static Public Member Functions | |
static MatrixConstant< T > | makeZero (size_t m, size_t n) |
Makes a m x n matrix with zeros. More... | |
static MatrixIdentity< T > | makeIdentity (size_t m) |
M x N matrix class.
This class defines M x N row-major matrix.
T | Type of the element. |
typedef ContainerType::ConstIterator jet::MatrixMxN< T >::ConstIterator |
typedef Array2<T> jet::MatrixMxN< T >::ContainerType |
typedef ContainerType::Iterator jet::MatrixMxN< T >::Iterator |
jet::MatrixMxN< T >::MatrixMxN | ( | ) |
Constructs an empty matrix.
jet::MatrixMxN< T >::MatrixMxN | ( | size_t | m, |
size_t | n, | ||
const T & | s = T(0) |
||
) |
Constructs m x n constant value matrix.
jet::MatrixMxN< T >::MatrixMxN | ( | const std::initializer_list< std::initializer_list< T >> & | lst | ) |
Constructs a matrix with given initializer list lst
.
This constructor will build a matrix with given initializer list lst
such as
Note the initializer has 4x3 structure which will create 4x3 matrix.
lst | Initializer list that should be copy to the new matrix. |
jet::MatrixMxN< T >::MatrixMxN | ( | const MatrixExpression< T, E > & | other | ) |
Constructs a matrix with expression template.
jet::MatrixMxN< T >::MatrixMxN | ( | size_t | m, |
size_t | n, | ||
const T * | arr | ||
) |
Constructs a m x n matrix with input array.
jet::MatrixMxN< T >::MatrixMxN | ( | const MatrixMxN< T > & | other | ) |
Copy constructor.
jet::MatrixMxN< T >::MatrixMxN | ( | MatrixMxN< T > && | other | ) |
Move constructor.
T jet::MatrixMxN< T >::absmax | ( | ) | const |
Returns absolute maximum among all elements.
T jet::MatrixMxN< T >::absmin | ( | ) | const |
Returns absolute minimum among all elements.
MatrixAdd<T, MatrixMxN, E> jet::MatrixMxN< T >::add | ( | const E & | m | ) | const |
Returns this matrix + input matrix (element-wise).
MatrixScalarAdd<T, MatrixMxN> jet::MatrixMxN< T >::add | ( | const T & | s | ) | const |
Returns this matrix + input scalar.
T jet::MatrixMxN< T >::avg | ( | ) | const |
Returns average of all elements.
Iterator jet::MatrixMxN< T >::begin | ( | ) |
Returns the begin iterator of the matrix.
ConstIterator jet::MatrixMxN< T >::begin | ( | ) | const |
Returns the begin const iterator of the matrix.
MatrixTypeCast<U, MatrixMxN, T> jet::MatrixMxN< T >::castTo | ( | ) | const |
Type-casts to different value-typed matrix.
size_t jet::MatrixMxN< T >::cols | ( | ) | const |
Returns number of columns of this matrix.
T* jet::MatrixMxN< T >::data | ( | ) |
Returns data pointer of this matrix.
const T* const jet::MatrixMxN< T >::data | ( | ) | const |
Returns constant pointer of this matrix.
T jet::MatrixMxN< T >::determinant | ( | ) | const |
Returns determinant of this matrix.
MatrixDiagonal<T, MatrixMxN> jet::MatrixMxN< T >::diagonal | ( | ) | const |
Returns diagonal part of this matrix.
MatrixScalarDiv<T, MatrixMxN> jet::MatrixMxN< T >::div | ( | const T & | s | ) | const |
Returns this matrix / input scalar.
Iterator jet::MatrixMxN< T >::end | ( | ) |
Returns the end iterator of the matrix.
ConstIterator jet::MatrixMxN< T >::end | ( | ) | const |
Returns the end const iterator of the matrix.
void jet::MatrixMxN< T >::forEach | ( | Callback | func | ) | const |
Iterates the matrix and invoke given func
for each index.
This function iterates the matrix elements and invoke the callback function func
. The callback function takes matrix's element as its input. The order of execution will be the same as the nested for-loop below:
Below is the sample usage:
void jet::MatrixMxN< T >::forEachIndex | ( | Callback | func | ) | const |
Iterates the matrix and invoke given func
for each index.
This function iterates the matrix elements and invoke the callback function func
. The callback function takes two parameters which are the (i, j) indices of the matrix. The order of execution will be the same as the nested for-loop below:
Below is the sample usage:
Adds input matrix to this matrix (element-wise).
void jet::MatrixMxN< T >::iadd | ( | const T & | s | ) |
Adds input scalar to this matrix.
void jet::MatrixMxN< T >::idiv | ( | const T & | s | ) |
Divides this matrix with input scalar.
Multiplies input matrix to this matrix.
void jet::MatrixMxN< T >::imul | ( | const T & | s | ) |
Multiplies input scalar to this matrix.
MatrixMxN jet::MatrixMxN< T >::inverse | ( | ) | const |
Returns inverse matrix.
void jet::MatrixMxN< T >::invert | ( | ) |
Inverts this matrix.
This function computes the inverse using Gaussian elimination method.
bool jet::MatrixMxN< T >::isEqual | ( | const MatrixExpression< T, E > & | other | ) | const |
bool jet::MatrixMxN< T >::isSimilar | ( | const MatrixExpression< T, E > & | other, |
double | tol = std::numeric_limits< double >::epsilon() |
||
) | const |
Returns true if this matrix is similar to the input matrix within the given tolerance.
bool jet::MatrixMxN< T >::isSquare | ( | ) | const |
Returns true if this matrix is a square matrix.
Subtracts input matrix from this matrix (element-wise).
void jet::MatrixMxN< T >::isub | ( | const T & | s | ) |
Subtracts input scalar from this matrix.
MatrixTriangular<T, MatrixMxN> jet::MatrixMxN< T >::lowerTri | ( | ) | const |
Returns lower triangle part of this matrix (including the diagonal).
|
static |
Makes a m x m matrix with all diagonal elements to 1, and other elements to 0.
|
static |
Makes a m x n matrix with zeros.
T jet::MatrixMxN< T >::max | ( | ) | const |
Returns maximum among all elements.
T jet::MatrixMxN< T >::min | ( | ) | const |
Returns minimum among all elements.
MatrixMul<T, MatrixMxN, E> jet::MatrixMxN< T >::mul | ( | const E & | m | ) | const |
Returns this matrix * input matrix.
MatrixScalarMul<T, MatrixMxN> jet::MatrixMxN< T >::mul | ( | const T & | s | ) | const |
Returns this matrix * input scalar.
MatrixVectorMul<T, MatrixMxN, VE> jet::MatrixMxN< T >::mul | ( | const VectorExpression< T, VE > & | v | ) | const |
Returns this matrix * input vector.
MatrixDiagonal<T, MatrixMxN> jet::MatrixMxN< T >::offDiagonal | ( | ) | const |
Returns off-diagonal part of this matrix.
bool jet::MatrixMxN< T >::operator!= | ( | const MatrixExpression< T, E > & | m | ) | const |
Returns true if is not equal to m.
T& jet::MatrixMxN< T >::operator() | ( | size_t | i, |
size_t | j | ||
) |
Returns reference of (i,j) element.
const T& jet::MatrixMxN< T >::operator() | ( | size_t | i, |
size_t | j | ||
) | const |
Returns constant reference of (i,j) element.
MatrixMxN& jet::MatrixMxN< T >::operator*= | ( | const E & | m | ) |
Multiplication assignment with input matrix.
MatrixMxN& jet::MatrixMxN< T >::operator*= | ( | const T & | s | ) |
Multiplication assignment with input scalar.
MatrixMxN& jet::MatrixMxN< T >::operator+= | ( | const E & | m | ) |
Addition assignment with input matrix (element-wise).
MatrixMxN& jet::MatrixMxN< T >::operator+= | ( | const T & | s | ) |
Addition assignment with input scalar.
MatrixMxN& jet::MatrixMxN< T >::operator-= | ( | const E & | m | ) |
Subtraction assignment with input matrix (element-wise).
MatrixMxN& jet::MatrixMxN< T >::operator-= | ( | const T & | s | ) |
Subtraction assignment with input scalar.
MatrixMxN& jet::MatrixMxN< T >::operator/= | ( | const T & | s | ) |
Division assignment with input scalar.
MatrixMxN& jet::MatrixMxN< T >::operator= | ( | const E & | m | ) |
Assigns input matrix.
MatrixMxN& jet::MatrixMxN< T >::operator= | ( | const MatrixMxN< T > & | other | ) |
Copies to this matrix.
MatrixMxN& jet::MatrixMxN< T >::operator= | ( | MatrixMxN< T > && | other | ) |
Moves to this matrix.
bool jet::MatrixMxN< T >::operator== | ( | const MatrixExpression< T, E > & | m | ) | const |
Returns true if is equal to m.
T& jet::MatrixMxN< T >::operator[] | ( | size_t | i | ) |
Returns reference of i-th element.
const T& jet::MatrixMxN< T >::operator[] | ( | size_t | i | ) | const |
Returns constant reference of i-th element.
void jet::MatrixMxN< T >::parallelForEach | ( | Callback | func | ) |
Iterates the matrix and invoke given func
for each index in parallel.
This function iterates the matrix elements and invoke the callback function func
. The callback function takes matrix's element as its input. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:
The parameter type of the callback function doesn't have to be T&, but const T& or T can be used as well.
void jet::MatrixMxN< T >::parallelForEachIndex | ( | Callback | func | ) | const |
Iterates the matrix and invoke given func
for each index in parallel using multi-threading.
This function iterates the matrix elements and invoke the callback function func
in parallel using multi-threading. The callback function takes two parameters which are the (i, j) indices of the matrix. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:
MatrixAdd<T, MatrixMxN, E> jet::MatrixMxN< T >::radd | ( | const E & | m | ) | const |
Returns input matrix + this matrix (element-wise).
MatrixScalarAdd<T, MatrixMxN> jet::MatrixMxN< T >::radd | ( | const T & | s | ) | const |
Returns input scalar + this matrix.
MatrixScalarRDiv<T, MatrixMxN> jet::MatrixMxN< T >::rdiv | ( | const T & | s | ) | const |
Returns input matrix / this scalar.
void jet::MatrixMxN< T >::resize | ( | size_t | m, |
size_t | n, | ||
const T & | s = T(0) |
||
) |
Resizes to m x n matrix with initial value s
.
MatrixMul<T, E, MatrixMxN> jet::MatrixMxN< T >::rmul | ( | const E & | m | ) | const |
Returns input matrix * this matrix.
MatrixScalarMul<T, MatrixMxN> jet::MatrixMxN< T >::rmul | ( | const T & | s | ) | const |
Returns input scalar * this matrix.
size_t jet::MatrixMxN< T >::rows | ( | ) | const |
Returns number of rows of this matrix.
MatrixSub<T, MatrixMxN, E> jet::MatrixMxN< T >::rsub | ( | const E & | m | ) | const |
Returns input matrix - this matrix (element-wise).
MatrixScalarRSub<T, MatrixMxN> jet::MatrixMxN< T >::rsub | ( | const T & | s | ) | const |
Returns input scalar - this matrix.
void jet::MatrixMxN< T >::set | ( | const MatrixExpression< T, E > & | other | ) |
Copies from input matrix expression.
void jet::MatrixMxN< T >::set | ( | const std::initializer_list< std::initializer_list< T >> & | lst | ) |
Sets a matrix with given initializer list lst
.
This function will fill the matrix with given initializer list lst
such as
Note the initializer has 4x3 structure which will resize to 4x3 matrix.
lst | Initializer list that should be copy to the new matrix. |
void jet::MatrixMxN< T >::set | ( | const T & | s | ) |
Sets whole matrix with input scalar.
void jet::MatrixMxN< T >::set | ( | size_t | m, |
size_t | n, | ||
const T * | arr | ||
) |
Copies from input array.
void jet::MatrixMxN< T >::setColumn | ( | size_t | j, |
const VectorExpression< T, E > & | col | ||
) |
Sets j-th column with input vector.
void jet::MatrixMxN< T >::setDiagonal | ( | const T & | s | ) |
Sets diagonal elements with input scalar.
void jet::MatrixMxN< T >::setOffDiagonal | ( | const T & | s | ) |
Sets off-diagonal elements with input scalar.
void jet::MatrixMxN< T >::setRow | ( | size_t | i, |
const VectorExpression< T, E > & | row | ||
) |
Sets i-th row with input vector.
Size2 jet::MatrixMxN< T >::size | ( | ) | const |
Returns the size of this matrix.
MatrixTriangular<T, MatrixMxN> jet::MatrixMxN< T >::strictLowerTri | ( | ) | const |
Returns strictly lower triangle part of this matrix.
MatrixTriangular<T, MatrixMxN> jet::MatrixMxN< T >::strictUpperTri | ( | ) | const |
Returns strictly upper triangle part of this matrix.
MatrixSub<T, MatrixMxN, E> jet::MatrixMxN< T >::sub | ( | const E & | m | ) | const |
Returns this matrix - input matrix (element-wise).
MatrixScalarSub<T, MatrixMxN> jet::MatrixMxN< T >::sub | ( | const T & | s | ) | const |
Returns this matrix - input scalar.
T jet::MatrixMxN< T >::sum | ( | ) | const |
Returns sum of all elements.
T jet::MatrixMxN< T >::trace | ( | ) | const |
Returns sum of all diagonal elements.
void jet::MatrixMxN< T >::transpose | ( | ) |
Transposes this matrix.
MatrixMxN jet::MatrixMxN< T >::transposed | ( | ) | const |
Returns transposed matrix.
MatrixTriangular<T, MatrixMxN> jet::MatrixMxN< T >::upperTri | ( | ) | const |
Returns upper triangle part of this matrix (including the diagonal).