Matrix class with compile-time size. More...
#include <AMReX_SmallMatrix.H>
Public Types | |
using | value_type = T |
using | reference_type = T & |
Public Member Functions | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr | SmallMatrix ()=default |
Default constructor. | |
template<typename... Ts, int MM = NRows, int NN = NCols, std::enable_if_t< MM==1||NN==1, int > = 0> | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr | SmallMatrix (Ts... vs) |
Constructs column- or row-vector. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE | SmallMatrix (std::initializer_list< std::initializer_list< T > > const &init) |
Constructs SmallMatrix with nested std::initializer_list. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & | operator() (int i, int j) const noexcept |
Returns a const reference to the element at row i and column j. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & | operator() (int i, int j) noexcept |
Returns a reference to the element at row i and column j. | |
template<int MM = NRows, int NN = NCols, std::enable_if_t<(MM==1||NN==1), int > = 0> | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & | operator() (int i) const noexcept |
Returns a const reference to element i of a vector. | |
template<int MM = NRows, int NN = NCols, std::enable_if_t<(MM==1||NN==1), int > = 0> | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & | operator() (int i) noexcept |
Returns a reference to element i of a vector. | |
template<int MM = NRows, int NN = NCols, std::enable_if_t<(MM==1||NN==1), int > = 0> | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T & | operator[] (int i) const noexcept |
Returns a const reference to element i of a vector. | |
template<int MM = NRows, int NN = NCols, std::enable_if_t<(MM==1||NN==1), int > = 0> | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T & | operator[] (int i) noexcept |
Returns a reference to element i of a vector. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * | begin () const noexcept |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE const T * | end () const noexcept |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * | begin () noexcept |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * | end () noexcept |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & | setVal (T val) |
Set all elements in the matrix to the given value. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SmallMatrix< T, NCols, NRows, ORDER, StartIndex > | transpose () const |
Returns transposed matrix. | |
template<int MM = NRows, int NN = NCols, std::enable_if_t< MM==NN, int > = 0> | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & | transposeInPlace () |
Transposes a square matrix in-place. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T | product () const |
Returns the product of all elements in the matrix. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T | sum () const |
Returns the sum of all elements in the matrix. | |
template<int MM = NRows, int NN = NCols, std::enable_if_t< MM==NN, int > = 0> | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T | trace () const |
Returns the trace of a square matrix. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & | operator+= (SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &rhs) |
Operator += performing matrix addition as in (*this) += rhs. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & | operator-= (SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &rhs) |
Operator -= performing matrix subtraction as in (*this) -= rhs. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SmallMatrix< T, NRows, NCols, ORDER, StartIndex > | operator- () const |
Unary minus operator. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & | operator*= (T a) |
Operator *= that scales this matrix in place by a scalar. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T | dot (SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &rhs) const |
Returns the dot product of two vectors. | |
template<int N, std::enable_if_t<(N< NRows *NCols), int > = 0> | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T const & | get () const |
template<int N, std::enable_if_t<(N< NRows *NCols), int > = 0> | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE constexpr T & | get () |
Static Public Member Functions | |
template<int MM = NRows, int NN = NCols, std::enable_if_t< MM==NN, int > = 0> | |
static constexpr AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SmallMatrix< T, NRows, NCols, ORDER, StartIndex > | Identity () noexcept |
Returns an identity matrix. | |
static constexpr AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SmallMatrix< T, NRows, NCols, ORDER, StartIndex > | Zero () noexcept |
Returns a matrix initialized with zeros. | |
Static Public Attributes | |
static constexpr int | row_size = NRows |
static constexpr int | column_size = NCols |
static constexpr Order | ordering = ORDER |
static constexpr int | starting_index = StartIndex |
Private Attributes | |
T | m_mat [NRows *NCols] |
Friends | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE friend SmallMatrix< T, NRows, NCols, ORDER, StartIndex > | operator+ (SmallMatrix< T, NRows, NCols, ORDER, StartIndex > lhs, SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &rhs) |
Binary operator + returning the result of maxtrix addition, lhs+rhs. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE friend SmallMatrix< T, NRows, NCols, ORDER, StartIndex > | operator- (SmallMatrix< T, NRows, NCols, ORDER, StartIndex > lhs, SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &rhs) |
Binary operator - returning the result of maxtrix subtraction, lhs-rhs. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE friend SmallMatrix< T, NRows, NCols, ORDER, StartIndex > | operator* (SmallMatrix< T, NRows, NCols, ORDER, StartIndex > m, T a) |
Returns the product of a matrix and a scalar. | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE friend SmallMatrix< T, NRows, NCols, ORDER, StartIndex > | operator* (T a, SmallMatrix< T, NRows, NCols, ORDER, StartIndex > m) |
Returns the product of a scalar and a matrix. | |
template<class U , int N1, int N2, int N3, Order Ord, int SI> | |
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE friend SmallMatrix< U, N1, N3, Ord, SI > | operator* (SmallMatrix< U, N1, N2, Ord, SI > const &lhs, SmallMatrix< U, N2, N3, Ord, SI > const &rhs) |
Returns matrix product of two matrices. | |
Matrix class with compile-time size.
Note that column vectors and row vectors are special cases of a Matrix.
T | Matrix element data type. |
NRows | Number of rows. |
NCols | Number of columns. |
ORDER | Memory layout order. Order::F (i.e., column-major) by default. |
StartIndex | Starting index. Either 0 or 1. |
using amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::reference_type = T& |
using amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::value_type = T |
|
constexprdefault |
Default constructor.
The data are uninitialized by default. If you want to initialize to zero, you can do SmallMatrix<T,NRows,NCols> M{};
.
|
inlineexplicitconstexpr |
Constructs column- or row-vector.
The data are initialized with the given variadic arguments. If the number of argument is less than the size of the vector, the rest of the vector is initialized to zero.
|
inlineexplicit |
Constructs SmallMatrix with nested std::initializer_list.
The initializer list is assumed to be in row-major order, even when the ordering for the SmallMatrix object is colum-major. Below is an example of constructing a matrix with 2 rows and 3 columns.
SmallMatrix<double,2,3> M{{11., 12., 13.}, {21., 22., 23.}};
|
inlinenoexcept |
Returns a const
pointer address to the first element of the SmallMatrix object, as if the object is treated as one-dimensional.
|
inlinenoexcept |
Returns a pointer address to the first element of the SmallMatrix object, as if the object is treated as one-dimensional.
|
inline |
Returns the dot product of two vectors.
|
inlinenoexcept |
Returns a const
pointer address right after the last element of the SmallMatrix object, as if the object is treated as one-dimensional.
|
inlinenoexcept |
Returns a pointer address right after the last element of the SmallMatrix object, as if the object is treated as one-dimensional.
|
inlineconstexpr |
|
inlineconstexpr |
|
inlinestaticconstexprnoexcept |
Returns an identity matrix.
|
inlinenoexcept |
Returns a const reference to element i of a vector.
|
inlinenoexcept |
Returns a reference to element i of a vector.
|
inlinenoexcept |
Returns a const reference to the element at row i and column j.
|
inlinenoexcept |
Returns a reference to the element at row i and column j.
|
inline |
Operator *= that scales this matrix in place by a scalar.
|
inline |
Operator += performing matrix addition as in (*this) += rhs.
|
inline |
Unary minus operator.
|
inline |
Operator -= performing matrix subtraction as in (*this) -= rhs.
|
inlinenoexcept |
Returns a const reference to element i of a vector.
|
inlinenoexcept |
Returns a reference to element i of a vector.
|
inline |
Returns the product of all elements in the matrix.
|
inline |
Set all elements in the matrix to the given value.
|
inline |
Returns the sum of all elements in the matrix.
|
inline |
Returns the trace of a square matrix.
|
inline |
Returns transposed matrix.
|
inline |
Transposes a square matrix in-place.
|
inlinestaticconstexprnoexcept |
Returns a matrix initialized with zeros.
|
friend |
Returns the product of a matrix and a scalar.
|
friend |
Returns matrix product of two matrices.
|
friend |
Returns the product of a scalar and a matrix.
|
friend |
Binary operator + returning the result of maxtrix addition, lhs+rhs.
|
friend |
Binary operator - returning the result of maxtrix subtraction, lhs-rhs.
|
staticconstexpr |
|
private |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |