Block-Structured AMR Software Framework
 
Loading...
Searching...
No Matches
amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex > Struct Template Reference

Matrix class with compile-time size. More...

#include <AMReX_SmallMatrix.H>

Public Types

using value_type = T
 
using reference_type = T &
 

Public Member Functions

__host__ __device__ constexpr SmallMatrix ()=default
 Default constructor.
 
template<typename... Ts, int MM = NRows, int NN = NCols, std::enable_if_t< MM==1||NN==1, int > = 0>
__host__ __device__ constexpr SmallMatrix (Ts... vs)
 Constructs column- or row-vector.
 
__host__ __device__ SmallMatrix (std::initializer_list< std::initializer_list< T > > const &init)
 Constructs SmallMatrix with nested std::initializer_list.
 
__host__ __device__ const T & operator() (int i, int j) const noexcept
 Returns a const reference to the element at row i and column j.
 
__host__ __device__ 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>
__host__ __device__ 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>
__host__ __device__ 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>
__host__ __device__ 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>
__host__ __device__ T & operator[] (int i) noexcept
 Returns a reference to element i of a vector.
 
__host__ __device__ const T * begin () const noexcept
 
__host__ __device__ const T * end () const noexcept
 
__host__ __device__ T * begin () noexcept
 
__host__ __device__ T * end () noexcept
 
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & setVal (T val)
 Set all elements in the matrix to the given value.
 
__host__ __device__ 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>
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & transposeInPlace ()
 Transposes a square matrix in-place.
 
__host__ __device__ T product () const
 Returns the product of all elements in the matrix.
 
__host__ __device__ 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>
__host__ __device__ T trace () const
 Returns the trace of a square matrix.
 
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & operator+= (SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &rhs)
 Operator += performing matrix addition as in (*this) += rhs.
 
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & operator-= (SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &rhs)
 Operator -= performing matrix subtraction as in (*this) -= rhs.
 
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > operator- () const
 Unary minus operator.
 
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & operator*= (T a)
 Operator *= that scales this matrix in place by a scalar.
 
__host__ __device__ 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>
__host__ __device__ constexpr T const & get () const
 
template<int N, std::enable_if_t<(N< NRows *NCols), int > = 0>
__host__ __device__ constexpr T & get ()
 

Static Public Member Functions

template<int MM = NRows, int NN = NCols, std::enable_if_t< MM==NN, int > = 0>
static constexpr __host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > Identity () noexcept
 Returns an identity matrix.
 
static constexpr __host__ __device__ 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

m_mat [NRows *NCols]
 

Friends

__host__ __device__ 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.
 
__host__ __device__ 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.
 
__host__ __device__ 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.
 
__host__ __device__ 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 , class V , int N1, int N2, int N3, Order Ord, int SI>
__host__ __device__ friend decltype(auto) operator* (SmallMatrix< U, N1, N2, Ord, SI > const &lhs, SmallMatrix< V, N2, N3, Ord, SI > const &rhs)
 Returns matrix product of two matrices.
 

Detailed Description

template<class T, int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
struct amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >

Matrix class with compile-time size.

Note that column vectors and row vectors are special cases of a Matrix.

Template Parameters
TMatrix element data type.
NRowsNumber of rows.
NColsNumber of columns.
ORDERMemory layout order. Order::F (i.e., column-major) by default.
StartIndexStarting index. Either 0 or 1.

Member Typedef Documentation

◆ reference_type

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
using amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::reference_type = T&

◆ value_type

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
using amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::value_type = T

Constructor & Destructor Documentation

◆ SmallMatrix() [1/3]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ constexpr amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::SmallMatrix ( )
inlineconstexprdefault

Default constructor.

The data are uninitialized by default. If you want to initialize to zero, you can do SmallMatrix<T,NRows,NCols> M{};.

◆ SmallMatrix() [2/3]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
template<typename... Ts, int MM = NRows, int NN = NCols, std::enable_if_t< MM==1||NN==1, int > = 0>
__host__ __device__ constexpr amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::SmallMatrix ( Ts...  vs)
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.

◆ SmallMatrix() [3/3]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::SmallMatrix ( std::initializer_list< std::initializer_list< T > > const &  init)
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.}};
Matrix class with compile-time size.
Definition AMReX_SmallMatrix.H:36

Member Function Documentation

◆ begin() [1/2]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ const T * amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::begin ( ) const
inlinenoexcept

Returns a const pointer address to the first element of the SmallMatrix object, as if the object is treated as one-dimensional.

◆ begin() [2/2]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ T * amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::begin ( )
inlinenoexcept

Returns a pointer address to the first element of the SmallMatrix object, as if the object is treated as one-dimensional.

◆ dot()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ T amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::dot ( SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &  rhs) const
inline

Returns the dot product of two vectors.

◆ end() [1/2]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ const T * amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::end ( ) const
inlinenoexcept

Returns a const pointer address right after the last element of the SmallMatrix object, as if the object is treated as one-dimensional.

◆ end() [2/2]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ T * amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::end ( )
inlinenoexcept

Returns a pointer address right after the last element of the SmallMatrix object, as if the object is treated as one-dimensional.

◆ get() [1/2]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
template<int N, std::enable_if_t<(N< NRows *NCols), int > = 0>
__host__ __device__ constexpr T & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::get ( )
inlineconstexpr

◆ get() [2/2]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
template<int N, std::enable_if_t<(N< NRows *NCols), int > = 0>
__host__ __device__ constexpr T const & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::get ( ) const
inlineconstexpr

