geomc 1.0
A c++ linear algebra template library
Public Types | Public Member Functions | Static Public Attributes | List of all members
SimpleMatrix< T, M, N, Lyt, P > Class Template Reference

A basic matrix with M x N elements. More...

#include <geomc/linalg/mtxtypes/SimpleMatrix.h>

Inheritance diagram for SimpleMatrix< T, M, N, Lyt, P >:
WriteableMatrixBase< T, M, N, SimpleMatrix< T, M, N, Lyt, P > > MatrixBase< T, M, N, Derived >

Public Types

typedef FlatMatrixLayout< T, Lyt >::const_row_iterator const_iterator
 Read-only row-major iterator over the elements of the matrix. This is a T* if the matrix is row-major; a proxy otherwise.
 
typedef FlatMatrixLayout< T, Lyt >::const_row_iterator const_row_iterator
 Read-only iterator over the elements of a row. This is a T* if the matrix is row-major; a proxy otherwise.
 
typedef FlatMatrixLayout< T, Lyt >::const_col_iterator const_col_iterator
 Read-only iterator over the elements of a column. This is a T* if the matrix is column-major; a proxy otherwise.
 
typedef T & reference
 Reference to element type.
 
typedef FlatMatrixLayout< T, Lyt >::row_iterator iterator
 Writeable row-major iterator over the elements of the matrix. This is a T* if the matrix is row-major; a proxy otherwise.
 
typedef FlatMatrixLayout< T, Lyt >::row_iterator row_iterator
 Writeable iterator over the elements of a row. This is a T* if the matrix is row-major; a proxy otherwise.
 
typedef FlatMatrixLayout< T, Lyt >::col_iterator col_iterator
 Writeable iterator over the elements of a column. This is a T* if the matrix is column-major; a proxy otherwise.
 
typedef iterator region_iterator
 Writeable row-major region iterator.
 
typedef T elem_t
 Element type.
 
typedef const_iterator const_region_iterator
 Read-only row-major iterator over the matrix elements in a rectangular region.
 
typedef Storage< storage_token_t, _ImplStorageObjCount< Derived >::count > storagebuffer_t
 
typedef Derived recurring_t
 

Public Member Functions

 SimpleMatrix (index_t nrows, index_t ncols)
 Construct a matrix of size (nrows x ncols). More...
 
 SimpleMatrix (T *src_data, index_t nrows, index_t ncols)
 Construct a matrix of size (nrows x ncols), initialized with src_data. More...
 
template<typename Mx >
 SimpleMatrix (const Mx &mtx)
 
template<typename U >
SimpleMatrix< T, M, N > & operator*= (U k)
 
index_t rows () const
 
index_t cols () const
 
const_row_iterator row (index_t i) const
 
row_iterator row (index_t i)
 
const_col_iterator col (index_t i) const
 
col_iterator col (index_t i)
 
const_iterator begin () const
 
const_iterator end () const
 
iterator begin ()
 
iterator end ()
 
T * data_begin ()
 
T * data_end ()
 
const T * data_begin () const
 
const T * data_end () const
 
operator() (index_t r, index_t c) const
 
reference operator() (index_t r, index_t c)
 
reference set (index_t r, index_t c, T val)
 
WrapperMatrix< T, N, M,(Lyt==ROW_MAJOR) ? COL_MAJOR :ROW_MAJOR > as_transpose () const
 
void set_identity ()
 
void set_zero ()
 
void get_storage_tokens (storage_token_t *buf) const
 
constexpr index_t storage_token_count () const
 
derived_row_iterator operator[] (index_t i)
 
derived_const_row_iterator operator[] (index_t i) const
 
region_iterator region_begin (const MatrixRegion &r)
 
const_region_iterator region_begin (const MatrixRegion &r) const
 
region_iterator region_end (const MatrixRegion &r)
 
const_region_iterator region_end (const MatrixRegion &r) const
 
storagebuffer_t get_storage_token_buffer () const
 

Static Public Attributes

static constexpr MatrixLayout Layout = Lyt
 The data layout of this matrix.
 
static constexpr index_t ROWDIM = M
 Row dimension template parameter.
 
static constexpr index_t COLDIM = N
 Column dimension template parameter.
 

Detailed Description

template<typename T, index_t M, index_t N, MatrixLayout Lyt, StoragePolicy P>
class geom::SimpleMatrix< T, M, N, Lyt, P >

