|
AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
|
The Matrix class is used to represent \( M \times N \) matrices. It provides common matrix operations and allows accessing matrix elements in a more natural way, using row and column indices, regardless of the underlying flat array storage layout. More...
#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/develop/src/axom/core/numerics/Matrix.hpp>

Public Member Functions | |
| Matrix () | |
| Default constructor. More... | |
| Matrix (int rows, int cols, T val=static_cast< T >(0)) | |
| Constructor, creates a Matrix with the given rows and columns. More... | |
| AXOM_HOST_DEVICE | Matrix (int rows, int cols, T *data, bool useExternal=false) |
| Array constructor, creates a Matrix with the given rows and columns and initializes its entries with the data from the supplied array. More... | |
| Matrix (const Matrix< T > &m) | |
| Copy constructor. More... | |
| AXOM_HOST_DEVICE | ~Matrix () |
| Destructor. More... | |
| bool | isSquare () const |
| Check to see if the matrix is square. More... | |
| bool | empty () const |
| Checks if the matrix is empty. More... | |
| bool | usesExternalBuffer () const |
| Checks to see if the matrix has an external buffer. More... | |
| int | getNumRows () const |
| Returns the number of rows in the matrix.. More... | |
| AXOM_HOST_DEVICE int | getNumColumns () const |
| Returns the number of columns in the matrix. More... | |
| int | getDiagonalSize () const |
| Returns the size of the diagonal. More... | |
| void | getDiagonal (T *diagonal) const |
| Returns the diagonal entries of this Matrix instance. More... | |
| void | fillDiagonal (const T &val) |
| Assigns val to all entries in the diagonal. More... | |
| void | fillRow (IndexType i, const T &val) |
| Assigns val to all elements in the given matrix row. More... | |
| void | fillColumn (IndexType j, const T &val) |
| Assigns val to all elements in the given matrix column. More... | |
| void | fill (const T &val) |
| Assigns val to all elements of the matrix. More... | |
| void | swapRows (IndexType i, IndexType j) |
| Swaps the rows of this matrix instance. More... | |
| void | swapColumns (IndexType i, IndexType j) |
| Swaps the columns of this matrix instance. More... | |
Random Access Operators | |
| AXOM_HOST_DEVICE const T & | operator() (IndexType i, IndexType j) const |
| Given an \( M \times N \) matrix, \( \mathcal{A} \), return a const reference to matrix element \( \alpha_{ij} \). More... | |
| AXOM_HOST_DEVICE T & | operator() (IndexType i, IndexType j) |
| Given an \( M \times N \) matrix, \( \mathcal{A} \), return a reference to matrix element \( \alpha_{ij} \). More... | |
| AXOM_HOST_DEVICE const T * | getColumn (IndexType j) const |
| Returns a const pointer to the \( jth \) column of an \( M \times N \) matrix, \( \mathcal{A} \). More... | |
| AXOM_HOST_DEVICE T * | getColumn (IndexType j) |
| Returns pointer to the \( jth \) column of an \( M \times N \) matrix, \( \mathcal{A} \). More... | |
| const T * | getDiagonal (IndexType &p, IndexType &N) const |
| Returns a const pointer for strided access along the main diagonal. More... | |
| T * | getDiagonal (IndexType &p, IndexType &N) |
| Returns a pointer for strided access along the main diagonal. More... | |
| const T * | getRow (IndexType i, IndexType &p, IndexType &N) const |
| Returns a const pointer to the \( ith \) row of an \( M \times N \) matrix, \( \mathcal{A} \). More... | |
| T * | getRow (IndexType i, IndexType &p, IndexType &N) |
| Returns a pointer to the \( ith \) row of an \( M \times N \) matrix, \( \mathcal{A} \). More... | |
| const T * | data () const |
| Returns a const pointer to the raw data. More... | |
| T * | data () |
| Returns pointer to the raw data. More... | |
Overloaded Operators | |
| Matrix< T > & | operator= (const Matrix< T > &rhs) |
| Overloaded assignment operator. More... | |
| bool | isIdentity () const |
| Determines whether matrix is identity matrix. More... | |
Static Public Member Functions | |
Static Methods | |
| static Matrix< T > | identity (int n) |
| Returns an identity matrix \( \mathcal{I}_n \). More... | |
| static Matrix< T > | zeros (int nrows, int ncols) |
| Returns a zero matrix, \( \mathcal{A} \). More... | |
| static Matrix< T > | ones (int nrows, int ncols) |
| Returns a unity matrix, \( \mathcal{A} \). More... | |
The Matrix class is used to represent \( M \times N \) matrices. It provides common matrix operations and allows accessing matrix elements in a more natural way, using row and column indices, regardless of the underlying flat array storage layout.
Basic usage example:
| T | the underlying matrix data type, e.g., float, double, etc. |
|
inline |
Default constructor.
| axom::numerics::Matrix< T >::Matrix | ( | int | rows, |
| int | cols, | ||
| T | val = static_cast<T>(0) |
||
| ) |
Constructor, creates a Matrix with the given rows and columns.
| [in] | rows | the number of rows in the matrix. |
| [in] | cols | the number of columns in the matrix. |
| [in] | val | optional argument to initialize the entries of the matrix. If not supplied, the default is zero. |
References axom::numerics::Matrix< T >::fill().
| AXOM_HOST_DEVICE axom::numerics::Matrix< T >::Matrix | ( | int | rows, |
| int | cols, | ||
| T * | data, | ||
| bool | useExternal = false |
||
| ) |
Array constructor, creates a Matrix with the given rows and columns and initializes its entries with the data from the supplied array.
| [in] | rows | the number of rows in the matrix |
| [in] | cols | the number of columns in the matrix |
| [in] | data | pointer to user-supplied buffer to initialize the matrix. |
| [in] | useExternal | optional flag that indicates that this matrix instance should not make a deep copy of the data. Default is false. |
References axom::numerics::Matrix< T >::data().
| axom::numerics::Matrix< T >::Matrix | ( | const Matrix< T > & | m | ) |
Copy constructor.
| [in] | m | the matrix instance that is being passed. |
References axom::copy().
| AXOM_HOST_DEVICE axom::numerics::Matrix< T >::~Matrix |
Destructor.
|
inline |
Check to see if the matrix is square.
|
inline |
Checks if the matrix is empty.
|
inline |
Checks to see if the matrix has an external buffer.
|
inline |
Returns the number of rows in the matrix..
|
inline |
Returns the number of columns in the matrix.
|
inline |
Returns the size of the diagonal.
| void axom::numerics::Matrix< T >::getDiagonal | ( | T * | diagonal | ) | const |
Returns the diagonal entries of this Matrix instance.
| [in] | diagonal | user-supplied buffer to store the diagonal entries. |
| void axom::numerics::Matrix< T >::fillDiagonal | ( | const T & | val | ) |
Assigns val to all entries in the diagonal.
| [in] | val | value to assign to all diagonal entries. |
| void axom::numerics::Matrix< T >::fillRow | ( | IndexType | i, |
| const T & | val | ||
| ) |
Assigns val to all elements in the given matrix row.
| [in] | i | the row index. |
| [in] | val | value to assign to all elements in the given row. |
| void axom::numerics::Matrix< T >::fillColumn | ( | IndexType | j, |
| const T & | val | ||
| ) |
Assigns val to all elements in the given matrix column.
| [in] | j | the column index. |
| [in] | val | value to assign to all elements in the given column. |
| void axom::numerics::Matrix< T >::fill | ( | const T & | val | ) |
Assigns val to all elements of the matrix.
| [in] | val | value to assign to all elements of the matrix. |
| void axom::numerics::Matrix< T >::swapRows | ( | IndexType | i, |
| IndexType | j | ||
| ) |
Swaps the rows of this matrix instance.
| [in] | i | index of the first row to swap |
| [in] | j | index of the second row to swap |
References axom::utilities::swap().
| void axom::numerics::Matrix< T >::swapColumns | ( | IndexType | i, |
| IndexType | j | ||
| ) |
Swaps the columns of this matrix instance.
| [in] | i | index of the first column to swap |
| [in] | j | index of the second column to swap |
| AXOM_HOST_DEVICE const T & axom::numerics::Matrix< T >::operator() | ( | IndexType | i, |
| IndexType | j | ||
| ) | const |
Given an \( M \times N \) matrix, \( \mathcal{A} \), return a const reference to matrix element \( \alpha_{ij} \).
| [in] | i | the row index of the matrix element, |
| [in] | j | the column index of the matrix element. |
| AXOM_HOST_DEVICE T & axom::numerics::Matrix< T >::operator() | ( | IndexType | i, |
| IndexType | j | ||
| ) |
Given an \( M \times N \) matrix, \( \mathcal{A} \), return a reference to matrix element \( \alpha_{ij} \).
| [in] | i | the row index of the matrix element. |
| [in] | j | the column index of the matrix element. |
| AXOM_HOST_DEVICE const T * axom::numerics::Matrix< T >::getColumn | ( | IndexType | j | ) | const |
Returns a const pointer to the \( jth \) column of an \( M \times N \) matrix, \( \mathcal{A} \).
| [in] | j | the jth column of the matrix. |
| AXOM_HOST_DEVICE T * axom::numerics::Matrix< T >::getColumn | ( | IndexType | j | ) |
Returns pointer to the \( jth \) column of an \( M \times N \) matrix, \( \mathcal{A} \).
| [in] | j | the jth column of the matrix. |
| const T * axom::numerics::Matrix< T >::getDiagonal | ( | IndexType & | p, |
| IndexType & | N | ||
| ) | const |
Returns a const pointer for strided access along the main diagonal.
| [out] | p | stride used to access elements along the main diagonal. |
| [out] | N | upper-bound used to loop over the main diagonal entries. |
| T * axom::numerics::Matrix< T >::getDiagonal | ( | IndexType & | p, |
| IndexType & | N | ||
| ) |
Returns a pointer for strided access along the main diagonal.
| [out] | p | stride used to access elements along the main diagonal. |
| [out] | N | upper-bound used to loop over the main diagonal entris. |
| const T * axom::numerics::Matrix< T >::getRow | ( | IndexType | i, |
| IndexType & | p, | ||
| IndexType & | N | ||
| ) | const |
Returns a const pointer to the \( ith \) row of an \( M \times N \) matrix, \( \mathcal{A} \).
| [in] | i | index to the \( ith \) row of the matrix |
| [out] | p | stride used to access row elements |
| [out] | N | upper-bound to loop over |
| T * axom::numerics::Matrix< T >::getRow | ( | IndexType | i, |
| IndexType & | p, | ||
| IndexType & | N | ||
| ) |
Returns a pointer to the \( ith \) row of an \( M \times N \) matrix, \( \mathcal{A} \).
| [in] | i | index to the \( ith \) row of the matrix |
| [out] | p | stride used to access row elements |
| [out] | N | upper-bound to loop over |
| const T * axom::numerics::Matrix< T >::data |
Returns a const pointer to the raw data.
| T * axom::numerics::Matrix< T >::data |
Returns pointer to the raw data.
| Matrix< T > & axom::numerics::Matrix< T >::operator= | ( | const Matrix< T > & | rhs | ) |
Overloaded assignment operator.
| [in] | rhs | matrix instance on the right-hand side. |
References axom::copy().
| bool axom::numerics::Matrix< T >::isIdentity |
Determines whether matrix is identity matrix.
|
static |
Returns an identity matrix \( \mathcal{I}_n \).
| [in] | n | the size of the identity matrix. |
|
static |
Returns a zero matrix, \( \mathcal{A} \).
| [in] | nrows | the number of rows in the matrix. |
| [in] | ncols | the number of columns in the matrix. |
References axom::numerics::Matrix< T >::fill().
|
static |
Returns a unity matrix, \( \mathcal{A} \).
| [in] | nrows | the number of rows in the matrix. |
| [in] | ncols | the number of columns in the matrix. |
References axom::numerics::Matrix< T >::fill().