Library of Assembled Shared Sources
|
a dynamic sized n-dimensional matrix with expression templates More...
#include <matrix.h>
Public Member Functions | |
Matrix () | |
constructs an empty matrix | |
Matrix (TSize rows, TSize columns) | |
Construct a matrix of dimension rows x columns. | |
template<typename T2, typename S2> | |
Matrix (const Matrix< T2, S2 > &other) | |
assign storage/expression matrix to this (this should be a storage matrix). | |
template<typename T2, typename S2> | |
Matrix< T, S > & | operator= (const Matrix< T2, S2 > &other) |
assign storage/expression matrix to this (this should be a storage matrix). | |
const TSize | rows () const |
return number of rows in matrix. | |
const TSize | columns () const |
return number of columns in matrix. | |
const TValue | operator() (TSize row, TSize column) const |
return the component value at position (row, column) | |
TReference | operator() (TSize row, TSize column) |
access the component value at position (row, column) | |
const TValue | at (TSigned row, TSigned column) const |
return the component value at position (row, column) (row, column) will be wrapped to range [0, this->rows()) x [0, this->columns()] by using a modulus operator | |
TReference | at (TSigned row, TSigned column) |
access the component value at position (row, column) (row, column) will be wrapped to range [0, this->rows()) x [0, this->columns()] by using a modulus operator | |
ConstRow | row (TSigned index) const |
return a row of matrix. | |
Row | row (TSigned index) |
return a row of matrix. | |
ConstColumn | column (TSigned index) const |
return a column of matrix. | |
Column | column (TSigned index) |
return a column of matrix. | |
const Matrix< T, S > & | operator+ () const |
A weird way to get back the same object. | |
const Matrix< T, impl::MNeg< T, S > > | operator- () const |
return a vector with all components negated (-a)(i, j) == -(a(i, j)). | |
template<typename S2> | |
Matrix< T, S > & | operator+= (const Matrix< T, S2 > &other) |
componentswise addition assignment of two matrices | |
template<typename S2> | |
Matrix< T, S > & | operator-= (const Matrix< T, S2 > &other) |
componentswise subtraction assignment of two matrices This method is equivalent to this+=(-iB) . | |
Matrix< T, S > & | operator*= (TParam scalar) |
scalar multiplication assignment of matrix | |
Matrix< T, S > & | operator/= (TParam scalar) |
scalar multiplication assignment of matrix | |
void | setZero (TSize rows, TSize columns) |
set this to a zero matrix of rows rows and columns columns. | |
void | setIdentity (TSize size) |
set matrix to an identity matrix. | |
bool | isEmpty () const |
return true if this is a (0�0) matrix | |
bool | isZero () const |
test if this matrix equals a zero matrix. | |
bool | isIdentity () const |
test if this matrix equals a identity matrix | |
bool | isDiagonal () const |
test if this matrix is an diagonal matrix | |
bool | isSquare () const |
return true if matrix has as many rows as columns | |
const Matrix< T, impl::MTrans< T, S > > | transposed () const |
return transposed matrix | |
void | invert () |
replace matrix by its inverse. | |
void | swap (Matrix< T, S > &other) |
swap two matrices | |
Related Symbols | |
(Note that these are not member symbols.) | |
template<typename T, typename S1, typename S2> | |
bool | operator== (const Matrix< T, S1 > &a, const Matrix< T, S2 > &b) |
template<typename T, typename S1, typename S2> | |
bool | operator!= (const Matrix< T, S1 > &a, const Matrix< T, S2 > &b) |
template<typename T, typename S1, typename S2> | |
const Matrix< T, impl::MAdd< T, S1, S2 > > | operator+ (const Matrix< T, S1 > &a, const Matrix< T, S2 > &b) |
componentwise addition | |
template<typename T, typename S1, typename S2> | |
const Matrix< T, impl::MSub< T, S1, S2 > > | operator- (const Matrix< T, S1 > &a, const Matrix< T, S2 > &b) |
componentwise addition | |
template<typename T, typename S1, typename S2> | |
const Matrix< T, impl::MProd< T, S1, S2 > > | operator* (const Matrix< T, S1 > &a, const Matrix< T, S2 > &b) |
Matrix multiplication. | |
template<typename T, typename S> | |
const Matrix< T, impl::MAdd< T, impl::MScalar< T >, S > > | operator+ (const T &a, const Matrix< T, S > &b) |
add a to all components of b | |
template<typename T, typename S> | |
const Matrix< T, impl::MSub< T, impl::MScalar< T >, S > > | operator- (const T &a, const Matrix< T, S > &b) |
add a to all negated components of b | |
template<typename T, typename S> | |
const Matrix< T, impl::MMul< T, impl::MScalar< T >, S > > | operator* (const T &a, const Matrix< T, S > &b) |
multiply a with all components of b | |
template<typename T, typename S> | |
const Matrix< T, impl::MAdd< T, S, impl::MScalar< T > > > | operator+ (const Matrix< T, S > &a, typename Matrix< T, S >::TParam b) |
add b to all components of a | |
template<typename T, typename S> | |
const Matrix< T, impl::MAdd< T, S, impl::MScalar< T > > > | operator- (const Matrix< T, S > &a, typename Matrix< T, S >::TParam b) |
subtract b from all components of a | |
template<typename T, typename S> | |
const Matrix< T, impl::MMul< T, S, impl::MScalar< T > > > | operator* (const Matrix< T, S > &a, typename Matrix< T, S >::TParam b) |
multiply all components of a with b. | |
template<typename T, typename S> | |
const Matrix< T, impl::MMul< T, S, impl::MScalar< T > > > | operator/ (const Matrix< T, S > &a, typename Matrix< T, S >::TParam b) |
divide all components of a by b. | |
template<typename T, typename S, typename S2> | |
void | solve (const Matrix< T, S > &a, Matrix< T, S2 > &bx, bool improve) |
solve equation A * X = B | |
a dynamic sized n-dimensional matrix with expression templates
lass::num::Matrix< T, S >::Matrix | ( | ) |
constructs an empty matrix
Definition at line 84 of file matrix.inl.
Referenced by invert(), Matrix(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/=(), swap(), and transposed().
|
explicit |
Construct a matrix of dimension rows x columns.
Can be used as default constructor for storage in containers.
rows | the number of rows of the matrix to be created. |
columns | the number of columns of the matrix to be created. By default both rows and columns are zero, what creates an empty matrix. Not very usefull though, except as place holder. So, it's safe to pass zero as arguments, but you shouldn't pass negative values. |
Definition at line 106 of file matrix.inl.
lass::num::Matrix< T, S >::Matrix | ( | const Matrix< T2, S2 > & | other | ) |
assign storage/expression matrix to this (this should be a storage matrix).
this
must be an l-value (storage matrix).Definition at line 133 of file matrix.inl.
References columns(), LASS_META_ASSERT, Matrix(), and rows().
Matrix< T, S > & lass::num::Matrix< T, S >::operator= | ( | const Matrix< T2, S2 > & | other | ) |
assign storage/expression matrix to this (this should be a storage matrix).
this
must be an l-value (storage matrix).Definition at line 164 of file matrix.inl.
|
inline |
return number of rows in matrix.
Definition at line 196 of file matrix.inl.
Referenced by at(), at(), invert(), isDiagonal(), isIdentity(), isZero(), Matrix(), Matrix(), operator()(), operator()(), operator*(), operator*(), operator*=(), operator+(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/=(), operator==(), row(), row(), setZero(), and solve().
|
inline |
return number of columns in matrix.
Definition at line 215 of file matrix.inl.
Referenced by at(), at(), column(), column(), isDiagonal(), isIdentity(), isZero(), Matrix(), Matrix(), operator()(), operator()(), operator*(), operator*(), operator*=(), operator+=(), operator-=(), operator/(), operator/=(), operator==(), setZero(), and solve().
|
inline |
|
inline |
access the component value at position (row, column)
this
must be an l-value (storage matrix). Definition at line 246 of file matrix.inl.
References columns(), LASS_META_ASSERT, and rows().
|
inline |
access the component value at position (row, column) (row, column) will be wrapped to range [0, this->rows()) x [0, this->columns()] by using a modulus operator
this
must be an l-value (storage matrix). Definition at line 276 of file matrix.inl.
References column(), columns(), LASS_META_ASSERT, row(), and rows().
|
inline |
return a row of matrix.
index will be wrapped to range [0, this->rows()) by using a modulus operator
Definition at line 289 of file matrix.inl.
References rows().
Referenced by at(), at(), and operator()().
|
inline |
return a row of matrix.
index will be wrapped to range [0, this->rows()) by using a modulus operator. THIS MUST BE LVALUE (storage matrix).
Definition at line 302 of file matrix.inl.
References rows().
|
inline |
return a column of matrix.
index will be wrapped to range [0, this->columns()) by using a modulus operator
Definition at line 314 of file matrix.inl.
References columns().
Referenced by at(), at(), invert(), operator()(), and solve().
|
inline |
return a column of matrix.
index will be wrapped to range [0, this->columns()) by using a modulus operator THIS MUST BE LVALUE (storage matrix).
Definition at line 327 of file matrix.inl.
References columns().
|
inline |
A weird way to get back the same object.
Definition at line 343 of file matrix.inl.
References Matrix().
const Matrix< T, impl::MNeg< T, S > > lass::num::Matrix< T, S >::operator- | ( | ) | const |
return a vector with all components negated (-a)(i, j) == -(a(i, j)).
Definition at line 361 of file matrix.inl.
References Matrix().
Matrix< T, S > & lass::num::Matrix< T, S >::operator+= | ( | const Matrix< T, S2 > & | other | ) |
componentswise addition assignment of two matrices
Matrix Addition: Denote the sum of two matrices
A and
B (of the same dimensions) by
C=A+B. The sum is defined by adding entries with the same indices
Cij=Aij+Bij over all
i and
j. http://mathworld.wolfram.com/MatrixAddition.html
This method implements the assignment addition what reduces to
Aij+=Bij over all
i and
j.
this
must be an l-value (storage matrix).an | exception is thrown if *this and iB are not of the same dimensions |
Definition at line 388 of file matrix.inl.
References columns(), LASS_META_ASSERT, Matrix(), and rows().
Matrix< T, S > & lass::num::Matrix< T, S >::operator-= | ( | const Matrix< T, S2 > & | other | ) |
componentswise subtraction assignment of two matrices This method is equivalent to
this+=(-iB) .
this
must be an l-value (storage matrix).an | exception is thrown if *this and iB are not of the same dimensions |
Definition at line 421 of file matrix.inl.
References columns(), LASS_META_ASSERT, Matrix(), and rows().
Matrix< T, S > & lass::num::Matrix< T, S >::operator*= | ( | TParam | scalar | ) |
scalar multiplication assignment of matrix
this
must be an l-value (storage matrix).Definition at line 448 of file matrix.inl.
References columns(), LASS_META_ASSERT, Matrix(), and rows().
Matrix< T, S > & lass::num::Matrix< T, S >::operator/= | ( | TParam | scalar | ) |
scalar multiplication assignment of matrix
this
must be an l-value (storage matrix). Definition at line 470 of file matrix.inl.
References columns(), LASS_META_ASSERT, Matrix(), and rows().
void lass::num::Matrix< T, S >::setZero | ( | TSize | rows, |
TSize | columns ) |
set this to a zero matrix of rows rows and columns columns.
Definition at line 496 of file matrix.inl.
References columns(), LASS_META_ASSERT, and rows().
void lass::num::Matrix< T, S >::setIdentity | ( | TSize | iSize | ) |
set matrix to an identity matrix.
Definition at line 520 of file matrix.inl.
References LASS_META_ASSERT.
Referenced by invert().
bool lass::num::Matrix< T, S >::isEmpty | ( | ) | const |
return true if this is a (0�0) matrix
Definition at line 544 of file matrix.inl.
bool lass::num::Matrix< T, S >::isZero | ( | ) | const |
test if this matrix equals a zero matrix.
A zero matrix is an
m�n matrix consisting of all 0s (MacDuffee 1943, p. 27), denoted
0. Zero matrices are sometimes also known as null matrices (Akivis and Goldberg 1972, p. 71). http://mathworld.wolfram.com/ZeroMatrix.html
an empty matrix is also a zero matrix.
Definition at line 563 of file matrix.inl.
bool lass::num::Matrix< T, S >::isIdentity | ( | ) | const |
test if this matrix equals a identity matrix
The identity matrix is a the simplest nontrivial diagonal matrix, defined such that
I(X)=X for all vectors
X. An identity matrix may be denoted
1,
I, or
E (the latter being an abbreviation for the German term "Einheitsmatrix"; Courant and Hilbert 1989, p. 7). Identity matrices are sometimes also known as unit matrices (Akivis and Goldberg 1972, p. 71). The
n�n identity matrix is given explicitly by
Iij=dij for
i,
j = 1, 2, ..., n, where
dij is the Kronecker delta. http://mathworld.wolfram.com/IdentityMatrix.html
an empty matrix is also an identity matrix.
Definition at line 598 of file matrix.inl.
References columns(), isSquare(), and rows().
bool lass::num::Matrix< T, S >::isDiagonal | ( | ) | const |
test if this matrix is an diagonal matrix
A diagonal matrix is a square matrix
A of the form
Aij=Ci*dij where
dij is the Kronecker delta,
Ci are constants, and
i,
j = 1, 2, ..., n, with is no implied summation over indices. http://mathworld.wolfram.com/DiagonalMatrix.html
Definition at line 634 of file matrix.inl.
References columns(), isSquare(), and rows().
bool lass::num::Matrix< T, S >::isSquare | ( | ) | const |
return true if matrix has as many rows as columns
Definition at line 663 of file matrix.inl.
Referenced by invert(), isDiagonal(), isIdentity(), and solve().
const Matrix< T, impl::MTrans< T, S > > lass::num::Matrix< T, S >::transposed | ( | ) | const |
return transposed matrix
Definition at line 677 of file matrix.inl.
References Matrix().
void lass::num::Matrix< T, S >::invert | ( | ) |
replace matrix by its inverse.
If matrix has no inverse (this is singular), no exception is thrown. Instead, an empty matrix is made.
this
must be an l-value (storage matrix).an | exception is thrown if this is not a square matrix |
Definition at line 696 of file matrix.inl.
References column(), isSquare(), LASS_META_ASSERT, Matrix(), rows(), and setIdentity().
|
inline |
swap two matrices
this
and other must be an l-value (storage matrix).Definition at line 750 of file matrix.inl.
References LASS_META_ASSERT, and Matrix().
|
Definition at line 774 of file matrix.inl.
|
Definition at line 804 of file matrix.inl.
|
Matrix multiplication.
The product
C of two matrices
A and
B is defined by
Cik=Aij*Bjk, where
j is summed over for all possible values of
i and
k. The implied summation over repeated indices without the presence of an explicit sum sign is called Einstein summation, and is commonly used in both matrix and tensor analysis. Therefore, in order for matrix multiplication to be defined, the dimensions of the matrices must satisfy
(n�m)*(m�p)=(n�p) where
(a�b) denotes a matrix with
a rows and
b columns. http://mathworld.wolfram.com/MatrixMultiplication.html
an | exception is throw in a and b don't meet the requirement a.columns()==b.rows() . |
Definition at line 864 of file matrix.inl.
|
solve equation A * X = B
a | [in] matrix A |
bx | [in,out] serves both as the input matrix B and the output matrix X. |
improve | [in] if true, it will perform an extra iteration to improve the solution, but it comes at the cost of having to take an extra copy of a. |
an | exception is thrown if dimensions don't match (this->isSquare() && this->columns() == bx.rows()) |
Definition at line 1006 of file matrix.inl.