Main MRPT website > C++ reference
MRPT logo
Classes | Public Types | Public Member Functions | Protected Types | Protected Attributes

DynamicSparseMatrix< _Scalar, _Options, _Index > Class Template Reference


Detailed Description

template<typename _Scalar, int _Options, typename _Index>
class DynamicSparseMatrix< _Scalar, _Options, _Index >

A sparse matrix class designed for matrix assembly purpose.

Parameters:
_Scalarthe scalar type, i.e. the type of the coefficients

Unlike SparseMatrix, this class provides a much higher degree of flexibility. In particular, it allows random read/write accesses in log(rho*outer_size) where rho is the probability that a coefficient is nonzero and outer_size is the number of columns if the matrix is column-major and the number of rows otherwise.

Internally, the data are stored as a std::vector of compressed vector. The performances of random writes might decrease as the number of nonzeros per inner-vector increase. In practice, we observed very good performance till about 100 nonzeros/vector, and the performance remains relatively good till 500 nonzeros/vectors.

See also:
SparseMatrix

Definition at line 67 of file DynamicSparseMatrix.h.

#include <src/Sparse/DynamicSparseMatrix.h>

Inheritance diagram for DynamicSparseMatrix< _Scalar, _Options, _Index >:
Inheritance graph
[legend]

List of all members.

Classes

class  InnerIterator

Public Types

enum  { Options = _Options }
typedef MappedSparseMatrix
< Scalar, Flags > 
Map

Public Member Functions

Index rows () const
Index cols () const
Index innerSize () const
Index outerSize () const
Index innerNonZeros (Index j) const
std::vector< CompressedStorage
< Scalar, Index > > & 
_data ()
const std::vector
< CompressedStorage< Scalar,
Index > > & 
_data () const
Scalar coeff (Index row, Index col) const
ScalarcoeffRef (Index row, Index col)
void setZero ()
Index nonZeros () const
void reserve (Index reserveSize=1000)
void startVec (Index)
 Does nothing: provided for compatibility with SparseMatrix.
ScalarinsertBack (Index row, Index col)
ScalarinsertBackByOuterInner (Index outer, Index inner)
Scalarinsert (Index row, Index col)
void finalize ()
 Does nothing: provided for compatibility with SparseMatrix.
void prune (Scalar reference, RealScalar epsilon=NumTraits< RealScalar >::dummy_precision())
 Suppress all nonzeros which are smaller than reference under the tolerence epsilon.
void resize (Index rows, Index cols)
 Resize the matrix without preserving the data (the matrix is set to zero)
void resizeAndKeepData (Index rows, Index cols)
 DynamicSparseMatrix ()
 DynamicSparseMatrix (Index rows, Index cols)
template<typename OtherDerived >
 DynamicSparseMatrix (const SparseMatrixBase< OtherDerived > &other)
 DynamicSparseMatrix (const DynamicSparseMatrix &other)
void swap (DynamicSparseMatrix &other)
DynamicSparseMatrixoperator= (const DynamicSparseMatrix &other)
template<typename OtherDerived >
DynamicSparseMatrixoperator= (const SparseMatrixBase< OtherDerived > &other)
template<typename OtherDerived >
EIGEN_STRONG_INLINE
DynamicSparseMatrix
operator= (const ReturnByValue< OtherDerived > &func)
 ~DynamicSparseMatrix ()
 Destructor.
EIGEN_DEPRECATED void startFill (Index reserveSize=1000)
EIGEN_DEPRECATED Scalarfill (Index row, Index col)
EIGEN_DEPRECATED Scalarfillrand (Index row, Index col)
EIGEN_DEPRECATED void endFill ()

Protected Types

typedef DynamicSparseMatrix
< Scalar,(Flags &~RowMajorBit)|(IsRowMajor?RowMajorBit:0)> 
TransposedSparseMatrix

Protected Attributes

Index m_innerSize
std::vector< CompressedStorage
< Scalar, Index > > 
m_data

Member Typedef Documentation

