This class represents a small matrix whose size is known at compile time, containing elements of any Composite Numerical Type (CNT) and engineered to have no runtime overhead whatsoever.
More...
|
| ScalarNormSq | scalarNormSqr () const |
| | Scalar norm square is the sum of squares of all the scalars that comprise the value of this Mat.
|
| |
| TSqrt | sqrt () const |
| | Elementwise square root; that is, the return value has the same dimensions as this Mat but with each element replaced by whatever it thinks its square root is.
|
| |
| TAbs | abs () const |
| | Elementwise absolute value; that is, the return value has the same dimensions as this Mat but with each element replaced by whatever it thinks its absolute value is.
|
| |
| TStandard | standardize () const |
| |
| | Mat () |
| | Default construction initializes to NaN when debugging but is left uninitialized otherwise to ensure that there is no overhead.
|
| |
| | Mat (const Mat &src) |
| | Copy constructor copies only the elements that are present and does not touch any unused memory space between them if they are not packed.
|
| |
| Mat & | operator= (const Mat &src) |
| | Copy assignment copies only the elements that are present and does not touch any unused memory space between them if they are not packed.
|
| |
| | Mat (const SymMat< M, ELT > &src) |
| | Explicit construction of a Mat from a SymMat (symmetric/Hermitian matrix).
|
| |
| template<int CSS, int RSS> |
| | Mat (const Mat< M, N, E, CSS, RSS > &src) |
| | This provides an implicit conversion from a Mat of the same dimensions and element type but with different element spacing.
|
| |
| template<int CSS, int RSS> |
| | Mat (const Mat< M, N, ENeg, CSS, RSS > &src) |
| | This provides an implicit conversion from a Mat of the same dimensions and negated element type, possibly with different element spacing.
|
| |
| template<class EE , int CSS, int RSS> |
| | Mat (const Mat< M, N, EE, CSS, RSS > &mm) |
| | Explicit construction of a Mat from a source Mat of the same dimensions and an assignment-compatible element type, with any element spacing allowed.
|
| |
| | Mat (const E &e) |
| | Explicit construction from a single element e of this Mat's element type E sets all the main diagonal elements to e but sets the rest of the elements to zero.
|
| |
| | Mat (const ENeg &e) |
| | Explicit construction from a single element e whose type is negator<E> (abbreviated ENeg here) where E is this Mat's element type sets all the main diagonal elements to e but sets the rest of the elements to zero.
|
| |
| | Mat (int i) |
| | Explicit construction from an int value means we convert the int into an object of this Mat's element type E, and then apply the single-element constructor above which sets the Mat to zero except for its main diagonal elements which will all be set to the given value.
|
| |
| template<typename... Elements, typename = std::enable_if_t< (M*N==sizeof...(Elements)) && (std::is_convertible_v<Elements&&, const E&> && ...) >> |
| | Mat (Elements &&... elementsRowByRow) |
| |
| | Mat (const TRow &r0) |
| |
| | Mat (const TRow &r0, const TRow &r1) |
| |
| | Mat (const TRow &r0, const TRow &r1, const TRow &r2) |
| |
| | Mat (const TRow &r0, const TRow &r1, const TRow &r2, const TRow &r3) |
| |
| | Mat (const TRow &r0, const TRow &r1, const TRow &r2, const TRow &r3, const TRow &r4) |
| |
| | Mat (const TRow &r0, const TRow &r1, const TRow &r2, const TRow &r3, const TRow &r4, const TRow &r5) |
| |
| template<class EE , int SS> |
| | Mat (const Row< N, EE, SS > &r0) |
| |
| template<class EE , int SS> |
| | Mat (const Row< N, EE, SS > &r0, const Row< N, EE, SS > &r1) |
| |
| template<class EE , int SS> |
| | Mat (const Row< N, EE, SS > &r0, const Row< N, EE, SS > &r1, const Row< N, EE, SS > &r2) |
| |
| template<class EE , int SS> |
| | Mat (const Row< N, EE, SS > &r0, const Row< N, EE, SS > &r1, const Row< N, EE, SS > &r2, const Row< N, EE, SS > &r3) |
| |
| template<class EE , int SS> |
| | Mat (const Row< N, EE, SS > &r0, const Row< N, EE, SS > &r1, const Row< N, EE, SS > &r2, const Row< N, EE, SS > &r3, const Row< N, EE, SS > &r4) |
| |
| template<class EE , int SS> |
| | Mat (const Row< N, EE, SS > &r0, const Row< N, EE, SS > &r1, const Row< N, EE, SS > &r2, const Row< N, EE, SS > &r3, const Row< N, EE, SS > &r4, const Row< N, EE, SS > &r5) |
| |
| | Mat (const TCol &r0) |
| |
| | Mat (const TCol &r0, const TCol &r1) |
| |
| | Mat (const TCol &r0, const TCol &r1, const TCol &r2) |
| |
| | Mat (const TCol &r0, const TCol &r1, const TCol &r2, const TCol &r3) |
| |
| | Mat (const TCol &r0, const TCol &r1, const TCol &r2, const TCol &r3, const TCol &r4) |
| |
| | Mat (const TCol &r0, const TCol &r1, const TCol &r2, const TCol &r3, const TCol &r4, const TCol &r5) |
| |
| template<class EE , int SS> |
| | Mat (const Vec< M, EE, SS > &r0) |
| |
| template<class EE , int SS> |
| | Mat (const Vec< M, EE, SS > &r0, const Vec< M, EE, SS > &r1) |
| |
| template<class EE , int SS> |
| | Mat (const Vec< M, EE, SS > &r0, const Vec< M, EE, SS > &r1, const Vec< M, EE, SS > &r2) |
| |
| template<class EE , int SS> |
| | Mat (const Vec< M, EE, SS > &r0, const Vec< M, EE, SS > &r1, const Vec< M, EE, SS > &r2, const Vec< M, EE, SS > &r3) |
| |
| template<class EE , int SS> |
| | Mat (const Vec< M, EE, SS > &r0, const Vec< M, EE, SS > &r1, const Vec< M, EE, SS > &r2, const Vec< M, EE, SS > &r3, const Vec< M, EE, SS > &r4) |
| |
| template<class EE , int SS> |
| | Mat (const Vec< M, EE, SS > &r0, const Vec< M, EE, SS > &r1, const Vec< M, EE, SS > &r2, const Vec< M, EE, SS > &r3, const Vec< M, EE, SS > &r4, const Vec< M, EE, SS > &r5) |
| |
| template<class EE > |
| | Mat (const EE *p) |
| |
| template<class EE , int CSS, int RSS> |
| Mat & | operator= (const Mat< M, N, EE, CSS, RSS > &mm) |
| |
| template<class EE > |
| Mat & | operator= (const EE *p) |
| |
| template<class EE , int CSS, int RSS> |
| Mat & | operator+= (const Mat< M, N, EE, CSS, RSS > &mm) |
| |
| template<class EE , int CSS, int RSS> |
| Mat & | operator+= (const Mat< M, N, negator< EE >, CSS, RSS > &mm) |
| |
| template<class EE , int CSS, int RSS> |
| Mat & | operator-= (const Mat< M, N, EE, CSS, RSS > &mm) |
| |
| template<class EE , int CSS, int RSS> |
| Mat & | operator-= (const Mat< M, N, negator< EE >, CSS, RSS > &mm) |
| |
| template<class EE , int CSS, int RSS> |
| Mat & | operator*= (const Mat< N, N, EE, CSS, RSS > &mm) |
| |
| template<class E2 , int CS2, int RS2> |
| Result< Mat< M, N, E2, CS2, RS2 > >::Add | conformingAdd (const Mat< M, N, E2, CS2, RS2 > &r) const |
| |
| template<class E2 , int CS2, int RS2> |
| Result< Mat< M, N, E2, CS2, RS2 > >::Sub | conformingSubtract (const Mat< M, N, E2, CS2, RS2 > &r) const |
| |
| template<class E2 , int CS2, int RS2> |
| Mat< M, N, E2, CS2, RS2 >::template Result< Mat >::Sub | conformingSubtractFromLeft (const Mat< M, N, E2, CS2, RS2 > &l) const |
| |
| template<class E2 , int CS2, int RS2> |
| EltResult< E2 >::Mul | elementwiseMultiply (const Mat< M, N, E2, CS2, RS2 > &r) const |
| |
| template<class E2 , int CS2, int RS2> |
| EltResult< E2 >::Dvd | elementwiseDivide (const Mat< M, N, E2, CS2, RS2 > &r) const |
| |
| template<class E2 , int RS2> |
| Result< SymMat< M, E2, RS2 > >::Add | conformingAdd (const SymMat< M, E2, RS2 > &sy) const |
| |
| template<class E2 , int RS2> |
| Result< SymMat< M, E2, RS2 > >::Sub | conformingSubtract (const SymMat< M, E2, RS2 > &sy) const |
| |
| template<class E2 , int RS2> |
| SymMat< M, E2, RS2 >::template Result< Mat >::Sub | conformingSubtractFromLeft (const SymMat< M, E2, RS2 > &sy) const |
| |
| template<int N2, class E2 , int CS2, int RS2> |
| Result< Mat< N, N2, E2, CS2, RS2 > >::Mul | conformingMultiply (const Mat< N, N2, E2, CS2, RS2 > &m) const |
| |
| template<int M2, class E2 , int CS2, int RS2> |
| Mat< M2, M, E2, CS2, RS2 >::template Result< Mat >::Mul | conformingMultiplyFromLeft (const Mat< M2, M, E2, CS2, RS2 > &m) const |
| |
| template<int M2, class E2 , int CS2, int RS2> |
| Result< Mat< M2, N, E2, CS2, RS2 > >::Dvd | conformingDivide (const Mat< M2, N, E2, CS2, RS2 > &m) const |
| |
| template<int M2, class E2 , int CS2, int RS2> |
| Mat< M2, N, E2, CS2, RS2 >::template Result< Mat >::Dvd | conformingDivideFromLeft (const Mat< M2, N, E2, CS2, RS2 > &m) const |
| |
| const TRow & | operator[] (int i) const |
| |
| TRow & | operator[] (int i) |
| |
| const TCol & | operator() (int j) const |
| |
| TCol & | operator() (int j) |
| |
| const E & | operator() (int i, int j) const |
| |
| E & | operator() (int i, int j) |
| |
| ScalarNormSq | normSqr () const |
| |
| CNT< ScalarNormSq >::TSqrt | norm () const |
| |
| TNormalize | normalize () const |
| |
| TInvert | invert () const |
| |
| const Mat & | operator+ () const |
| |
| const TNeg & | operator- () const |
| |
| TNeg & | operator- () |
| |
| const THerm & | operator~ () const |
| |
| THerm & | operator~ () |
| |
| const TNeg & | negate () const |
| |
| TNeg & | updNegate () |
| |
| const THerm & | transpose () const |
| |
| THerm & | updTranspose () |
| |
| const TPosTrans & | positionalTranspose () const |
| |
| TPosTrans & | updPositionalTranspose () |
| |
| const TReal & | real () const |
| |
| TReal & | real () |
| |
| const TImag & | imag () const |
| |
| TImag & | imag () |
| |
| const TWithoutNegator & | castAwayNegatorIfAny () const |
| |
| TWithoutNegator & | updCastAwayNegatorIfAny () |
| |
| const TRow & | row (int i) const |
| |
| TRow & | row (int i) |
| |
| const TCol & | col (int j) const |
| |
| TCol & | col (int j) |
| |
| const E & | elt (int i, int j) const |
| |
| E & | elt (int i, int j) |
| |
| const TDiag & | diag () const |
| | Select main diagonal (of largest leading square if rectangular) and return it as a read-only view (as a Vec) of the diagonal elements of this Mat.
|
| |
| TDiag & | updDiag () |
| | Select main diagonal (of largest leading square if rectangular) and return it as a writable view (as a Vec) of the diagonal elements of this Mat.
|
| |
| TDiag & | diag () |
| | This non-const version of diag() is an alternate name for updDiag() available for historical reasons.
|
| |
| EStandard | trace () const |
| |
| template<class EE > |
| Mat< M, N, typename CNT< E >::template Result< EE >::Mul > | scalarMultiply (const EE &e) const |
| |
| template<class EE > |
| Mat< M, N, typename CNT< EE >::template Result< E >::Mul > | scalarMultiplyFromLeft (const EE &e) const |
| |
| template<class EE > |
| Mat< M, N, typename CNT< E >::template Result< EE >::Dvd > | scalarDivide (const EE &e) const |
| |
| template<class EE > |
| Mat< M, N, typename CNT< EE >::template Result< E >::Dvd > | scalarDivideFromLeft (const EE &e) const |
| |
| template<class EE > |
| Mat< M, N, typename CNT< E >::template Result< EE >::Add > | scalarAdd (const EE &e) const |
| |
| template<class EE > |
| Mat< M, N, typename CNT< E >::template Result< EE >::Sub > | scalarSubtract (const EE &e) const |
| |
| template<class EE > |
| Mat< M, N, typename CNT< EE >::template Result< E >::Sub > | scalarSubtractFromLeft (const EE &e) const |
| |
| template<class EE > |
| Mat & | operator= (const EE &e) |
| |
| template<class EE > |
| Mat & | operator+= (const EE &e) |
| |
| template<class EE > |
| Mat & | operator-= (const EE &e) |
| |
| template<class EE > |
| Mat & | operator*= (const EE &e) |
| |
| template<class EE > |
| Mat & | operator/= (const EE &e) |
| |
| template<class EE > |
| Mat & | scalarEq (const EE &ee) |
| |
| template<class EE > |
| Mat & | scalarPlusEq (const EE &ee) |
| |
| template<class EE > |
| Mat & | scalarMinusEq (const EE &ee) |
| |
| template<class EE > |
| Mat & | scalarMinusEqFromLeft (const EE &ee) |
| |
| template<class EE > |
| Mat & | scalarTimesEq (const EE &ee) |
| |
| template<class EE > |
| Mat & | scalarTimesEqFromLeft (const EE &ee) |
| |
| template<class EE > |
| Mat & | scalarDivideEq (const EE &ee) |
| |
| template<class EE > |
| Mat & | scalarDivideEqFromLeft (const EE &ee) |
| |
| void | setToNaN () |
| |
| void | setToZero () |
| |
| template<int MM, int NN> |
| const SubMat< MM, NN >::Type & | getSubMat (int i, int j) const |
| |
| template<int MM, int NN> |
| SubMat< MM, NN >::Type & | updSubMat (int i, int j) |
| |
| template<int MM, int NN> |
| void | setSubMat (int i, int j, const typename SubMat< MM, NN >::Type &value) |
| |
| TDropRow | dropRow (int i) const |
| | Return a matrix one row smaller than this one by dropping row i.
|
| |
| TDropCol | dropCol (int j) const |
| | Return a matrix one column smaller than this one by dropping column j.
|
| |
| TDropRowCol | dropRowCol (int i, int j) const |
| | Return a matrix one row and one column smaller than this one by dropping row i and column j.
|
| |
| template<class EE , int SS> |
| TAppendRow | appendRow (const Row< N, EE, SS > &row) const |
| | Return a matrix one row larger than this one by adding a row to the end.
|
| |
| template<class EE , int SS> |
| TAppendCol | appendCol (const Vec< M, EE, SS > &col) const |
| | Return a matrix one column larger than this one by adding a column to the end.
|
| |
| template<class ER , int SR, class EC , int SC> |
| TAppendRowCol | appendRowCol (const Row< N+1, ER, SR > &row, const Vec< M+1, EC, SC > &col) const |
| | Return a matrix one row and one column larger than this one by adding a row to the bottom and a column to the right.
|
| |
| template<class EE , int SS> |
| TAppendRow | insertRow (int i, const Row< N, EE, SS > &row) const |
| | Return a matrix one row larger than this one by inserting a row before row i.
|
| |
| template<class EE , int SS> |
| TAppendCol | insertCol (int j, const Vec< M, EE, SS > &col) const |
| | Return a matrix one column larger than this one by inserting a column before column j.
|
| |
| template<class ER , int SR, class EC , int SC> |
| TAppendRowCol | insertRowCol (int i, int j, const Row< N+1, ER, SR > &row, const Vec< M+1, EC, SC > &col) const |
| | Return a matrix one row and one column larger than this one by inserting a row before row i and a column before column j.
|
| |
| bool | isNaN () const |
| | Return true if any element of this Mat contains a NaN anywhere.
|
| |
| bool | isInf () const |
| | Return true if any element of this Mat contains a +Inf or -Inf somewhere but no element contains a NaN anywhere.
|
| |
| bool | isFinite () const |
| | Return true if no element contains an Infinity or a NaN.
|
| |
| template<class E2 , int CS2, int RS2> |
| bool | isNumericallyEqual (const Mat< M, N, E2, CS2, RS2 > &m, double tol) const |
| | Test whether this matrix is numerically equal to some other matrix with the same shape, using a specified tolerance.
|
| |
| template<class E2 , int CS2, int RS2> |
| bool | isNumericallyEqual (const Mat< M, N, E2, CS2, RS2 > &m) const |
| | Test whether this matrix is numerically equal to some other matrix with the same shape, using a default tolerance which is the looser of the default tolerances of the two objects being compared.
|
| |
| bool | isNumericallyEqual (const ELT &e, double tol=getDefaultTolerance()) const |
| | Test whether this is numerically a "scalar" matrix, meaning that it is a diagonal matrix in which each diagonal element is numerically equal to the same scalar, using either a specified tolerance or the matrix's default tolerance (which is always the same or looser than the default tolerance for one of its elements).
|
| |
| bool | isNumericallySymmetric (double tol=getDefaultTolerance()) const |
| | A Matrix is symmetric (actually Hermitian) if it is square and each element (i,j) is the Hermitian transpose of element (j,i).
|
| |
| bool | isExactlySymmetric () const |
| | A Matrix is symmetric (actually Hermitian) if it is square and each element (i,j) is the Hermitian (conjugate) transpose of element (j,i).
|
| |
| TRow | colSum () const |
| | Returns a row vector (Row) containing the column sums of this matrix.
|
| |
| TRow | sum () const |
| | This is an alternate name for colSum(); behaves like the Matlab function of the same name.
|
| |
| TCol | rowSum () const |
| | Returns a column vector (Vec) containing the row sums of this matrix.
|
| |
| std::string | toString () const |
| | toString() returns a string representation of the Mat.
|
| |
| const ELT & | get (int i, int j) const |
| | Variant of indexing operator that's scripting friendly to get entry (i, j)
|
| |
| void | set (int i, int j, const ELT &value) |
| | Variant of indexing operator that's scripting friendly to set entry (i, j)
|
| |
This class represents a small matrix whose size is known at compile time, containing elements of any Composite Numerical Type (CNT) and engineered to have no runtime overhead whatsoever.
Memory layout defaults to packed, column-ordered storage but can be specified to have any regular row and column spacing. A Mat object is itself a Composite Numerical Type and can thus be the element type for other matrix and vector types. Some common use cases are provided below.
- Template Parameters
-
| M | The number of rows in this matrix (no default). |
| N | The number of columns in this matrix (no default). |
| ELT | The element type; default is Real. |
| CS | Column spacing in memory as a multiple of element size (default M). |
| RS | Row spacing in memory as a multiple of element size (default 1). |
Construction
A 3x3 identity matrix can be constructed in the following ways:
Mat<3,3,Real>(1,0,0, 0,1,0, 0,0,1);
Mat33(1,0,0,0,1,0,0,0,1);
This class represents a small matrix whose size is known at compile time, containing elements of any ...
Definition Mat.h:100
Mat< 3, 3 > Mat33
This is the most common 3x3 matrix type: three packed columns of 3 Real values each.
Definition SmallMatrix.h:142
Vec< 3 > Vec3
This is the most common 3D vector type: a column of 3 Real values stored consecutively in memory (pac...
Definition SmallMatrix.h:129
Note that the default element type is Real, and that Mat33 is a typedef for Mat<3,3>; analogous typedefs exist for matrices of up to 9x9 elements.
Manipulation
Standard arithmetic operators can be used, as well as methods like trace() and transpose(). Here are some usage examples, each of which prints a 2x2 identity matrix:
std::cout <<
myMat.getSubMat<2,2>(0,1) << std::endl;
std::cout <<
myMat.dropCol(0) << std::endl;
std::cout <<
Mat12(1,0).appendRow(~
Vec2(0,1)) << std::endl;
std::cout <<
Mat21(0,1).insertCol(0,
Vec2(1,0)) << std::endl;
void set(int i, int j, const ELT &value)
Variant of indexing operator that's scripting friendly to set entry (i, j)
Definition Mat.h:1180
Vec< 2 > Vec2
This is the most common 2D vector type: a column of 2 Real values stored consecutively in memory (pac...
Definition SmallMatrix.h:126
Mat< 2, 1 > Mat21
2x1 Real column matrix.
Definition SmallMatrix.h:189
Mat< 1, 2 > Mat12
1x2 Real row matrix.
Definition SmallMatrix.h:180
Conversion
It may be necessary to convert between a Mat and a Matrix (to interface with FactorQTZ, for instance). In the example below, we print a Mat33 created from a 3x3 Matrix:
const THerm & transpose() const
Definition Mat.h:685
Converting from a Mat33 to a Matrix is straightforward:
Matrix_< Real > Matrix
Variable-size 2D matrix of Real elements; abbreviation for Matrix_<Real>.
Definition BigMatrix.h:1482
- See also
- Matrix_ for handling of large or variable-sized matrices.
-
SymMat, Vec, Row