Main MRPT website > C++ reference
MRPT logo
Public Types | Public Member Functions | Protected Attributes
mrpt::math::CSparseMatrixTemplate Class Reference

Detailed Description

A sparse matrix container (with cells of any type), with iterators.

This class stores only those elements created by assigning them a value, for example: "M(2,3)=8;".

This class doesn't implement math operations since it's a generic sparse container, but it can be used to initialize the contents of a CSparse library-based matrix of type mrpt::math::CSparseMatrix.

Note that reading non-existing cell elements will return the default value (0 for numbers) and that cell will remain non-created in the matrix.

There is an additional method "exists(i,j)" to check whether a given element exists in the matrix.

See also:
mrpt::math::CSparseMatrix, CSparseSymmetricalMatrix
Note:
Methods marked as "Doesn't check bounds" mean that if an access to an element out of the matrix size is tried, an empty element will be assumed, but this will not raise any invalid memory access.

#include <mrpt/math/CSparseMatrixTemplate.h>

Inheritance diagram for mrpt::math::CSparseMatrixTemplate:
Inheritance graph
[legend]

List of all members.

Public Types

typedef std::map< std::pair
< size_t, size_t >, T > 
SparseMatrixMap
 Internal map type, used to store the actual matrix.
typedef
SparseMatrixMap::const_iterator 
const_iterator
 Const iterator to move through the matrix.
typedef
SparseMatrixMap::const_reverse_iterator 
const_reverse_iterator
 Const reverse iterator to move through the matrix.

Public Member Functions

 CSparseMatrixTemplate ()
 Basic constructor with no data.
 CSparseMatrixTemplate (size_t nR, size_t nC)
 Constructor with default size.
operator() (size_t r, size_t c) const
 Element access operator.
bool exists (size_t r, size_t c) const
 Element access operator.
T & operator() (size_t r, size_t c)
 Reference access operator.
size_t getRowCount () const
 Returns the amount of rows in this matrix.
size_t getColCount () const
 Returns the amount of columns in this matrix.
void getRow (size_t nRow, std::vector< T > &vec) const
 Extracts a full row from the matrix.
void getColumn (size_t nCol, std::vector< T > &vec) const
 Extracts a full column from the matrix.
void insert (size_t row, size_t column, const T &obj)
 Inserts an element into the matrix.
template<class MATRIX_LIKE >
void insertMatrix (size_t row, size_t column, const MATRIX_LIKE &mat)
 Inserts submatrix at a given location.
const_iterator begin () const
 Returns an iterator which points to the starting point of the matrix.
const_iterator end () const
 Returns an iterator which points to the end of the matrix.
const_reverse_iterator rbegin () const
 Returns an iterator which points to the end of the matrix, and can be used to move backwards.
const_reverse_iterator rend () const
 Returns an iterator which points to the starting point of the matrix, although it's the upper limit of the matrix since it's a reverse iterator.
void setRow (size_t nRow, const std::vector< T > &vec, const T &nullObject=T())
 Inserts a full row into the matrix.
void setColumn (size_t nCol, const std::vector< T > &vec, const T &nullObject=T())
 Inserts a full column into the matrix.
void resize (size_t nRows, size_t nCols)
 Changes the size of the matrix.
CSparseMatrixTemplate< T > operator() (size_t firstRow, size_t lastRow, size_t firstColumn, size_t lastColumn) const
 Extracts a submatrix form the matrix.
void getAsVector (std::vector< T > &vec) const
 Gets a vector containing all the elements of the matrix, ignoring their position.
size_t getNonNullElements () const
 Gets the amount of non-null elements inside the matrix.
bool empty () const
 Are there no elements set to !=0 ?
size_t getNullElements () const
 Gets the amount of null elements inside the matrix.
bool isNull (size_t nRow, size_t nCol) const
 Checks whether an element of the matrix is the default object.
bool isNotNull (size_t nRow, size_t nCol) const
 Checks whether an element of the matrix is not the default object.
void clear ()
 Completely removes all elements, although maintaining the matrix's size.
void purge (T nullObject=T())
 Checks each non-null elements against the basic objects, erasing unnecesary references to it.

Protected Attributes

size_t mRows
 Size of the matrix.
size_t mColumns
SparseMatrixMap objectList
 Actual matrix.

Member Typedef Documentation

Const iterator to move through the matrix.

See also:
CSparseMatrixTemplate::const_reverse_iterator

Definition at line 64 of file CSparseMatrixTemplate.h.

typedef SparseMatrixMap::const_reverse_iterator mrpt::math::CSparseMatrixTemplate::const_reverse_iterator

Const reverse iterator to move through the matrix.

