Thea
Public Types | Public Member Functions | List of all members
MatrixWrapper< MatrixT > Class Template Reference

Wrapper for a dense 2D matrix, implementing a pure virtual interface for passing across shared library boundaries. More...

#include <MatrixWrapper.hpp>

Inheritance diagram for MatrixWrapper< MatrixT >:
IDenseMatrix< MatrixT::value_type > IAddressableMatrix< MatrixT::value_type > IRowOrColumnMajorMatrix< MatrixT::value_type > IMatrix< MatrixT::value_type > IMatrix< MatrixT::value_type >

Public Types

typedef MatrixT::value_type Value
 Type of values stored in the matrix. More...
 
typedef MatrixT::value_type value_type
 Type of values stored in the matrix (STL convention). More...
 
typedef MatrixT WrappedMatrix
 The wrapped matrix type. More...
 

Public Member Functions

IAddressableMatrix< Value > const * asAddressable () const
 If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access. More...
 
IAddressableMatrix< Value > * asAddressable ()
 If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access. More...
 
IDenseMatrix< Value > const * asDense () const
 If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access. More...
 
IDenseMatrix< Value > * asDense ()
 If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access. More...
 
ISparseMatrix< Value > const * asSparse () const
 If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access. More...
 
ISparseMatrix< Value > * asSparse ()
 If the matrix is sparse, get a pointer to a derived interface giving sparse-specific access. More...
 
Value const & at (int64 row, int64 col) const
 Get a read-only element. More...
 
int64 cols () const
 Get the number of columns. More...
 
Value const * data () const
 Get a pointer to the beginning of the matrix's data block. More...
 
Valuedata ()
 Get a pointer to the beginning of the matrix's data block. More...
 
void fill (Value value)
 Set all elements of the matrix to a given value. More...
 
void getColumn (int64 col, Value *values) const
 Get a column of the matrix. More...
 
MatrixT const & getMatrix () const
 Get the wrapped matrix. More...
 
MatrixT & getMatrix ()
 Get the wrapped matrix. More...
 
void getRow (int64 row, Value *values) const
 Get a row of the matrix. More...
 
int8 isColumnMajor () const
 Is the matrix stored in column-major format? More...
 
int8 isResizable () const
 Check if the matrix can be freely resized. More...
 
int8 isRowMajor () const
 Is the matrix stored in row-major format? More...
 
 MatrixWrapper (MatrixT *mat=nullptr)
 Constructor. More...
 
ValuemutableAt (int64 row, int64 col)
 Get an element that can be directly modified. More...
 
int8 resize (int64 nrows, int64 ncols)
 Resize the matrix to new dimensions, if isResizable() returns true. More...
 
int64 rows () const
 Get the number of rows. More...
 
void setColumn (int64 col, Value const *values)
 Set a column of the matrix. More...
 
void setMatrix (MatrixT *mat)
 Set the wrapped matrix. More...
 
void setRow (int64 row, Value const *values)
 Set a row of the matrix. More...
 
void setZero ()
 Set all elements to zero. More...
 
 ~MatrixWrapper ()
 Destructor. More...
 

Detailed Description

template<typename MatrixT>
class Thea::MatrixWrapper< MatrixT >

Wrapper for a dense 2D matrix, implementing a pure virtual interface for passing across shared library boundaries.

MatrixT must be an instance of the Eigen::Matrix template.

Definition at line 29 of file MatrixWrapper.hpp.

Member Typedef Documentation

typedef MatrixT::value_type Value
inherited

Type of values stored in the matrix.

Definition at line 33 of file IMatrix.hpp.

typedef MatrixT::value_type value_type
inherited

Type of values stored in the matrix (STL convention).

Definition at line 34 of file IMatrix.hpp.

typedef MatrixT WrappedMatrix

The wrapped matrix type.

Definition at line 40 of file MatrixWrapper.hpp.

Constructor & Destructor Documentation

MatrixWrapper ( MatrixT *  mat = nullptr)

Constructor.

The passed matrix must persist as long as this class is being actively used, since it is accessed via a pointer. If a null pointer is supplied, the functions of this class will have undefined behavior until a valid matrix is supplied via setMatrix or the copy constructor.

Definition at line 49 of file MatrixWrapper.hpp.

Destructor.

Definition at line 52 of file MatrixWrapper.hpp.

Member Function Documentation

IAddressableMatrix<Value> const* asAddressable ( ) const
virtual

If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.

Else, return null.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IMatrix< MatrixT::value_type >.

Definition at line 126 of file MatrixWrapper.hpp.

IAddressableMatrix<Value>* asAddressable ( )
virtual

If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.

Else, return null.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IMatrix< MatrixT::value_type >.

Definition at line 127 of file MatrixWrapper.hpp.

IDenseMatrix<Value> const* asDense ( ) const
virtual

If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access.

Else, return null.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IAddressableMatrix< MatrixT::value_type >.

Definition at line 130 of file MatrixWrapper.hpp.

IDenseMatrix<Value>* asDense ( )
virtual

If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access.

Else, return null.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IAddressableMatrix< MatrixT::value_type >.

Definition at line 131 of file MatrixWrapper.hpp.

