This template class is an abstraction of a small matrix with a size known at compile time.
More...
|
| Matrix (double fillValue) |
|
| Matrix (const double(&initArray)[Rows *Cols]) |
|
template<typename... Doubles, typename = typename std::enable_if<sizeof...(Doubles) + 1u == Rows * Cols>::type> |
| Matrix (double firstElement, Doubles... matrixElements) |
|
template<uint fromRow, uint toRow, uint fromCol, uint toCol> |
auto | subMat () const -> Matrix< details::rangeDim(fromRow, toRow), details::rangeDim(fromCol, toCol)> |
|
template<uint from, uint to> |
auto | subMat () const -> Matrix< details::vecRangeDim< Rows >(from, to), details::vecRangeDim< Cols >(from, to)> |
|
template<uint i> |
Matrix< 1, Cols > | row () const |
|
template<uint j> |
Matrix< Rows, 1 > | column () const |
|
void | fill (double fillValue) |
|
void | normalize () |
|
Matrix< Rows, Cols > | normalized () const |
|
double | trace () const |
|
Matrix< Cols, Rows > | transposed () const |
|
template<uint NewRows, uint NewCols> |
Matrix< NewRows, NewCols > | reshaped () const |
|
Matrix< Rows *Cols, 1 > | reshapedAsVector () const |
|
Matrix< Rows, Cols > | operator- () const |
|
Matrix< Rows, Cols > & | operator *= (double scalar) |
|
Matrix< Rows, Cols > & | operator/= (double scalar) |
|
Matrix< Rows, Cols > & | operator+= (const Matrix< Rows, Cols > &rhs) |
|
Matrix< Rows, Cols > & | operator-= (const Matrix< Rows, Cols > &rhs) |
|
Matrix< Rows, Cols > & | operator%= (const Matrix< Rows, Cols > &rhs) |
|
Matrix< Rows, Cols > & | operator|= (const Matrix< Rows, Cols > &rhs) |
|
Matrix< Rows, Cols > | operator * (double scalar) const |
|
Matrix< Rows, Cols > | operator/ (double scalar) const |
|
Matrix< Rows, Cols > | operator+ (const Matrix< Rows, Cols > &rhs) const |
|
Matrix< Rows, Cols > | operator- (const Matrix< Rows, Cols > &rhs) const |
|
template<uint Cols2> |
Matrix< Rows, Cols2 > | operator * (const Matrix< Cols, Cols2 > &rhs) const |
|
Matrix< Rows, Cols > | operator% (const Matrix< Rows, Cols > &rhs) const |
|
Matrix< Rows, Cols > | operator| (const Matrix< Rows, Cols > &rhs) const |
|
| MatrixBase (double fillValue) |
|
| MatrixBase (const double(&initArray)[Rows *Cols]) |
|
template<typename... Doubles> |
| MatrixBase (double firstElement, Doubles... matrixElements) |
|
double * | operator[] (uint row) |
|
const double * | operator[] (uint row) const |
|
double & | operator() (uint row, uint column) |
|
double | operator() (uint row, uint column) const |
|
double & | at (uint row, uint column) noexcept(false) |
|
double | at (uint row, uint column) const noexcept(false) |
|
template<uint row, uint column> |
double & | get () noexcept |
|
template<uint row, uint column> |
double | get () const noexcept |
|
double & | operator() (uint n) |
|
double | operator() (uint n) const |
|
double & | at (uint n) |
|
double | at (uint n) const |
|
template<uint n> |
double & | get () noexcept |
|
template<uint n> |
double | get () const noexcept |
|
double * | data () |
|
const double * | data () const |
|
const double * | constData () const |
|
double * | begin () |
|
const double * | begin () const |
|
const double * | constBegin () const |
|
double * | end () |
|
const double * | end () const |
|
const double * | constEnd () const |
|
constexpr size_t | size () const |
|
std::string | info (const char *lineModifier="") const |
|
double | norm () const |
|
bool | operator== (const MatrixBase< Rows, Cols > &rhs) const |
|
bool | operator!= (const MatrixBase< Rows, Cols > &rhs) const |
|
|
(Note that these are not member functions.)
|
template<uint Rows, uint Cols> |
Matrix< Rows, Cols > | operator * (double scalar, const Matrix< Rows, Cols > &rhs) |
|
template<uint N> |
double | dot (const Matrix< N, 1 > &vector1, const Matrix< N, 1 > &vector2) |
|
template<uint N> |
double | dot (const Matrix< 1, N > &vector1, const Matrix< 1, N > &vector2) |
|
template<uint N> |
double | dot (const Matrix< N, 1 > &vector1, const Matrix< 1, N > &vector2) |
|
template<uint N> |
double | dot (const Matrix< 1, N > &vector1, const Matrix< N, 1 > &vector2) |
|
template<uint N> |
Matrix< N, N > | diag (const Matrix< N, 1 > &diagElements) |
|
template<uint Rows, uint Cols> |
Matrix< Rows, Cols > | diag (const Matrix< details::minDim(Rows, Cols), 1 > &diagElements) |
|
template<uint Rows, uint Cols> |
auto | diag (const Matrix< Rows, Cols > &m) -> Matrix< details::minDim(Rows, Cols), 1 > |
|
template<uint N> |
Matrix< N, N > | eye () |
|
template<uint Rows, uint Cols> |
Matrix< Rows, Cols > | eye () |
|
template<uint Rows, uint Cols1, uint Cols2> |
Matrix< Rows, Cols1+Cols2 > | horzcat (const Matrix< Rows, Cols1 > &m1, const Matrix< Rows, Cols2 > &m2) |
|
template<uint Rows1, uint Rows2, uint Cols> |
Matrix< Rows1+Rows2, Cols > | vertcat (const Matrix< Rows1, Cols > &m1, const Matrix< Rows2, Cols > &m2) |
|
template<uint Rows, uint Cols>
class CTL::mat::Matrix< Rows, Cols >
This template class is an abstraction of a small matrix with a size known at compile time.
Basic algebraic operations are provided and dimension checks are carried out during compilation. No heap allocation is performed. Elements are stored in row major order.
template<uint Rows, uint Cols>
template<typename... Doubles, typename >
Construct an instance from a list of arguments that specifies each element in row major order. The length of the argument list must match the total number of matrix elements, otherwise it results in a compilation error.
Matrix<3, 3> M{ 1.1, 1.2, 1.3,
2.1, 2.2, 2.3,
3.1, 3.2, 3.3 };
template<uint Rows, uint Cols>
template<class Container >
Matrix< Rows, Cols > CTL::mat::Matrix< Rows, Cols >::fromContainer |
( |
const Container & |
vector, |
|
|
size_t |
NthMat, |
|
|
bool * |
ok = nullptr |
|
) |
| |
|
static |
Returns a Rows x Cols matrix that is extracted from a vector that stores these matrices in row major order. The NthMat matrix is read from the container, meaning that NthMat*Rows
*Cols
elements are skipped. Optionally, a pointer ok to a boolean can be passed to check if the reading was successful. It is set to false
if the vector size would be exceeded. In this case it returns a zero-initialized matrix.
template<uint Rows, uint Cols>
template<uint fromRow, uint toRow, uint fromCol, uint toCol>
auto CTL::mat::Matrix< Rows, Cols >::subMat |
( |
| ) |
const -> Matrix<details::rangeDim(fromRow, toRow),
details::rangeDim(fromCol, toCol)> |
subMat<fromRow, toRow, fromCol, toCol>()
returns a submatrix specified by the boundary indices for the rows (fromRow, toRow) and for the columns (fromCol, toCol). For instance M.subMat<0,1, 1,1>()
will return the first to elements of the second column of M
as a 2x1 matrix (vector) if the dimensions of the matrix M
are at least 2x2, otherwise (in case the dimensions are exceeded) it results in a compiler error. Except the size of the matrix from which is extracted, there are no further limitation for choosing the boundaries (the template arguments). The dimension of the returned matrix is abs(toRow-fromRow+1) x abs(toCol-fromCol+1)
. If a 'from' index is larger than a 'to' index, the submatrix is extracted in reverse order, e.g. M.subMat<1,0, 0,1>()
returns the upper left 2x2 submatrix with its rows flipped in the up-down direction.
const Matrix<2, 2> mat{ 11., 12.,
21., 22. };
bool test = (mat.subMat<1,1, 1,1>() == 22.);
template<uint Rows, uint Cols>
template<uint from, uint to>
auto CTL::mat::Matrix< Rows, Cols >::subMat |
( |
| ) |
const -> Matrix<details::vecRangeDim<Rows>(from, to),
details::vecRangeDim<Cols>(from, to)> |
This subvector extraction is a simplified overload of subMat<fromRow, toRow, fromCol, toCol>()
that is more handy to use for vectors. The behavior of subMat<from, to>()
is equivalent to subMat<from, to, 0, 0>()
for column vectors or subMat<0, 0, from, to>()
for row vectors.