See also:
CSparseMatrixTemplate::const_iterator

Definition at line 69 of file CSparseMatrixTemplate.h.

typedef std::map<std::pair<size_t,size_t>,T> mrpt::math::CSparseMatrixTemplate::SparseMatrixMap

Internal map type, used to store the actual matrix.

Definition at line 59 of file CSparseMatrixTemplate.h.


Constructor & Destructor Documentation

mrpt::math::CSparseMatrixTemplate::CSparseMatrixTemplate ( ) [inline]

Basic constructor with no data.

Size is set to (0,0).

Definition at line 83 of file CSparseMatrixTemplate.h.

mrpt::math::CSparseMatrixTemplate::CSparseMatrixTemplate ( size_t  nR,
size_t  nC 
) [inline]

Constructor with default size.

Definition at line 87 of file CSparseMatrixTemplate.h.


Member Function Documentation

const_iterator mrpt::math::CSparseMatrixTemplate::begin ( ) const [inline]

Returns an iterator which points to the starting point of the matrix.

It's a const_iterator, so that the usar isn't able to modify the matrix content into an invalid state.

See also:
end,rbegin,rend

Definition at line 196 of file CSparseMatrixTemplate.h.

Referenced by mrpt::math::CSparseMatrix::CSparseMatrix().

void mrpt::math::CSparseMatrixTemplate::clear ( ) [inline]

Completely removes all elements, although maintaining the matrix's size.

Definition at line 336 of file CSparseMatrixTemplate.h.

Referenced by mrpt::math::intersect().

bool mrpt::math::CSparseMatrixTemplate::empty ( ) const [inline]

Are there no elements set to !=0 ?

See also:
getNullElements,isNull,isNotNull

Definition at line 307 of file CSparseMatrixTemplate.h.

Referenced by mrpt::math::CSparseMatrix::CSparseMatrix().

const_iterator mrpt::math::CSparseMatrixTemplate::end ( ) const [inline]

Returns an iterator which points to the end of the matrix.

It's a const_iterator, so that the usar isn't able to modify the matrix content into an invalid state.

See also:
begin,rbegin,rend

Definition at line 203 of file CSparseMatrixTemplate.h.

Referenced by mrpt::math::CSparseMatrix::CSparseMatrix().

bool mrpt::math::CSparseMatrixTemplate::exists ( size_t  r,
size_t  c 
) const [inline]

Element access operator.

Checks bounds.

Definition at line 99 of file CSparseMatrixTemplate.h.

void mrpt::math::CSparseMatrixTemplate::getAsVector ( std::vector< T > &  vec) const [inline]

Gets a vector containing all the elements of the matrix, ignoring their position.

Definition at line 291 of file CSparseMatrixTemplate.h.

size_t mrpt::math::CSparseMatrixTemplate::getColCount ( ) const [inline]

Returns the amount of columns in this matrix.

See also:
getRowCount

Definition at line 126 of file CSparseMatrixTemplate.h.

Referenced by mrpt::math::CSparseMatrix::CSparseMatrix().

void mrpt::math::CSparseMatrixTemplate::getColumn ( size_t  nCol,
std::vector< T > &  vec 
) const [inline]

Extracts a full column from the matrix.

See also:
getColCount,getRow,setColumn
Exceptions:
std::logic_erroron out of range.

Definition at line 158 of file CSparseMatrixTemplate.h.

size_t mrpt::math::CSparseMatrixTemplate::getNonNullElements ( ) const [inline]

Gets the amount of non-null elements inside the matrix.

See also:
getNullElements,isNull,isNotNull

Definition at line 301 of file CSparseMatrixTemplate.h.

Referenced by mrpt::math::intersect().

size_t mrpt::math::CSparseMatrixTemplate::getNullElements ( ) const [inline]

Gets the amount of null elements inside the matrix.

See also:
getNonNullElements,isNull,isNotNull

Definition at line 313 of file CSparseMatrixTemplate.h.

void mrpt::math::CSparseMatrixTemplate::getRow ( size_t  nRow,
std::vector< T > &  vec 
) const [inline]

Extracts a full row from the matrix.

See also:
getRowCount,getColumn,setRow
Exceptions:
std::logic_erroron out of range.

Definition at line 134 of file CSparseMatrixTemplate.h.

size_t mrpt::math::CSparseMatrixTemplate::getRowCount ( ) const [inline]

Returns the amount of rows in this matrix.

See also:
getColCount,getRow

Definition at line 119 of file CSparseMatrixTemplate.h.

Referenced by mrpt::math::CSparseMatrix::CSparseMatrix().

void mrpt::math::CSparseMatrixTemplate::insert ( size_t  row,
size_t  column,
const T &  obj 
) [inline]