template<typename _Scalar, int _Options, typename _Index>
typedef MappedSparseMatrix<Scalar,Flags> DynamicSparseMatrix< _Scalar, _Options, _Index >::Map

Definition at line 75 of file DynamicSparseMatrix.h.

template<typename _Scalar, int _Options, typename _Index>
typedef DynamicSparseMatrix<Scalar,(Flags&~RowMajorBit)|(IsRowMajor?RowMajorBit:0)> DynamicSparseMatrix< _Scalar, _Options, _Index >::TransposedSparseMatrix [protected]

Definition at line 84 of file DynamicSparseMatrix.h.


Member Enumeration Documentation

template<typename _Scalar, int _Options, typename _Index>
anonymous enum
Enumerator:
Options 

Definition at line 78 of file DynamicSparseMatrix.h.


Constructor & Destructor Documentation

template<typename _Scalar, int _Options, typename _Index>
DynamicSparseMatrix< _Scalar, _Options, _Index >::DynamicSparseMatrix (  ) [inline]
template<typename _Scalar, int _Options, typename _Index>
DynamicSparseMatrix< _Scalar, _Options, _Index >::DynamicSparseMatrix ( Index  rows,
Index  cols 
) [inline]
template<typename _Scalar, int _Options, typename _Index>
template<typename OtherDerived >
DynamicSparseMatrix< _Scalar, _Options, _Index >::DynamicSparseMatrix ( const SparseMatrixBase< OtherDerived > &  other ) [inline]

Definition at line 248 of file DynamicSparseMatrix.h.

References EigenBase< Derived >::derived().

template<typename _Scalar, int _Options, typename _Index>
DynamicSparseMatrix< _Scalar, _Options, _Index >::DynamicSparseMatrix ( const DynamicSparseMatrix< _Scalar, _Options, _Index > &  other ) [inline]

Definition at line 254 of file DynamicSparseMatrix.h.

References EigenBase< Derived >::derived().

template<typename _Scalar, int _Options, typename _Index>
DynamicSparseMatrix< _Scalar, _Options, _Index >::~DynamicSparseMatrix (  ) [inline]

Destructor.

Definition at line 295 of file DynamicSparseMatrix.h.


Member Function Documentation

