Main MRPT website > C++ reference
MRPT logo
List of all members | Public Types | Public Member Functions | Protected Attributes
mrpt::math::CSparseMatrixTemplate< T > Class Template Reference

Detailed Description

template<class T>
class mrpt::math::CSparseMatrixTemplate< T >

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::MatrixBlockSparseCols, 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.

Definition at line 60 of file CSparseMatrixTemplate.h.

#include <mrpt/math/CSparseMatrixTemplate.h>

Inheritance diagram for mrpt::math::CSparseMatrixTemplate< T >:
Inheritance graph
[legend]

Public Types

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

Public Member Functions

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

Protected Attributes

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

Member Typedef Documentation

◆ const_iterator

template<class T>
typedef SparseMatrixMap::const_iterator mrpt::math::CSparseMatrixTemplate< T >::const_iterator

Const iterator to move through the matrix.

See also
CSparseMatrixTemplate::const_reverse_iterator

Definition at line 71 of file CSparseMatrixTemplate.h.

◆ const_reverse_iterator

template<class T>
typedef SparseMatrixMap::const_reverse_iterator mrpt::math::CSparseMatrixTemplate< T >::const_reverse_iterator

Const reverse iterator to move through the matrix.

See also
CSparseMatrixTemplate::const_iterator

Definition at line 76 of file CSparseMatrixTemplate.h.

◆ SparseMatrixMap

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

Internal map type, used to store the actual matrix.

Definition at line 66 of file CSparseMatrixTemplate.h.

Constructor & Destructor Documentation

◆ CSparseMatrixTemplate() [1/2]

template<class T>
mrpt::math::CSparseMatrixTemplate< T >::CSparseMatrixTemplate ( )
inline

Basic constructor with no data.

Size is set to (0,0).

Definition at line 90 of file CSparseMatrixTemplate.h.

◆ CSparseMatrixTemplate() [2/2]

template<class T>
mrpt::math::CSparseMatrixTemplate< T >::CSparseMatrixTemplate ( size_t  nR,
size_t  nC 
)
inline

Constructor with default size.

Definition at line 94 of file CSparseMatrixTemplate.h.

Member Function Documentation

◆ begin()

template<class T>
const_iterator mrpt::math::CSparseMatrixTemplate< T >::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 203 of file CSparseMatrixTemplate.h.

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

◆ clear()

template<class T>
void mrpt::math::CSparseMatrixTemplate< T >::clear ( )
inline

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

Definition at line 343 of file CSparseMatrixTemplate.h.

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

◆ empty()

template<class T>
bool mrpt::math::CSparseMatrixTemplate< T >::empty ( ) const
inline

Are there no elements set to !=0 ?

See also
getNullElements,isNull,isNotNull

Definition at line 314 of file CSparseMatrixTemplate.h.

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

◆ end()

template<class T>
const_iterator mrpt::math::CSparseMatrixTemplate< T >::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 210 of file CSparseMatrixTemplate.h.

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

◆ exists()

template<class T>
bool mrpt::math::CSparseMatrixTemplate< T >::exists ( size_t  r,
size_t  c 
) const
inline

Element access operator.

Checks bounds.

Definition at line 106 of file CSparseMatrixTemplate.h.

◆ getAsVector()

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

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

Definition at line 298 of file CSparseMatrixTemplate.h.

◆ getColCount()

template<class T>
size_t mrpt::math::CSparseMatrixTemplate< T >::getColCount ( ) const
inline

Returns the amount of columns in this matrix.

See also
getRowCount

Definition at line 133 of file CSparseMatrixTemplate.h.

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

◆ getColumn()

template<class T>
void mrpt::math::CSparseMatrixTemplate< T >::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 165 of file CSparseMatrixTemplate.h.

◆ getNonNullElements()

template<class T>
size_t mrpt::math::CSparseMatrixTemplate< T >::getNonNullElements ( ) const
inline

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

See also
getNullElements,isNull,isNotNull

Definition at line 308 of file CSparseMatrixTemplate.h.

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

◆ getNullElements()

