Thea
Classes | Public Types | Public Member Functions | List of all members
MappedMatrix< T, IndexT > Class Template Reference

Matrix that stores elements as a (row, col) –> value map. More...

#include <MappedMatrix.hpp>

Inheritance diagram for MappedMatrix< T, IndexT >:
IAddressableMatrix< T > ISparseMatrix< T > IMatrix< T > IMatrix< T >

Classes

class  Triplet
 The stored (row, col, value) triplet type. More...
 

Public Types

typedef IndexT Index
 The type of row or column indices. More...
 
typedef TripletSet::const_iterator TripletConstIterator
 Read-only iterator over triplets. More...
 
typedef T Value
 Type of values stored in the matrix. More...
 
typedef T value_type
 Type of values stored in the matrix (STL convention). More...
 

Public Member Functions

IAddressableMatrix< T > 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< T > * asAddressable ()
 If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access. More...
 
ICompressedSparseMatrix< T > const * asCompressed () const
 If the matrix is stored in compressed column or row format, get a pointer to a derived interface supporting access specific to that format. More...
 
ICompressedSparseMatrix< T > * asCompressed ()
 If the matrix is stored in compressed column or row format, get a pointer to a derived interface supporting access specific to that format. More...
 
IDenseMatrix< T > 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< T > * asDense ()
 If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access. More...
 
ISparseMatrix< T > 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< T > * asSparse ()
 If the matrix is sparse, get a pointer to a derived interface giving sparse-specific access. More...
 
T const & at (int64 row, int64 col) const
 Get a read-only element. More...
 
int64 cols () const
 Get the number of columns. More...
 
void getColumn (int64 col, T *values) const
 Get a column of the matrix. More...
 
void getRow (int64 row, T *values) const
 Get a row of the matrix. More...
 
int8 isResizable () const
 Check if the matrix can be freely resized. More...
 
 MappedMatrix (intx nrows=0, intx ncols=0)
 Constructor. More...
 
T & mutableAt (int64 row, int64 col)
 Get an element that can be directly modified. More...
 
int64 numStoredElements () const
 Get the number of entries actually stored in the matrix. More...
 
T const & operator() (Index row, Index col) const
 Get the element at position (row, col). 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 set (Index row, Index col, T const &value)
 Set the element at position (row, col). More...
 
void setColumn (int64 col, T const *values)
 Set a column of the matrix. More...
 
void setRow (int64 row, T const *values)
 Set a row of the matrix. More...
 
void setZero ()
 Set all elements to zero. More...
 
TripletConstIterator tripletsBegin () const
 Get a read-only iterator pointing to the first (row, col, value) triplet in the matrix. More...
 
TripletConstIterator tripletsEnd () const
 Get a read-only iterator pointing to one past the last (row, col, value) triplet in the matrix. More...
 

Detailed Description

template<typename T = Real, typename IndexT = intx>
class Thea::MappedMatrix< T, IndexT >

Matrix that stores elements as a (row, col) –> value map.

Definition at line 28 of file MappedMatrix.hpp.

Member Typedef Documentation

typedef IndexT Index

The type of row or column indices.

Definition at line 31 of file MappedMatrix.hpp.

typedef TripletSet::const_iterator TripletConstIterator

Read-only iterator over triplets.

Definition at line 98 of file MappedMatrix.hpp.

typedef T Value
inherited

Type of values stored in the matrix.

Definition at line 33 of file IMatrix.hpp.

typedef T value_type
inherited

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

Definition at line 34 of file IMatrix.hpp.

Constructor & Destructor Documentation

MappedMatrix ( intx  nrows = 0,
intx  ncols = 0 
)

Constructor.

Definition at line 101 of file MappedMatrix.hpp.

Member Function Documentation

IAddressableMatrix<T> 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< T >.

Definition at line 233 of file MappedMatrix.hpp.

IAddressableMatrix<T>* 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< T >.

Definition at line 234 of file MappedMatrix.hpp.

ICompressedSparseMatrix<T> const* asCompressed ( ) const
virtual