Inserts an element into the matrix.

See also:
operator()(size_t,size_t)

Definition at line 178 of file CSparseMatrixTemplate.h.

template<class MATRIX_LIKE >
void mrpt::math::CSparseMatrixTemplate::insertMatrix ( size_t  row,
size_t  column,
const MATRIX_LIKE &  mat 
) [inline]

Inserts submatrix at a given location.

Definition at line 184 of file CSparseMatrixTemplate.h.

bool mrpt::math::CSparseMatrixTemplate::isNotNull ( size_t  nRow,
size_t  nCol 
) const [inline]

Checks whether an element of the matrix is not the default object.

See also:
getNonNullElements,getNullElements,isNull

Definition at line 329 of file CSparseMatrixTemplate.h.

bool mrpt::math::CSparseMatrixTemplate::isNull ( size_t  nRow,
size_t  nCol 
) const [inline]

Checks whether an element of the matrix is the default object.

See also:
getNonNullElements,getNullElements,isNotNull
Exceptions:
std::logic_erroron out of range

Definition at line 321 of file CSparseMatrixTemplate.h.

T mrpt::math::CSparseMatrixTemplate::operator() ( size_t  r,
size_t  c 
) const [inline]

Element access operator.

Doesn't check bounds.

Reimplemented in mrpt::math::CSparseSymmetricalMatrix.

Definition at line 91 of file CSparseMatrixTemplate.h.

T& mrpt::math::CSparseMatrixTemplate::operator() ( size_t  r,
size_t  c 
) [inline]

Reference access operator.

Checks for bounds.

Reimplemented in mrpt::math::CSparseSymmetricalMatrix.

Definition at line 109 of file CSparseMatrixTemplate.h.

CSparseMatrixTemplate<T> mrpt::math::CSparseMatrixTemplate::operator() ( size_t  firstRow,
size_t  lastRow,
size_t  firstColumn,
size_t  lastColumn 
) const [inline]

Extracts a submatrix form the matrix.

See also:
operator()(size_t,size_t)
Exceptions:
std::logic_erroron invalid bounds.

Definition at line 276 of file CSparseMatrixTemplate.h.

void mrpt::math::CSparseMatrixTemplate::purge ( nullObject = T()) [inline]

Checks each non-null elements against the basic objects, erasing unnecesary references to it.

Definition at line 342 of file CSparseMatrixTemplate.h.

const_reverse_iterator mrpt::math::CSparseMatrixTemplate::rbegin ( ) const [inline]

Returns an iterator which points to the end of the matrix, and can be used to move backwards.

It's a const_reverse_iterator, so that the usar isn't able to modify the matrix content into an invalid state.

See also:
begin,end,rend

Definition at line 210 of file CSparseMatrixTemplate.h.

const_reverse_iterator mrpt::math::CSparseMatrixTemplate::rend ( ) const [inline]

Returns an iterator which points to the starting point of the matrix, although it's the upper limit of the matrix since it's a reverse iterator.

Also, it's a const_reverse_iterator, so that the usar isn't able to modify the matrix content into an invalid state.

See also:
begin,end,rbegin

Definition at line 217 of file CSparseMatrixTemplate.h.

void mrpt::math::CSparseMatrixTemplate::resize ( size_t  nRows,
size_t  nCols 
) [inline]

Changes the size of the matrix.

Definition at line 259 of file CSparseMatrixTemplate.h.

Referenced by mrpt::math::intersect().

void mrpt::math::CSparseMatrixTemplate::setColumn ( size_t  nCol,
const std::vector< T > &  vec,
const T &  nullObject = T() 
) [inline]

Inserts a full column into the matrix.

The third argument is used to specify a null object (which won't be inserted, since the matrix is sparse).

See also:
getColumn
Exceptions:
std::logic_erroron out of range or wrong sized vector.

Definition at line 243 of file CSparseMatrixTemplate.h.

void mrpt::math::CSparseMatrixTemplate::setRow ( size_t  nRow,
const std::vector< T > &  vec,
const T &  nullObject = T() 
) [inline]

Inserts a full row into the matrix.

The third argument is used to specify a null object (which won't be inserted, since the matrix is sparse).

See also:
getRow
Exceptions:
std::logic_erroron out of range or wrong sized vector.

Definition at line 225 of file CSparseMatrixTemplate.h.


Member Data Documentation

Definition at line 74 of file CSparseMatrixTemplate.h.

Size of the matrix.

Definition at line 74 of file CSparseMatrixTemplate.h.

Actual matrix.

Definition at line 78 of file CSparseMatrixTemplate.h.




Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011