template<typename _Scalar, int _Options, typename _Index>
std::vector<CompressedStorage<Scalar,Index> >& DynamicSparseMatrix< _Scalar, _Options, _Index >::_data (  ) [inline]
template<typename _Scalar, int _Options, typename _Index>
const std::vector<CompressedStorage<Scalar,Index> >& DynamicSparseMatrix< _Scalar, _Options, _Index >::_data (  ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
Scalar DynamicSparseMatrix< _Scalar, _Options, _Index >::coeff ( Index  row,
Index  col 
) const [inline]
template<typename _Scalar, int _Options, typename _Index>
Scalar& DynamicSparseMatrix< _Scalar, _Options, _Index >::coeffRef ( Index  row,
Index  col 
) [inline]
Returns:
a reference to the coefficient value at given position row, col This operation involes a log(rho*outer_size) binary search. If the coefficient does not exist yet, then a sorted insertion into a sequential buffer is performed.

Definition at line 114 of file DynamicSparseMatrix.h.

References SparseMatrixBase< DynamicSparseMatrix< _Scalar, _Options, _Index > >::col(), SparseMatrixBase< DynamicSparseMatrix< _Scalar, _Options, _Index > >::IsRowMajor, DynamicSparseMatrix< _Scalar, _Options, _Index >::m_data, and SparseMatrixBase< DynamicSparseMatrix< _Scalar, _Options, _Index > >::row().

template<typename _Scalar, int _Options, typename _Index>
Index DynamicSparseMatrix< _Scalar, _Options, _Index >::cols ( void   ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
EIGEN_DEPRECATED void DynamicSparseMatrix< _Scalar, _Options, _Index >::endFill (  ) [inline]
Deprecated:
use finalize() Does nothing.

Provided for compatibility with SparseMatrix.

Definition at line 335 of file DynamicSparseMatrix.h.

template<typename _Scalar, int _Options, typename _Index>
EIGEN_DEPRECATED Scalar& DynamicSparseMatrix< _Scalar, _Options, _Index >::fill ( Index  row,
Index  col 
) [inline]
Deprecated:
use insert() inserts a nonzero coefficient at given coordinates row, col and returns its reference assuming that: 1 - the coefficient does not exist yet 2 - this the coefficient with greater inner coordinate for the given outer coordinate.

In other words, assuming *this is column-major, then there must not exists any nonzero coefficient of coordinates i x col such that i >= row. Otherwise the matrix is invalid.

See also:
fillrand(), coeffRef()

Definition at line 316 of file DynamicSparseMatrix.h.

References SparseMatrixBase< DynamicSparseMatrix< _Scalar, _Options, _Index > >::col(), DynamicSparseMatrix< _Scalar, _Options, _Index >::insertBack(), SparseMatrixBase< DynamicSparseMatrix< _Scalar, _Options, _Index > >::IsRowMajor, and SparseMatrixBase< DynamicSparseMatrix< _Scalar, _Options, _Index > >::row().

template<typename _Scalar, int _Options, typename _Index>
EIGEN_DEPRECATED Scalar& DynamicSparseMatrix< _Scalar, _Options, _Index >::fillrand ( Index  row,
Index  col 
) [inline]
Deprecated:
use insert() Like fill() but with random inner coordinates.

Compared to the generic coeffRef(), the unique limitation is that we assume the coefficient does not exist yet.

Definition at line 328 of file DynamicSparseMatrix.h.

References DynamicSparseMatrix< _Scalar, _Options, _Index >::insert().

template<typename _Scalar, int _Options, typename _Index>
void DynamicSparseMatrix< _Scalar, _Options, _Index >::finalize (  ) [inline]

Does nothing: provided for compatibility with SparseMatrix.

Definition at line 196 of file DynamicSparseMatrix.h.

template<typename _Scalar, int _Options, typename _Index>
Index DynamicSparseMatrix< _Scalar, _Options, _Index >::innerNonZeros ( Index  j ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
Index DynamicSparseMatrix< _Scalar, _Options, _Index >::innerSize (  ) const [inline]
Returns:
the size of the inner dimension according to the storage order, i.e., the number of rows for a columns major matrix, and the number of cols otherwise

Reimplemented from SparseMatrixBase< DynamicSparseMatrix< _Scalar, _Options, _Index > >.

Definition at line 93 of file DynamicSparseMatrix.h.

References DynamicSparseMatrix< _Scalar, _Options, _Index >::m_innerSize.

Referenced by DynamicSparseMatrix< _Scalar, _Options, _Index >::DynamicSparseMatrix(), and DynamicSparseMatrix< _Scalar, _Options, _Index >::resizeAndKeepData().

template<typename _Scalar, int _Options, typename _Index>
Scalar& DynamicSparseMatrix< _Scalar, _Options, _Index >::insert ( Index  row,
Index  col 
) [inline]
template<typename _Scalar, int _Options, typename _Index>
Scalar& DynamicSparseMatrix< _Scalar, _Options, _Index >::insertBack ( Index  row,
Index  col 
) [inline]
Returns:
a reference to the non zero coefficient at position row, col assuming that:
  • the nonzero does not already exist
  • the new coefficient is the last one of the given inner vector.
See also:
insert, insertBackByOuterInner

Definition at line 160 of file DynamicSparseMatrix.h.

References DynamicSparseMatrix< _Scalar, _Options, _Index >::insertBackByOuterInner(), and SparseMatrixBase< DynamicSparseMatrix< _Scalar, _Options, _Index > >::IsRowMajor.

Referenced by DynamicSparseMatrix< _Scalar, _Options, _Index >::fill().

template<typename _Scalar, int _Options, typename _Index>
Scalar& DynamicSparseMatrix< _Scalar, _Options, _Index >::insertBackByOuterInner ( Index  outer,
Index  inner 
) [inline]
template<typename _Scalar, int _Options, typename _Index>
Index DynamicSparseMatrix< _Scalar, _Options, _Index >::nonZeros (  ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
DynamicSparseMatrix& DynamicSparseMatrix< _Scalar, _Options, _Index >::operator= ( const DynamicSparseMatrix< _Scalar, _Options, _Index > &  other ) [inline]
template<typename _Scalar, int _Options, typename _Index>
template<typename OtherDerived >
DynamicSparseMatrix& DynamicSparseMatrix< _Scalar, _Options, _Index >::operator= ( const SparseMatrixBase< OtherDerived > &  other ) [inline]
template<typename _Scalar, int _Options, typename _Index>
template<typename OtherDerived >
EIGEN_STRONG_INLINE DynamicSparseMatrix& DynamicSparseMatrix< _Scalar, _Options, _Index >::operator= ( const ReturnByValue< OtherDerived > &  func ) [inline]
template<typename _Scalar, int _Options, typename _Index>
Index DynamicSparseMatrix< _Scalar, _Options, _Index >::outerSize (  ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
void DynamicSparseMatrix< _Scalar, _Options, _Index >::prune ( Scalar  reference,
RealScalar  epsilon = NumTraits<RealScalar>::dummy_precision() 
) [inline]

Suppress all nonzeros which are smaller than reference under the tolerence epsilon.

Definition at line 199 of file DynamicSparseMatrix.h.

References DynamicSparseMatrix< _Scalar, _Options, _Index >::m_data, and DynamicSparseMatrix< _Scalar, _Options, _Index >::outerSize().

template<typename _Scalar, int _Options, typename _Index>
void DynamicSparseMatrix< _Scalar, _Options, _Index >::reserve ( Index  reserveSize = 1000 ) [inline]
template<typename _Scalar, int _Options, typename _Index>
void DynamicSparseMatrix< _Scalar, _Options, _Index >::resize ( Index  rows,
Index  cols 
) [inline]
template<typename _Scalar, int _Options, typename _Index>
void DynamicSparseMatrix< _Scalar, _Options, _Index >::resizeAndKeepData ( Index  rows,
Index  cols 
) [inline]
template<typename _Scalar, int _Options, typename _Index>
Index DynamicSparseMatrix< _Scalar, _Options, _Index >::rows ( void   ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
void DynamicSparseMatrix< _Scalar, _Options, _Index >::setZero (  ) [inline]
template<typename _Scalar, int _Options, typename _Index>
EIGEN_DEPRECATED void DynamicSparseMatrix< _Scalar, _Options, _Index >::startFill ( Index  reserveSize = 1000 ) [inline]
Deprecated:
Set the matrix to zero and reserve the memory for reserveSize nonzero coefficients.

Definition at line 301 of file DynamicSparseMatrix.h.

References DynamicSparseMatrix< _Scalar, _Options, _Index >::reserve(), and DynamicSparseMatrix< _Scalar, _Options, _Index >::setZero().

template<typename _Scalar, int _Options, typename _Index>
void DynamicSparseMatrix< _Scalar, _Options, _Index >::startVec ( Index   ) [inline]

Does nothing: provided for compatibility with SparseMatrix.

Definition at line 153 of file DynamicSparseMatrix.h.

template<typename _Scalar, int _Options, typename _Index>
void DynamicSparseMatrix< _Scalar, _Options, _Index >::swap ( DynamicSparseMatrix< _Scalar, _Options, _Index > &  other ) [inline]

Member Data Documentation

template<typename _Scalar, int _Options, typename _Index>
std::vector<CompressedStorage<Scalar,Index> > DynamicSparseMatrix< _Scalar, _Options, _Index >::m_data [protected]
template<typename _Scalar, int _Options, typename _Index>
Index DynamicSparseMatrix< _Scalar, _Options, _Index >::m_innerSize [protected]



Page generated by Doxygen 1.7.2 for MRPT 0.9.4 SVN: at Mon Jan 10 22:30:30 UTC 2011