LOOS  v2.3.2
loos::Math::Matrix< T, OrderPolicy, StoragePolicy > Class Template Reference

Simple matrix template class using policy classes to determine behavior. More...

#include <MatrixImpl.hpp>

Inheritance diagram for loos::Math::Matrix< T, OrderPolicy, StoragePolicy >:
Collaboration diagram for loos::Math::Matrix< T, OrderPolicy, StoragePolicy >:

Public Types

typedef T element_type
 

Public Member Functions

 Matrix ()
 Unitialized matrix.
 
 Matrix (T *p, const uint b, const uint a)
 Wrap an existing block of data with a Matrix. More...
 
 Matrix (const uint b, const uint a)
 Create a new block of data for the requested Matrix.
 
Matrix< T, OrderPolicy, StoragePolicy > copy (void) const
 Deep copy...
 
uint rows (void) const
 
uint cols (void) const
 
T & operator() (const uint y, const uint x)
 Return the appropriate element (y-rows, x-cols)
 
const T & operator() (const uint y, const uint x) const
 
void metaData (const std::string &s)
 
std::string metaData (void) const
 
void reset (void)
 Deallocate data...
 

Friends

Matrix< T, RowMajor, StoragePolicy > reinterpretOrder (const Matrix< T, ColMajor, StoragePolicy > &)
 Convert a Col-major to Row-major format.
 
Matrix< T, ColMajor, StoragePolicy > reinterpretOrder (const Matrix< T, RowMajor, StoragePolicy > &)
 Convert a Row-major to Col-major format.
 

Detailed Description

template<typename T, class OrderPolicy = ColMajor, template< typename > class StoragePolicy = SharedArray>
class loos::Math::Matrix< T, OrderPolicy, StoragePolicy >

Simple matrix template class using policy classes to determine behavior.

This class is essentially a wrapper around a block of data with a matrix-style interface. It is not (currently) meant to offer the same operations that a mathematical matrix would offer, despite being in the loos::Math namespace.

There are two options to a Matrix, other than the raw data type. The memory layout can be configured, i.e. row-major, column-major, and triangular (symmetric). The storage method can also be configured as either a SharedArray (dense) or SparseArray (sparse). These options are passed to the Matrix template at instantiation. The default options are for a column-major matrix that is dense.

For example, the simplest declaration:

creates a dense, column-major matrix M whose elements are a double.

This creates a dense, row-major matrix N whose elements are floats.

Finally,

creates a sparse, triangular matrix whose elements are ints.

Access to the elements of a matrix is permitted in two different ways. You can access the (j,i)'th element (j-rows, i-cols) by using operator(), i.e.

M(j,i) = foo;
fu = M(j+1,i);

Alternatively, for dense matrices, you can access the linear array of data underneath the matrix interpretation using operator[], i.e.

foo = M[i*rows+j];
M[i*rows+j+1] = fu;

For dense matrices, you can also access the raw block of memory by getting a pointer to it,

double *dblptr = M.get();
   Finally, you can access iterators into the matrix much like you would
   with an STL container,
std::copy(M.begin(), M.end(), ostream_iterator<double>(cout, "\n"));
   Not all Matrix interface functions are valid for all Matrix types.
   As mentioned above, you cannot access the pointer to a sparse matrix
   nor use the operator[].

   Finally, all matrices are initialized with 0 for each element...

   \b NOTE
   Although the Matrix class lives in loos::Math, the I/O
   functions are all in the loos namespace.  The reason for this
   is so you can import the loos namespace and get the I/O
   functions without importing the Matrix name, thereby allowing
   you to typedef it in your code...
using namespace std;
using namespace loos;
...
Matrix M;
writeAsciiMatrix(filename, M, "My matrix");
   For more information, see loos::writeAsciiMatrix() and loos::readAsciiMatrix()

Definition at line 53 of file MatrixImpl.hpp.

Constructor & Destructor Documentation

template<typename T, class OrderPolicy = ColMajor, template< typename > class StoragePolicy = SharedArray>
loos::Math::Matrix< T, OrderPolicy, StoragePolicy >::Matrix ( T *  p,
const uint  b,
const uint  a 
)
inline

Wrap an existing block of data with a Matrix.

This may not make sense, depending on storage policy (i.e. sparse matrices)

Definition at line 160 of file MatrixImpl.hpp.


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