Matrix Class Reference
Last update: 16.07.2025Standard matrix class. More...
Public Types | |
| typedef Eigen::Matrix< TScalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > | Base |
| the type of the ancestor class | |
| typedef TScalar * | TBuffer |
| the data type of the dynamic data buffer (pointer) | |
| typedef Base::Index | TEigenIndex |
| index type for Eigen matrices | |
| typedef number | TScalar |
| the floating point number type of a mtrix element | |
| typedef number | TUnsignedIndex |
| an unsigned index type | |
Public Member Functions | |
| string | __getstate__ () |
| Matrix | __neg__ () const |
| __setstate_internal (string state) | |
| char * | __str__ () |
| transforms this objects into a string, required by SWIG More... | |
| Add (Matrix other) | |
| modifies this matrix by the matrix sum A+B More... | |
| Add (MatrixBlock other) | |
| modifies this matrix by the matrix sum A+B More... | |
| Matrix | AddCol (Matrix m) |
| returns an object including new data data | |
| Matrix | AddRow (Matrix m) |
| Matrix | AppendCols (Matrix m) |
| returns an object with modified data More... | |
| Matrix | AppendRows (Matrix m) |
| returns an object with modified data More... | |
| Assign (Matrix ar) | |
| The assignment operator for matrices (data only) More... | |
| Assign (MatrixBlock ar) | |
| The assignment operator for blocks (data only) More... | |
| MatrixBlock | Block (TUnsignedIndex row, TUnsignedIndex col, TUnsignedIndex numrows, TUnsignedIndex numcols) |
| returns a reference to a block starting at 'row','column' with size 'numrows'*'numcols' More... | |
| MatrixBlock | Col (TUnsignedIndex col) |
| returns a reference to the 'col'th column More... | |
| TUnsignedIndex | Cols () const |
| MatrixBlock | Cols (TUnsignedIndex col1, TUnsignedIndex ncol) |
| returns a block containing the ncol columns starting at column index col1 More... | |
| void | ConservativeResize (TUnsignedIndex rows, TUnsignedIndex cols=1) |
| resizes the matrix to its new dimensions without destroying the contents. More... | |
| MatrixCWise | CW () |
| Div (TScalar other) | |
| modifies this matrix by the scalar matrix quotient A/s More... | |
| TScalar | Dot (Matrix other) |
| returns the scalar product of two vectors (a'b) More... | |
| TScalar | Dot (MatrixBlock other) |
| returns the scalar product of two vectors (a'b) More... | |
| TScalar | Dott (Matrix other) |
| returns the weighted scalar product of this matrix and the given vector multiplied once from left and once from right (b'Ab) More... | |
| TScalar | Dott (MatrixBlock other) |
| returns the weighted scalar product of this matrix and the given vector multiplied once from left and once from right (b'Ab) More... | |
| Matrix | GetCols (TUnsignedIndex col1, TUnsignedIndex ncol=1) |
| returns an object providing copy of data | |
| Matrix | GetCols (Matrix indices) |
| Matrix | GetColsThread (TUnsignedIndex col, TUnsignedIndex ncols) |
| Matrix | GetRows (TUnsignedIndex row1, TUnsignedIndex nrow=1) |
| Matrix | GetRows (Matrix indices) |
| Matrix | GetRowsThread (TUnsignedIndex row, TUnsignedIndex nrows) |
| Matrix | InnerProduct (Matrix other) |
| returns the inner product of two matrices/vectors (a'*b) More... | |
| Matrix | InnerProduct (MatrixBlock other) |
| returns the inner product of two matrices/vectors (a'*b) More... | |
| bool | IsApprox (Matrix other, TScalar s) const |
| returns true if other and this are approx. identical More... | |
| bool | IsApproxToConstant (TScalar value, TScalar s) |
| returns true if array is constant and approx. equal s More... | |
| bool | IsDiagonal (TScalar s) |
| returns true if array is a diagonal matrix by precision s More... | |
| bool | IsIdentity (TScalar s) |
| returns true if array is the identity matrix by precision s More... | |
| bool | IsLowerTriangular (TScalar s) |
| returns true if array is a lower triangular matrix by precision s More... | |
| bool | IsScalar () |
| bool | IsUnitary (TScalar s) |
| returns true if array is a unitary matrix by precision s (is an orthonormal basis) More... | |
| bool | IsUpperTriangular (TScalar s) |
| returns true if array is an upper triangular matrix by precision s More... | |
| bool | IsVector () |
| bool | IsZero (TScalar s) |
| Matrix () | |
| destructor More... | |
| Matrix (Matrix ar) | |
| copy constructor More... | |
| Matrix (TUnsignedIndex nrow, TUnsignedIndex ncol=1) | |
| constructs a matrix and allocates nrow*ncol elements More... | |
| Matrix (MatrixBlock x) | |
| constructs a matrix from a matrix block More... | |
| Matrix (sparse::SparseMatrix x) | |
| copies from a sparse matrix More... | |
| Matrix (sparse::SymSparseMatrix x) | |
| copies from a symmetric sparse matrix More... | |
| TScalar | MaxCoeff (TEigenIndex *OUTPUT, TEigenIndex *OUTPUT) const |
| TScalar | MinCoeff (TEigenIndex *OUTPUT, TEigenIndex *OUTPUT) const |
| find the smallest element in the array returns the minimum element in the array More... | |
| Mul (TScalar other) | |
| modifies this matrix by the scalar matrix product A*s More... | |
| Matrix | operator* (Matrix other) const |
| returns the matrix product A*B More... | |
| Matrix | operator* (MatrixBlock other) const |
| returns the matrix product A*B More... | |
| Matrix | operator* (TScalar other) const |
| returns the scalar matrix product A*s More... | |
| Matrix | operator+ (Matrix other) const |
| returns the matrix sum A+B More... | |
| Matrix | operator+ (MatrixBlock other) const |
| returns the matrix sum A+B More... | |
| Matrix | operator- (Matrix other) const |
| returns the matrix difference A-B More... | |
| Matrix | operator- (MatrixBlock other) const |
| returns the matrix difference A-B More... | |
| Matrix | operator/ (TScalar other) const |
| returns the scalar matrix quotient A/s More... | |
| Matrix | operator< (TScalar x) const |
| returns a matrix of 1 and 0 indicating which element is less than x More... | |
| Matrix | operator= (Matrix ar) |
| copy assignment operator More... | |
| Matrix | OuterProduct (Matrix other) |
| returns the outer product of two matrices/vectors (a*b') More... | |
| Matrix | OuterProduct (MatrixBlock other) |
| returns the outer product of two matrices/vectors (a*b') More... | |
| Print (string format="%g ", TUnsignedIndex rows=20, TUnsignedIndex cols=20) const | |
| prints the matrix up to the given rows and columns More... | |
| Matrix | RemoveCol (TUnsignedIndex col) |
| returns an object of corresponding smaller size | |
| Matrix | RemoveRow (TUnsignedIndex row) |
| MatrixBlock | Row (TUnsignedIndex row) |
| returns a reference to the 'row'th row More... | |
| TUnsignedIndex | Rows () const |
| MatrixBlock | Rows (TUnsignedIndex row1, TUnsignedIndex nrow) |
| returns a block containing the nrow columns starting at column index row1 More... | |
| void | SetCols (Matrix m, TUnsignedIndex col) |
| returns an object providing copy of data More... | |
| SetColsThread (Matrix m, TUnsignedIndex col) | |
| SetConstant (TScalar value) | |
| initializes the matrix with constant values More... | |
| void | SetIdentity () |
| initializes the matrix as identity matrix | |
| void | SetLinearCols (TScalar a, TScalar b) |
| initializes the matrix with linear columns More... | |
| SetLinearRows (TScalar a, TScalar b) | |
| initializes the matrix with linear rows More... | |
| void | SetOnes () |
| initializes the matrix with constant values "1" | |
| void | SetRandom () |
| initializes the matrix with random values | |
| void | SetRows (Matrix m, TUnsignedIndex row) |
| SetRowsThread (Matrix m, TUnsignedIndex row) | |
| void | SetZero () |
| initializes the matrix with zeros | |
| Sub (Matrix other) | |
| modifies this matrix by the matrix difference A-B More... | |
| Sub (MatrixBlock other) | |
| modifies this matrix by the matrix difference A-B More... | |
| Swap (Matrix ar) | |
| The swap operator for matrices (data only) More... | |
| Matrix | Transpose () const |
| void | TransposeInPlace () |
| transposes this matrix | |
Public Attributes | |
| apply | int { TEigenIndex } |
| find the largest element in the array returns the maximum element in the array More... | |
| apply int * | OUTPUT { TEigenIndex *OUTPUT } |
Detailed Description
Standard matrix class.
A class that represents storage for dense linalg objects.
The storage scheme is column_major (FORTRAN). It is derived from Eigen::Matrix. Many operations have been added/overwritten for compatibility with scripting requirements. Most operations of Eigen2 are still available.
Basic Eigen linalg operators have been overloaded. To access a linalg operator from C++, for example the matrix product, type
This will give you the fastest operation possible within the Eigen library. The overloaded operators have some if-clauses and do not make use of expression templates what may harm performance.
Matrix offers a handling for complex numbers which differs from Eigen: The odd columns are the real parts and the odd columns contain the imaginary parts.
Some of the underlying Eigen methods are available for SWIG. They are not integrated into the error chacking system, though! neverthelesse, ften they are the most efficient methods. To distuingish between Eigen and own methods, the Eigen methods identifiers start with a noncapital first letter, our own methods start with a capital letter.
Operators for SWIG are provided using the methods add, etc., The SWIG-operators must be safeguarded, whereas the C++-operators should be the original Eigen2 operators. Therefore they must be defined separately on C++ level.
Matrix is useing a reference counter system. It is advised not to use 'delete Matrix();' to remove it from memory, but to use removeReference.
Constructor & Destructor Documentation
◆ Matrix() [1/6]
| Matrix | ( | ) |
destructor
default constructor
◆ Matrix() [2/6]
◆ Matrix() [3/6]
| Matrix | ( | TUnsignedIndex | nrow, |
| TUnsignedIndex | ncol = 1 |
||
| ) |
constructs a matrix and allocates nrow*ncol elements
- Parameters
-
nrow the number of rows ncol the number of columns
◆ Matrix() [4/6]
| Matrix | ( | MatrixBlock | x | ) |
constructs a matrix from a matrix block
- Parameters
-
x the object to be copied from
◆ Matrix() [5/6]
| Matrix | ( | sparse::SparseMatrix | x | ) |
copies from a sparse matrix
- Parameters
-
x the object to be copied from
◆ Matrix() [6/6]
| Matrix | ( | sparse::SymSparseMatrix | x | ) |
copies from a symmetric sparse matrix
- Parameters
-
x the object to be copied from
Member Function Documentation
◆ __neg__()
| Matrix __neg__ | ( | ) | const |
- Returns
- unary minus (B=-A) Used by SWIG.
◆ __str__()
| char* __str__ | ( | ) |
transforms this objects into a string, required by SWIG
- Returns
- a string
◆ Add() [1/2]
| Add | ( | Matrix | other | ) |
modifies this matrix by the matrix sum A+B
- Parameters
-
other the matrix B
◆ Add() [2/2]
| Add | ( | MatrixBlock | other | ) |
modifies this matrix by the matrix sum A+B
- Parameters
-
other the matrix B
◆ AppendCols()
returns an object with modified data
- Parameters
-
m the columns to be appended
- Returns
- Matrix with columns appended
◆ AppendRows()
returns an object with modified data
- Parameters
-
m the rows to be appended
- Returns
- Matrix with rows appended
◆ Assign() [1/2]
| Assign | ( | Matrix | ar | ) |
The assignment operator for matrices (data only)
- Parameters
-
ar the source object
◆ Assign() [2/2]
| Assign | ( | MatrixBlock | ar | ) |
The assignment operator for blocks (data only)
- Parameters
-
ar the source object
◆ Block()
| MatrixBlock Block | ( | TUnsignedIndex | row, |
| TUnsignedIndex | col, | ||
| TUnsignedIndex | numrows, | ||
| TUnsignedIndex | numcols | ||
| ) |
returns a reference to a block starting at 'row','column' with size 'numrows'*'numcols'
- Parameters
-
row the top left row index col the top left column index numrows the number of rows of the matrix part numcols the number of columns of the matrix part
- Returns
- a matrix block serving as a reference to the specified matrix part
◆ Col()
| MatrixBlock Col | ( | TUnsignedIndex | col | ) |
returns a reference to the 'col'th column
- Parameters
-
col the requested column index
- Returns
- a matrix block serving as a reference to the column
◆ Cols() [1/2]
| TUnsignedIndex Cols | ( | ) | const |
- Returns
- the number of cols
◆ Cols() [2/2]
| MatrixBlock Cols | ( | TUnsignedIndex | col1, |
| TUnsignedIndex | ncol | ||
| ) |
returns a block containing the ncol columns starting at column index col1
- Parameters
-
col1 the left column index ncol the number of columns of the matrix part
- Returns
- a matrix block serving as a reference to the specified matrix part
◆ ConservativeResize()
| void ConservativeResize | ( | TUnsignedIndex | rows, |
| TUnsignedIndex | cols = 1 |
||
| ) |
resizes the matrix to its new dimensions without destroying the contents.
- Parameters
-
rows the number of rows after resize cols the number of columns after resize Internally it creates a copy of the object (nothing if memory is crucial).
◆ CW()
| MatrixCWise CW | ( | ) |
- Returns
- an object providing cwise access
◆ Div()
| Div | ( | TScalar | other | ) |
modifies this matrix by the scalar matrix quotient A/s
- Parameters
-
other the scalar s
◆ Dot() [1/2]
returns the scalar product of two vectors (a'b)
- Parameters
-
other the vector b
- Returns
- the result of the operation
◆ Dot() [2/2]
| TScalar Dot | ( | MatrixBlock | other | ) |
returns the scalar product of two vectors (a'b)
- Parameters
-
other the vector b
- Returns
- the result of the operation
◆ Dott() [1/2]
returns the weighted scalar product of this matrix and the given vector multiplied once from left and once from right (b'Ab)
- Parameters
-
other the vector b
- Returns
- the result of the operation
◆ Dott() [2/2]
| TScalar Dott | ( | MatrixBlock | other | ) |
returns the weighted scalar product of this matrix and the given vector multiplied once from left and once from right (b'Ab)
- Parameters
-
other the vector b
- Returns
- the result of the operation
◆ InnerProduct() [1/2]
returns the inner product of two matrices/vectors (a'*b)
- Parameters
-
other the vector/matrix b
- Returns
- the result of the operation
◆ InnerProduct() [2/2]
| Matrix InnerProduct | ( | MatrixBlock | other | ) |
returns the inner product of two matrices/vectors (a'*b)
- Parameters
-
other the vector/matrix b
- Returns
- the result of the operation
◆ IsApprox()
returns true if other and this are approx. identical
- Parameters
-
other the object to be compared s a tolerance for the equality test
- Returns
- the result of the operation
◆ IsApproxToConstant()
returns true if array is constant and approx. equal s
- Parameters
-
value the constant value to be compared with s a tolerance for the equality test
- Returns
- the result of the operation
◆ IsDiagonal()
| bool IsDiagonal | ( | TScalar | s | ) |
returns true if array is a diagonal matrix by precision s
- Parameters
-
s a tolerance for the test
- Returns
- the result of the operation
◆ IsIdentity()
| bool IsIdentity | ( | TScalar | s | ) |
returns true if array is the identity matrix by precision s
- Parameters
-
s a tolerance for the equality test
- Returns
- the result of the operation
◆ IsLowerTriangular()
| bool IsLowerTriangular | ( | TScalar | s | ) |
returns true if array is a lower triangular matrix by precision s
- Parameters
-
s a tolerance for the equality test
- Returns
- the result of the operation
◆ IsScalar()
| bool IsScalar | ( | ) |
- Returns
- true if array is a scalar
◆ IsUnitary()
| bool IsUnitary | ( | TScalar | s | ) |
returns true if array is a unitary matrix by precision s (is an orthonormal basis)
- Parameters
-
s a tolerance for the equality test
- Returns
- the result of the operation
◆ IsUpperTriangular()
| bool IsUpperTriangular | ( | TScalar | s | ) |
returns true if array is an upper triangular matrix by precision s
- Parameters
-
s a tolerance for the equality test
- Returns
- the result of the operation
◆ IsVector()
| bool IsVector | ( | ) |
- Returns
- true if array is a vector
◆ IsZero()
| bool IsZero | ( | TScalar | s | ) |
- Returns
- true if array is a zero matrix by precision s
- Parameters
-
s a tolerance for the equality test
◆ MinCoeff()
| TScalar MinCoeff | ( | TEigenIndex * | OUTPUT, |
| TEigenIndex * | OUTPUT | ||
| ) | const |
find the smallest element in the array returns the minimum element in the array
- Parameters
-
row will be modified and will contain the row position of the found value on return col will be modified and will contain the column position of the found value on return
- Returns
- smallest elment
◆ Mul()
| Mul | ( | TScalar | other | ) |
modifies this matrix by the scalar matrix product A*s
- Parameters
-
other the scalar s
◆ operator*() [1/3]
returns the matrix product A*B
- Parameters
-
other the matrix B
- Returns
- the result of the operation
◆ operator*() [2/3]
| Matrix operator* | ( | MatrixBlock | other | ) | const |
returns the matrix product A*B
- Parameters
-
other the matrix B
- Returns
- the result of the operation
◆ operator*() [3/3]
returns the scalar matrix product A*s
- Parameters
-
other the scalar s
- Returns
- the result of the operation
◆ operator+() [1/2]
returns the matrix sum A+B
- Parameters
-
other the matrix B
- Returns
- the result of the operation
◆ operator+() [2/2]
| Matrix operator+ | ( | MatrixBlock | other | ) | const |
returns the matrix sum A+B
- Parameters
-
other the matrix B
- Returns
- the result of the operation
◆ operator-() [1/2]
returns the matrix difference A-B
- Parameters
-
other the matrix B
- Returns
- the result of the operation
◆ operator-() [2/2]
| Matrix operator- | ( | MatrixBlock | other | ) | const |
returns the matrix difference A-B
- Parameters
-
other the matrix B
- Returns
- the result of the operation
◆ operator/()
returns the scalar matrix quotient A/s
- Parameters
-
other the scalar s
- Returns
- the result of the operation
◆ operator<()
returns a matrix of 1 and 0 indicating which element is less than x
- Parameters
-
x the scalar x
- Returns
- the result of the operation
◆ operator=()
◆ OuterProduct() [1/2]
returns the outer product of two matrices/vectors (a*b')
- Parameters
-
other the vector/matrix b
- Returns
- the result of the operation
◆ OuterProduct() [2/2]
| Matrix OuterProduct | ( | MatrixBlock | other | ) |
returns the outer product of two matrices/vectors (a*b')
- Parameters
-
other the vector/matrix b
- Returns
- the result of the operation
◆ Print()
| ( | string | format = "%g ", |
|
| TUnsignedIndex | rows = 20, |
||
| TUnsignedIndex | cols = 20 |
||
| ) | const |
prints the matrix up to the given rows and columns
- Parameters
-
format the format according to printf() rows the maximum number of rows to be printed cols the maximum number of columns to be printed
◆ Row()
| MatrixBlock Row | ( | TUnsignedIndex | row | ) |
returns a reference to the 'row'th row
- Parameters
-
row the requested row index
- Returns
- a matrix block serving as a reference to the row
◆ Rows() [1/2]
| TUnsignedIndex Rows | ( | ) | const |
- Returns
- the number of rows
◆ Rows() [2/2]
| MatrixBlock Rows | ( | TUnsignedIndex | row1, |
| TUnsignedIndex | nrow | ||
| ) |
returns a block containing the nrow columns starting at column index row1
- Parameters
-
row1 the right row index nrow the number of rows of the matrix part
- Returns
- a matrix block serving as a reference to the specified matrix part
◆ SetCols()
| void SetCols | ( | Matrix | m, |
| TUnsignedIndex | col | ||
| ) |
returns an object providing copy of data
changes object data in place
◆ SetConstant()
| SetConstant | ( | TScalar | value | ) |
initializes the matrix with constant values
- Parameters
-
value the scalar value of the matrix
◆ SetLinearCols()
initializes the matrix with linear columns
- Parameters
-
a the value of the first row b the value of the last row
◆ SetLinearRows()
initializes the matrix with linear rows
- Parameters
-
a the value of the first column b the value of the last column
◆ Sub() [1/2]
| Sub | ( | Matrix | other | ) |
modifies this matrix by the matrix difference A-B
- Parameters
-
other the matrix B
◆ Sub() [2/2]
| Sub | ( | MatrixBlock | other | ) |
modifies this matrix by the matrix difference A-B
- Parameters
-
other the matrix B
◆ Swap()
| Swap | ( | Matrix | ar | ) |
The swap operator for matrices (data only)
- Parameters
-
ar the other object. On output *this will contain the input value of ar while ar contains the input value of *this.
◆ Transpose()
| Matrix Transpose | ( | ) | const |
- Returns
- the transpose
Member Data Documentation
◆ int
| apply int { TEigenIndex } |
find the largest element in the array returns the maximum element in the array
- Parameters
-
row will be modified and will contain the row position of the found value on return col will be modified and will contain the column position of the found value on return
- Returns
- largest elment