Thea
|
Wrapper for a dense 2D matrix, implementing a pure virtual interface for passing across shared library boundaries. More...
#include <MatrixWrapper.hpp>
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... | |
Value * | data () |
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... | |
Value & | mutableAt (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... | |
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.
|
inherited |
Type of values stored in the matrix.
Definition at line 33 of file IMatrix.hpp.
|
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.
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.
~MatrixWrapper | ( | ) |
Destructor.
Definition at line 52 of file MatrixWrapper.hpp.
|
virtual |
If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.
Else, return null.
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.
|
virtual |
If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.
Else, return null.
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.
|
virtual |
If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access.
Else, return null.
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.
|
virtual |
If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access.
Else, return null.
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.
|
virtual |
If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.
Else, return null.
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.
|
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.
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.
|
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.
|
virtual |
Get the number of columns.
Implements IMatrix< MatrixT::value_type >.
Definition at line 65 of file MatrixWrapper.hpp.
|
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.
|
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.
|
virtual |
Set all elements of the matrix to a given value.
Implements IDenseMatrix< MatrixT::value_type >.
Definition at line 99 of file MatrixWrapper.hpp.
|
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.
|
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.
|
virtual |
Is the matrix stored in column-major format?
Implements IRowOrColumnMajorMatrix< MatrixT::value_type >.
Definition at line 94 of file MatrixWrapper.hpp.
|
virtual |
Check if the matrix can be freely resized.
Implements IMatrix< MatrixT::value_type >.
Definition at line 68 of file MatrixWrapper.hpp.
|
virtual |
Is the matrix stored in row-major format?
Implements IRowOrColumnMajorMatrix< MatrixT::value_type >.
Definition at line 93 of file MatrixWrapper.hpp.
|
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.
|
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.
Implements IMatrix< MatrixT::value_type >.
Definition at line 74 of file MatrixWrapper.hpp.
|
virtual |
Get the number of rows.
Implements IMatrix< MatrixT::value_type >.
Definition at line 64 of file MatrixWrapper.hpp.
|
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.
|
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.
|
virtual |
Set all elements to zero.
Implements IMatrix< MatrixT::value_type >.
Definition at line 66 of file MatrixWrapper.hpp.