ISparseMatrix<Value> const* asSparse ( ) const
virtual

If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.

Else, return null.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IMatrix< MatrixT::value_type >.

Definition at line 128 of file MatrixWrapper.hpp.

ISparseMatrix<Value>* asSparse ( )
virtual

If the matrix is sparse, get a pointer to a derived interface giving sparse-specific access.

Else, return null. Note that a sparse matrix can still be addressable, e.g. if it is stored as a map of (row, col) –> value pairs.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IMatrix< MatrixT::value_type >.

Definition at line 129 of file MatrixWrapper.hpp.

Value const& at ( int64  row,
int64  col 
) const
virtual

Get a read-only element.

Most derived/underlying classes define operator() to access an element quicker, without the virtual function overhead. Use this function only in generic algorithms that need polymorphic access to matrices without using templates, or when accessing matrices across shared library boundaries.

Implements IAddressableMatrix< MatrixT::value_type >.

Definition at line 89 of file MatrixWrapper.hpp.

int64 cols ( ) const
virtual

Get the number of columns.

Implements IMatrix< MatrixT::value_type >.

Definition at line 65 of file MatrixWrapper.hpp.

Value const* data ( ) const
virtual

Get a pointer to the beginning of the matrix's data block.

Implements IDenseMatrix< MatrixT::value_type >.

Definition at line 97 of file MatrixWrapper.hpp.

Value* data ( )
virtual

Get a pointer to the beginning of the matrix's data block.

Implements IDenseMatrix< MatrixT::value_type >.

Definition at line 98 of file MatrixWrapper.hpp.

void fill ( Value  value)
virtual

Set all elements of the matrix to a given value.

Warning
This is safe to call across shared library boundaries only if T is a POD type.

Implements IDenseMatrix< MatrixT::value_type >.

Definition at line 99 of file MatrixWrapper.hpp.

void getColumn ( int64  col,
Value values 
) const
virtual

Get a column of the matrix.

values must be preallocated with rows() elements.

Implements IAddressableMatrix< MatrixT::value_type >.

Definition at line 113 of file MatrixWrapper.hpp.

MatrixT const& getMatrix ( ) const

Get the wrapped matrix.

Definition at line 55 of file MatrixWrapper.hpp.

MatrixT& getMatrix ( )

Get the wrapped matrix.

Definition at line 58 of file MatrixWrapper.hpp.

void getRow ( int64  row,
Value values 
) const
virtual

Get a row of the matrix.

values must be preallocated with cols() elements.

Implements IAddressableMatrix< MatrixT::value_type >.

Definition at line 101 of file MatrixWrapper.hpp.

int8 isColumnMajor ( ) const
virtual

Is the matrix stored in column-major format?

Implements IRowOrColumnMajorMatrix< MatrixT::value_type >.

Definition at line 94 of file MatrixWrapper.hpp.

int8 isResizable ( ) const
virtual

Check if the matrix can be freely resized.

Implements IMatrix< MatrixT::value_type >.

Definition at line 68 of file MatrixWrapper.hpp.

int8 isRowMajor ( ) const
virtual

Is the matrix stored in row-major format?

Implements IRowOrColumnMajorMatrix< MatrixT::value_type >.

Definition at line 93 of file MatrixWrapper.hpp.

Value& mutableAt ( int64  row,
int64  col 
)
virtual

Get an element that can be directly modified.

Most derived/underlying classes define operator() to access an element quicker, without the virtual function overhead. Use this function only in generic algorithms that need polymorphic access to matrices without using templates, or when accessing matrices across shared library boundaries.

Implements IAddressableMatrix< MatrixT::value_type >.

Definition at line 90 of file MatrixWrapper.hpp.

int8 resize ( int64  nrows,
int64  ncols 
)
virtual

Resize the matrix to new dimensions, if isResizable() returns true.

Else, if the new dimensions are identical to the old dimensions, do nothing and return true, else return false. If the dimensions are changed, existing entries will in general not be preserved in the resized matrix.

Returns
True if the final dimensions of the matrix are identical to the desired dimensions, else false.

Implements IMatrix< MatrixT::value_type >.

Definition at line 74 of file MatrixWrapper.hpp.

int64 rows ( ) const
virtual

Get the number of rows.

Implements IMatrix< MatrixT::value_type >.

Definition at line 64 of file MatrixWrapper.hpp.

void setColumn ( int64  col,
Value const *  values 
)
virtual

Set a column of the matrix.

values must contain rows() elements.

Implements IAddressableMatrix< MatrixT::value_type >.

Definition at line 119 of file MatrixWrapper.hpp.

void setMatrix ( MatrixT *  mat)

Set the wrapped matrix.

Definition at line 61 of file MatrixWrapper.hpp.

void setRow ( int64  row,
Value const *  values 
)
virtual

Set a row of the matrix.

values must contain cols() elements.

Implements IAddressableMatrix< MatrixT::value_type >.

Definition at line 107 of file MatrixWrapper.hpp.

void setZero ( )
virtual

Set all elements to zero.

Implements IMatrix< MatrixT::value_type >.

Definition at line 66 of file MatrixWrapper.hpp.


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