template<typename Type>
class walberla::math::MatrixMxN< Type >
Efficient implementation of a \( M \times N \) matrix.
The MatrixMxN class is the representation of a dynamic \( M \times N \) matrix with a total of \( M \cdot N \) dynamically allocated elements. These elements can be directly accessed with the 1D subscript operator or with the 2D function operator. The matrix is stored in a row-wise fashion:
\f[\left(\begin{array}{*{5}{c}}
0 & 1 & 2 & \cdots & N-1 \\
N & N+1 & N+2 & \cdots & 2 \cdot N-1 \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
M \cdot N-N & M \cdot N-N+1 & M \cdot N-N+2 & \cdots & M \cdot N-1 \\
\end{array}\right)\f]
MatrixMxN can be used with any non-cv-qualified element type. The arithmetic operators for matrix/matrix, matrix/vector and matrix/element operations with the same element type work for any element type as long as the element type supports the arithmetic operation. Arithmetic operations between matrices, vectors and elements of different element types are only supported for all data types supported by the MathTrait class template (for details see the MathTrait class description).
MatrixMxN< double > a, b,
c;
MatrixMxN< float > d;
MatrixMxN< std::complex<double> >
e, f, g;
MatrixMxN< std::complex<float> > h;
...
|
template<typename Other , size_t M, size_t N> |
MatrixMxN< Type > & | operator= (const Other(&rhs)[M][N]) |
| Array assignment to all matrix elements. More...
|
|
template<typename Other > |
MatrixMxN< Type > & | scale (Other scalar) |
| Scaling of the matrix by the scalar value scalar ( \( A=B*s \)). More...
|
|
|
constexpr | MatrixMxN () |
| The default constructor for MatrixMxN. More...
|
|
constexpr | MatrixMxN (size_t m, size_t n) |
| Constructor for a matrix of size \( m \times n \). More...
|
|
constexpr | MatrixMxN (size_t m, size_t n, Type init) |
| Constructor for a homogenous initialization of all \( m \times n \) matrix elements. More...
|
|
constexpr | MatrixMxN (const MatrixMxN &m) |
| The copy constructor for MatrixMxN. More...
|
|
template<typename Other , size_t M, size_t N> |
constexpr | MatrixMxN (const Other(&rhs)[M][N]) |
| Array initialization of all matrix elements. More...
|
|
|
| ~MatrixMxN () |
| The destructor for MatrixMxN. More...
|
|
|
template<typename Other , size_t M, size_t N> |
MatrixMxN & | operator= (const Other(&rhs)[M][N]) |
|
MatrixMxN & | operator= (Type set) |
| Homogenous assignment to all matrix elements. More...
|
|
MatrixMxN & | operator= (const MatrixMxN &set) |
| Copy assignment operator for MatrixMxN. More...
|
|
Type & | operator[] (size_t index) |
| 1D-access to the matrix elements. More...
|
|
const Type & | operator[] (size_t index) const |
| 1D-access to the matrix elements. More...
|
|
Type & | operator() (size_t i, size_t j) |
| 2D-access to the matrix elements. More...
|
|
const Type & | operator() (size_t i, size_t j) const |
| 2D-access to the matrix elements. More...
|
|
|
size_t | rows () const |
| Returns the current number of rows of the matrix. More...
|
|
size_t | columns () const |
| Returns the current number of columns of the matrix. More...
|
|
size_t | capacity () const |
| Returns the maximum capacity of the matrix. More...
|
|
size_t | nonZeros () const |
| Returns the total number of non-zero elements in the matrix. More...
|
|
size_t | nonZeros (size_t i) const |
| Returns the number of non-zero elements in the specified row. More...
|
|
void | reset () |
| Reset to the default initial values. More...
|
|
void | clear () |
| Clearing the \( M \times N \) matrix. More...
|
|
void | resize (size_t m, size_t n, bool preserve=true) |
| Changing the size of the matrix. More...
|
|
void | extend (size_t m, size_t n, bool preserve=true) |
| Extending the size of the matrix. More...
|
|
void | reserve (size_t elements) |
| Setting the minimum capacity of the matrix. More...
|
|
MatrixMxN & | transpose () |
| Transposing the matrix. More...
|
|
bool | isDiagonal () const |
| Checks if the matrix is diagonal. More...
|
|
bool | isSymmetric () const |
| Checks if the matrix is symmetric. More...
|
|
template<typename Other > |
MatrixMxN & | scale (Other scalar) |
|
void | swap (MatrixMxN &m) |
| Swapping the contents of two matrices. More...
|
|
|
template<typename Other > |
bool | isAliased (const Other *alias) const |
| Returns whether the matrix is aliased with the given address alias. More...
|
|
template<typename Type >
template<typename Other , size_t M, size_t N>
Array initialization of all matrix elements.
- Parameters
-
rhs | \( M \times N \) dimensional array for the initialization. |
- Returns
- Reference to the assigned matrix.
This constructor offers the option to directly initialize the elements of the matrix:
const real init[3][3] = { { 1, 2, 3 },
{ 4, 5 },
{ 7, 8, 9 } };
MatrixMxN<real> A = init;
The matrix is sized according to the size of the array and initialized with the given values. Missing values are initialized with zero (as e.g. the value 6 in the example).
Checks if the matrix is diagonal.
- Returns
- true if the matrix is diagonal, false if not.
This function tests whether the matrix is diagonal, i.e. if the non-diagonal elements are default elements. In case of integral or floating point data types, a diagonal matrix has the form
\f[\left(\begin{array}{*{5}{c}}
aa & 0 & 0 & \cdots & 0 \\
0 & bb & 0 & \cdots & 0 \\
0 & 0 & cc & \cdots & 0 \\
\vdots & \vdots & \vdots & \ddots & 0 \\
0 & 0 & 0 & 0 & mn \\
\end{array}\right)\f]
template<typename Type >
template<typename Other , size_t M, size_t N>
Array assignment to all matrix elements.
- Parameters
-
rhs | \( M \times N \) dimensional array for the assignment. |
- Returns
- Reference to the assigned matrix.
This assignment operator offers the option to directly set all elements of the matrix:
const real init[3][3] = { { 1, 2, 3 },
{ 4, 5 },
{ 7, 8, 9 } };
MatrixMxN<real> A;
A = init;
The matrix is resized according to the size of the array and initialized with the given values. Missing values are initialized with zero (as e.g. the value 6 in the example).
Changing the size of the matrix.
- Parameters
-
m | The new number of rows of the matrix. |
n | The new number of columns of the matrix. |
preserve | true if the old values of the matrix should be preserved, false if not. |
- Returns
- void
This function resizes the matrix using the given size to \( m \times n \). During this operation, new dynamic memory may be allocated in case the capacity of the matrix is too small. Therefore this function potentially changes all matrix elements. In order to preserve the old matrix values, the preserve flag can be set to true. However, new matrix elements are not initialized!
The following example illustrates the resize operation of a \( 2 \times 4 \) matrix to a \( 4 \times 2 \) matrix. The new, uninitialized elements are marked with x:
\f[
\left(\begin{array}{*{4}{c}}
1 & 2 & 3 & 4 \\
5 & 6 & 7 & 8 \\
\end{array}\right)
\Longrightarrow
\left(\begin{array}{*{2}{c}}
1 & 2 \\
5 & 6 \\
x & x \\
x & x \\
\end{array}\right)
\f]