A basic matrix with M x N elements.

Template Parameters
TElement type.
MRow dimension.
NColumn dimension.
LytLayout of the underlying array (ROW_MAJOR or COL_MAJOR). ROW_MAJOR is the default.
PPolicy for memory ownership of the backing array.

Example:

SimpleMatrix<double,4,4> mx;

If M or N are 0, the matrix has runtime-chosen size.

The storage policy behavior is as follows:

Note that in c++11, array duplicatations will use rvalue references to avoid a performing full array-copy where possible.

Wrapping an array

A SimpleMatrix can be made into a wrapper around a user-owned array like so:

double myRowMajorArray[16] = { ... };
SimpleMatrix<double,4,4,STORAGE_WRAPPED> mtx(myRowMajorArray);

In the above example, no array duplication will occur, and myRowMajorArray is used direcly as the backing storage for the matrix. Note the use of STORAGE_WRAPPED for the SimpleMatrix's storage policy template parameter.

In c++11, a template alias is available for this construction, called WrapperMatrix:

WrapperMatrix<double,4,4> wmtx(myRowMajorArray);

For more on matrices, see the matrix module documentation.

Constructor & Destructor Documentation

◆ SimpleMatrix() [1/3]

SimpleMatrix ( index_t  nrows,
index_t  ncols 
)
inlineexplicit

Construct a matrix of size (nrows x ncols).

For matrices with dynamic dimension, a size argument is required for that dimension. Size arguments will be ignored for dimensions that are statically-sized.

Examples:

SimpleMatrix<double, 3, 3> m1;
SimpleMatrix<double, 0, 0> m2(3, 3);
SimpleMatrix<double, 0, 0> m3; // XXX: Compiler error!

This constructor is not available if the storage policy is STORAGE_WRAPPED.

Parameters
nrowsNumber of rows in the matrix.
ncolsNumber of columns in the matrix.

◆ SimpleMatrix() [2/3]

SimpleMatrix ( T *  src_data,
index_t  nrows,
index_t  ncols 
)
inlineexplicit

Construct a matrix of size (nrows x ncols), initialized with src_data.

For matrices with dynamic dimension, a size argument is required for that dimension. Size arguments will be ignored for dimensions that are statically-sized.

If the storage policy is STORAGE_WRAPPED, src_data will be used directly as the backing storage, and its lifetime must exceed the lifetime of this matrix.

Parameters
src_dataArray of nrows * ncols elements, in row-major order.
nrowsNumber of rows in the matrix.
ncolsNumber of columns in the matrix.

◆ SimpleMatrix() [3/3]

SimpleMatrix ( const Mx &  mtx)
inline

Construct and initialize this matrix with the contents of another.

This constructor is not available if the storage policy is STORAGE_WRAPPED.

Template Parameters
MxA matrix type with agreeing dimension.
Parameters
mtxMatrix containing source elements.

Member Function Documentation

◆ as_transpose()

WrapperMatrix< T, N, M,(Lyt==ROW_MAJOR) ? COL_MAJOR :ROW_MAJOR > as_transpose ( ) const
inline

Reinterpret this matrix as a transposed version of itself.

The returned matrix is backed by this matrix's underlying memory. As such, its lifetime must not be longer than that of this matrix. Changes to the elements of this matrix will also be reflected in the resultant matrix, and vice versa.

This operation is O(1), and fuctions by constructing a new WrapperMatrix with opposite layout (i.e., column-major if this matrix is row-major, or row-major if this matrix is column-major).

◆ begin() [1/2]

iterator begin ( )
inline
Returns
A writeable, random-access, row-major iterator over the elements of this matrix, pointing to the element at (0,0).

◆ begin() [2/2]

const_iterator begin ( ) const
inline
Returns
A read-only, random-access, row-major iterator over the elements of this matrix, pointing to the element at (0,0).

◆ col() [1/2]

col_iterator col ( index_t  i)
inline
Parameters
iIndex of column (zero-indexed)
Returns
A writeable iterator over the elements of row i.

◆ col() [2/2]

const_col_iterator col ( index_t  i) const
inline
Parameters
iIndex of column (zero-indexed)
Returns
A read-only iterator over the elements of row i.

◆ cols()

index_t cols ( ) const
inline
Returns
number of columns in the matrix.

◆ data_begin() [1/2]

