SCOREC core
Parallel unstructured mesh tools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
mth::Matrix< T, M, N > Class Template Reference

compile-time (static) matrix More...

Inheritance diagram for mth::Matrix< T, M, N >:
can::Array< Vector< T, N >, M >

Public Member Functions

 Matrix ()
 default constructor
 
 Matrix (unsigned m, unsigned n)
 construct with m by n elements More...
 
unsigned rows () const
 get the number of rows
 
unsigned cols () const
 get the number of columns
 
T & operator() (unsigned i, unsigned j)
 mutable index operator More...
 
T const & operator() (unsigned i, unsigned j) const
 immutable index operator More...
 
Matrix< T, M, N > operator+ (Matrix< T, M, N > const &b) const
 add two matrices
 
Matrix< T, M, N > operator- (Matrix< T, M, N > const &b) const
 subtract two matrices
 
Matrix< T, M, N > operator* (T const &s) const
 multiply by a scalar
 
Matrix< T, M, N > operator/ (T const &s) const
 divide by a scalar
 
Vector< T, M > operator* (Vector< T, N > const &b) const
 multiply a matrix by a vector
 
template<unsigned O>
Matrix< T, M, O > operator* (Matrix< T, N, O > const &b) const
 multiply two matrices More...
 
void zero ()
 zero a matrix
 
- Public Member Functions inherited from can::Array< Vector< T, N >, M >
 Array ()
 default constructor - necessary
 
 Array (Array< Vector< T, N >, N > const &other)
 copy constructor
 
 ~Array ()
 elems is destroyed automatically
 
Array< Vector< T, N >, N > & operator= (Array< Vector< T, N >, N > const &other)
 assignment operator
 
Vector< T, N > & operator[] (unsigned i)
 mutable index operator
 
Vector< T, N >const & operator[] (unsigned i) const
 immutable index operator
 
unsigned size () const
 get the size of this array
 

Detailed Description

template<class T, unsigned M = 0, unsigned N = 0>
class mth::Matrix< T, M, N >

compile-time (static) matrix

Definition at line 23 of file mthMatrix.h.

Constructor & Destructor Documentation

template<class T, unsigned M = 0, unsigned N = 0>
mth::Matrix< T, M, N >::Matrix ( unsigned  m,
unsigned  n 
)
inline

construct with m by n elements

A dummy constructor Matrix(m,n) is provided so that dynamic and static matrices can be used interchangebly

Definition at line 31 of file mthMatrix.h.

31 { (void) m; (void) n; }

Member Function Documentation

template<class T, unsigned M = 0, unsigned N = 0>
T& mth::Matrix< T, M, N >::operator() ( unsigned  i,
unsigned  j 
)
inline

mutable index operator

An index operator (i,j) is provided so that compile time matrices and runtime-sized matrices can be used interchangebly, without worrying about changing index syntax

Definition at line 40 of file mthMatrix.h.

40 {return (*this)[i][j];}
template<class T, unsigned M = 0, unsigned N = 0>
T const& mth::Matrix< T, M, N >::operator() ( unsigned  i,
unsigned  j 
) const
inline

immutable index operator

see the mutable index operator details

Definition at line 43 of file mthMatrix.h.

43 {return (*this)[i][j];}
template<class T, unsigned M = 0, unsigned N = 0>
template<unsigned O>
Matrix<T,M,O> mth::Matrix< T, M, N >::operator* ( Matrix< T, N, O > const &  b) const
inline

multiply two matrices

the extra template parameter generates code for all possible combinations of matrix sizes

Definition at line 88 of file mthMatrix.h.

89  {
90  Matrix<T,M,O> r;
91  for (unsigned i=0; i < M; ++i)
92  for (unsigned j=0; j < O; ++j)
93  {
94  r[i][j] = this->elems[i][0]*b[0][j];
95  for (unsigned k=1; k < N; ++k)
96  r[i][j] += this->elems[i][k]*b[k][j];
97  }
98  return r;
99  }

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