If the matrix is stored in compressed column or row format, get a pointer to a derived interface supporting access specific to that format.

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 ISparseMatrix< T >.

Definition at line 239 of file MappedMatrix.hpp.

ICompressedSparseMatrix<T>* asCompressed ( )
virtual

If the matrix is stored in compressed column or row format, get a pointer to a derived interface supporting access specific to that format.

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 ISparseMatrix< T >.

Definition at line 240 of file MappedMatrix.hpp.

IDenseMatrix<T> 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< T >.

Definition at line 237 of file MappedMatrix.hpp.

IDenseMatrix<T>* 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< T >.

Definition at line 238 of file MappedMatrix.hpp.

ISparseMatrix<T> 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< T >.

Definition at line 235 of file MappedMatrix.hpp.

ISparseMatrix<T>* 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< T >.

Definition at line 236 of file MappedMatrix.hpp.

T 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.

If the element is not already stored in the matrix, it will return a zero value.

Implements IAddressableMatrix< T >.

Definition at line 159 of file MappedMatrix.hpp.

int64 cols ( ) const
virtual

Get the number of columns.

Implements IMatrix< T >.

Definition at line 109 of file MappedMatrix.hpp.

void getColumn ( int64  col,
T *  values 
) const
virtual

Get a column of the matrix.

values must be preallocated with rows() elements.

This function is in general very slow because it has to iterate through all the stored elements, and should be avoided.

Implements IAddressableMatrix< T >.

Definition at line 210 of file MappedMatrix.hpp.

void getRow ( int64  row,
T *  values 
) const
virtual

Get a row of the matrix.

values must be preallocated with cols() elements.

This function is in general very slow because it has to iterate through all the stored elements, and should be avoided.

Implements IAddressableMatrix< T >.

Definition at line 182 of file MappedMatrix.hpp.

int8 isResizable ( ) const
virtual

Check if the matrix can be freely resized.

Implements IMatrix< T >.

Definition at line 111 of file MappedMatrix.hpp.

T& 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.

If the element is not already stored in the matrix, it will be inserted with an initial value of zero, increasing the storage size.

Implements IAddressableMatrix< T >.

Definition at line 170 of file MappedMatrix.hpp.

int64 numStoredElements ( ) const
virtual

Get the number of entries actually stored in the matrix.

These are often called "non-zeros", though they may actually have the numeric value 0.

Implements ISparseMatrix< T >.

Definition at line 125 of file MappedMatrix.hpp.

T const& operator() ( Index  row,
Index  col 
) const

Get the element at position (row, col).

If the element is not already stored in the matrix, it will return a zero value.

Definition at line 137 of file MappedMatrix.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< T >.

Definition at line 113 of file MappedMatrix.hpp.

int64 rows ( ) const
virtual

Get the number of rows.

Implements IMatrix< T >.

Definition at line 108 of file MappedMatrix.hpp.

void set ( Index  row,
Index  col,
T const &  value 
)

Set the element at position (row, col).

Definition at line 146 of file MappedMatrix.hpp.

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

Set a column of the matrix.

values must contain rows() elements.

This function compares the elements of values to 0 using the not-equals operator T::operator!=. This may be prone to numerical (floating-point) error.

Implements IAddressableMatrix< T >.

Definition at line 225 of file MappedMatrix.hpp.

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

Set a row of the matrix.

values must contain cols() elements.

This function compares the elements of values to 0 using the not-equals operator T::operator!=. This may be prone to numerical (floating-point) error.

Implements IAddressableMatrix< T >.

Definition at line 197 of file MappedMatrix.hpp.

void setZero ( )
virtual

Set all elements to zero.

Implements IMatrix< T >.

Definition at line 110 of file MappedMatrix.hpp.

TripletConstIterator tripletsBegin ( ) const

Get a read-only iterator pointing to the first (row, col, value) triplet in the matrix.

Definition at line 128 of file MappedMatrix.hpp.

TripletConstIterator tripletsEnd ( ) const

Get a read-only iterator pointing to one past the last (row, col, value) triplet in the matrix.

Definition at line 131 of file MappedMatrix.hpp.


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