T * data_begin ( )
inline
Returns
A pointer to the bare data array, in the layout policy of this matrix.

◆ data_begin() [2/2]

const T * data_begin ( ) const
inline
Returns
A pointer to the read-only bare data array, in the layout policy of this matrix.

◆ data_end() [1/2]

T * data_end ( )
inline
Returns
A pointer to the end of the bare data array.

◆ data_end() [2/2]

const T * data_end ( ) const
inline
Returns
A pointer to the end of the read-only bare data array.

◆ end() [1/2]

iterator end ( )
inline
Returns
A writeable, random-access, row-major iterator over the elements of this matrix, pointing to the element just beyond the last element in the matrix.

◆ end() [2/2]

const_iterator end ( ) const
inline
Returns
A read-only, random-access, row-major iterator over the elements of this matrix, pointing to the just beyond the last element in the matrix.

◆ operator()() [1/2]

reference operator() ( index_t  r,
index_t  c 
)
inline

Get the element at (row, col).

Parameters
rZero-indexed row coordinate
cZero-indexed column coordinate
Returns
A reference to the element at (row, col)

◆ operator()() [2/2]

T operator() ( index_t  r,
index_t  c 
) const
inline

Get the element at (row, col).

Parameters
rZero-indexed row coordinate
cZero-indexed column coordinate
Returns
The element at (row, col)

◆ operator*=()

SimpleMatrix< T, M, N > & operator*= ( k)
inline

Scalar in-place multiplication.

Template Parameters
UA type satisfying std::is_scalar<>.
Parameters
kScalar value.
Returns
A reference to this.

◆ operator[]() [1/2]

derived_row_iterator operator[] ( index_t  i)
inlineinherited
Parameters
iIndex of row (zero-indexed)
Returns
A writeable iterator over the elements of row i.

◆ operator[]() [2/2]

derived_const_row_iterator operator[] ( index_t  i) const
inlineinherited
Parameters
iIndex of row (zero-indexed)
Returns
A const iterator over the elements of row i

◆ region_begin() [1/2]

region_iterator region_begin ( const MatrixRegion r)
inlineinherited
Parameters
rThe zero-indexed region to iterate over. The upper extreme coordinates represent the index just beyond the last element to be iterated over.
Returns
A writeable, random-access, row-major iterator over the elements in region r, pointing at the first element in the region (upper left corner).

◆ region_begin() [2/2]

const_region_iterator region_begin ( const MatrixRegion r) const
inlineinherited
Parameters
rThe zero-indexed region to iterate over. The upper extreme coordinates represent the index just beyond the last element to be iterated over.
Returns
A read-only, random-access, row-major iterator over the elements in region r, pointing at the first element in the region (upper left corner).

◆ region_end() [1/2]

region_iterator region_end ( const MatrixRegion r)
inlineinherited
Parameters
rThe zero-indexed region to iterate over. The upper extreme coordinates represent the index just beyond the last element to be iterated over.
Returns
A writeable, random-access, row-major iterator over the elements in region r, pointing at the element just beyond the last element in the region.

◆ region_end() [2/2]

const_region_iterator region_end ( const MatrixRegion r) const
inlineinherited
Parameters
rThe zero-indexed region to iterate over. The upper extreme coordinates represent the index just beyond the last element to be iterated over.
Returns
A read-only, random-access, row-major iterator over the elements in region r, pointing at the element just beyond the last element in the region.

◆ row() [1/2]

row_iterator row ( index_t  i)
inline
Parameters
iIndex of row (zero-indexed)
Returns
A writeable iterator over the elements of row i.

◆ row() [2/2]

const_row_iterator row ( index_t  i) const
inline
Parameters
iIndex of row (zero-indexed)
Returns
A read-only iterator over the elements of row i.

◆ rows()

index_t rows ( ) const
inline
Returns
Number of rows in the matrix.

◆ set()

reference set ( index_t  r,
index_t  c,
val 
)
inline

Set the element at (row, col) to val.

Parameters
rZero-indexed row coordinate
cZero-indexed column coordinate
valNew value of element at (row, col)
Returns
A reference to the element at (row, col), for convenience.

◆ set_identity()

void set_identity ( )
inline

Clear this matrix and set its elements to the identity matrix.

◆ set_zero()

void set_zero ( )
inline

Set all the elements of this matrix to zero.


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