template<class T>
size_t mrpt::math::CSparseMatrixTemplate< T >::getNullElements ( ) const
inline

Gets the amount of null elements inside the matrix.

See also
getNonNullElements,isNull,isNotNull

Definition at line 320 of file CSparseMatrixTemplate.h.

◆ getRow()

template<class T>
void mrpt::math::CSparseMatrixTemplate< T >::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 141 of file CSparseMatrixTemplate.h.

◆ getRowCount()

template<class T>
size_t mrpt::math::CSparseMatrixTemplate< T >::getRowCount ( ) const
inline

Returns the amount of rows in this matrix.

See also
getColCount,getRow

Definition at line 126 of file CSparseMatrixTemplate.h.

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

◆ insert()

template<class T>
void mrpt::math::CSparseMatrixTemplate< T >::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 185 of file CSparseMatrixTemplate.h.

◆ insertMatrix()

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

Inserts submatrix at a given location.

Definition at line 191 of file CSparseMatrixTemplate.h.

◆ isNotNull()

template<class T>
bool mrpt::math::CSparseMatrixTemplate< T >::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 336 of file CSparseMatrixTemplate.h.

◆ isNull()

template<class T>
bool mrpt::math::CSparseMatrixTemplate< T >::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 328 of file CSparseMatrixTemplate.h.

◆ operator()() [1/3]

template<class T>
T mrpt::math::CSparseMatrixTemplate< T >::operator() ( size_t  r,
size_t  c 
) const
inline

Element access operator.

Doesn't check bounds.

Definition at line 98 of file CSparseMatrixTemplate.h.

◆ operator()() [2/3]

template<class T>
T& mrpt::math::CSparseMatrixTemplate< T >::operator() ( size_t  r,
size_t  c 
)
inline

Reference access operator.

Checks for bounds.

Definition at line 116 of file CSparseMatrixTemplate.h.

◆ operator()() [3/3]

template<class T>
CSparseMatrixTemplate<T> mrpt::math::CSparseMatrixTemplate< T >::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 283 of file CSparseMatrixTemplate.h.

References begin(), and end().

◆ purge()

template<class T>
void mrpt::math::CSparseMatrixTemplate< T >::purge ( nullObject = T())
inline

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

Definition at line 349 of file CSparseMatrixTemplate.h.

References begin(), and end().

◆ rbegin()

template<class T>
const_reverse_iterator mrpt::math::CSparseMatrixTemplate< T >::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 217 of file CSparseMatrixTemplate.h.

◆ rend()

template<class T>
const_reverse_iterator mrpt::math::CSparseMatrixTemplate< T >::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 224 of file CSparseMatrixTemplate.h.

◆ resize()

template<class T>
void mrpt::math::CSparseMatrixTemplate< T >::resize ( size_t  nRows,
size_t  nCols 
)
inline

Changes the size of the matrix.

Definition at line 266 of file CSparseMatrixTemplate.h.

Referenced by mrpt::math::intersect(), and mrpt::math::CSparseSymmetricalMatrix< T >::resize().

◆ setColumn()

template<class T>
void mrpt::math::CSparseMatrixTemplate< T >::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 250 of file CSparseMatrixTemplate.h.

◆ setRow()

template<class T>
void mrpt::math::CSparseMatrixTemplate< T >::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 232 of file CSparseMatrixTemplate.h.

Member Data Documentation

◆ mColumns

template<class T>
size_t mrpt::math::CSparseMatrixTemplate< T >::mColumns
protected

Definition at line 81 of file CSparseMatrixTemplate.h.

◆ mRows

template<class T>
size_t mrpt::math::CSparseMatrixTemplate< T >::mRows
protected

Size of the matrix.

Definition at line 81 of file CSparseMatrixTemplate.h.

◆ objectList

template<class T>
SparseMatrixMap mrpt::math::CSparseMatrixTemplate< T >::objectList
protected

Actual matrix.

Definition at line 85 of file CSparseMatrixTemplate.h.




Page generated by Doxygen 1.8.14 for MRPT 1.0.2 SVN: at lun oct 28 00:52:41 CET 2019 Hosted on:
SourceForge.net Logo