◆ Identity()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
template<int MM = NRows, int NN = NCols, std::enable_if_t< MM==NN, int > = 0>
static constexpr __host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::Identity ( )
inlinestaticconstexprnoexcept

Returns an identity matrix.

◆ operator()() [1/4]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
template<int MM = NRows, int NN = NCols, std::enable_if_t<(MM==1||NN==1), int > = 0>
__host__ __device__ const T & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::operator() ( int  i) const
inlinenoexcept

Returns a const reference to element i of a vector.

◆ operator()() [2/4]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
template<int MM = NRows, int NN = NCols, std::enable_if_t<(MM==1||NN==1), int > = 0>
__host__ __device__ T & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::operator() ( int  i)
inlinenoexcept

Returns a reference to element i of a vector.

◆ operator()() [3/4]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ const T & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::operator() ( int  i,
int  j 
) const
inlinenoexcept

Returns a const reference to the element at row i and column j.

◆ operator()() [4/4]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ T & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::operator() ( int  i,
int  j 
)
inlinenoexcept

Returns a reference to the element at row i and column j.

◆ operator*=()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::operator*= ( a)
inline

Operator *= that scales this matrix in place by a scalar.

◆ operator+=()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::operator+= ( SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &  rhs)
inline

Operator += performing matrix addition as in (*this) += rhs.

◆ operator-()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::operator- ( ) const
inline

Unary minus operator.

◆ operator-=()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::operator-= ( SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &  rhs)
inline

Operator -= performing matrix subtraction as in (*this) -= rhs.

◆ operator[]() [1/2]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
template<int MM = NRows, int NN = NCols, std::enable_if_t<(MM==1||NN==1), int > = 0>
__host__ __device__ const T & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::operator[] ( int  i) const
inlinenoexcept

Returns a const reference to element i of a vector.

◆ operator[]() [2/2]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
template<int MM = NRows, int NN = NCols, std::enable_if_t<(MM==1||NN==1), int > = 0>
__host__ __device__ T & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::operator[] ( int  i)
inlinenoexcept

Returns a reference to element i of a vector.

◆ product()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ T amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::product ( ) const
inline

Returns the product of all elements in the matrix.

◆ setVal()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::setVal ( val)
inline

Set all elements in the matrix to the given value.

◆ sum()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ T amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::sum ( ) const
inline

Returns the sum of all elements in the matrix.

◆ trace()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
template<int MM = NRows, int NN = NCols, std::enable_if_t< MM==NN, int > = 0>
__host__ __device__ T amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::trace ( ) const
inline

Returns the trace of a square matrix.

◆ transpose()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ SmallMatrix< T, NCols, NRows, ORDER, StartIndex > amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::transpose ( ) const
inline

Returns transposed matrix.

◆ transposeInPlace()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
template<int MM = NRows, int NN = NCols, std::enable_if_t< MM==NN, int > = 0>
__host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > & amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::transposeInPlace ( )
inline

Transposes a square matrix in-place.

◆ Zero()

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
static constexpr __host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::Zero ( )
inlinestaticconstexprnoexcept

Returns a matrix initialized with zeros.

Friends And Related Symbol Documentation

◆ operator* [1/3]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ friend SmallMatrix< T, NRows, NCols, ORDER, StartIndex > operator* ( SmallMatrix< T, NRows, NCols, ORDER, StartIndex >  m,
a 
)
friend

Returns the product of a matrix and a scalar.

◆ operator* [2/3]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
template<class U , class V , int N1, int N2, int N3, Order Ord, int SI>
__host__ __device__ friend decltype(auto) operator* ( SmallMatrix< U, N1, N2, Ord, SI > const &  lhs,
SmallMatrix< V, N2, N3, Ord, SI > const &  rhs 
)
friend

Returns matrix product of two matrices.

◆ operator* [3/3]

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ friend SmallMatrix< T, NRows, NCols, ORDER, StartIndex > operator* ( a,
SmallMatrix< T, NRows, NCols, ORDER, StartIndex >  m 
)
friend

Returns the product of a scalar and a matrix.

◆ operator+

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ friend SmallMatrix< T, NRows, NCols, ORDER, StartIndex > operator+ ( SmallMatrix< T, NRows, NCols, ORDER, StartIndex >  lhs,
SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &  rhs 
)
friend

Binary operator + returning the result of maxtrix addition, lhs+rhs.

◆ operator-

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
__host__ __device__ friend SmallMatrix< T, NRows, NCols, ORDER, StartIndex > operator- ( SmallMatrix< T, NRows, NCols, ORDER, StartIndex >  lhs,
SmallMatrix< T, NRows, NCols, ORDER, StartIndex > const &  rhs 
)
friend

Binary operator - returning the result of maxtrix subtraction, lhs-rhs.

Member Data Documentation

◆ column_size

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
constexpr int amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::column_size = NCols
staticconstexpr

◆ m_mat

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
T amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::m_mat[NRows *NCols]
private

◆ ordering

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
constexpr Order amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::ordering = ORDER
staticconstexpr

◆ row_size

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
constexpr int amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::row_size = NRows
staticconstexpr

◆ starting_index

template<class T , int NRows, int NCols, Order ORDER = Order::F, int StartIndex = 0>
constexpr int amrex::SmallMatrix< T, NRows, NCols, ORDER, StartIndex >::starting_index = StartIndex
staticconstexpr

The documentation for this struct was generated from the following file: