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

SparseMatrix< _Scalar, _Options, _Index > Class Template Reference


Detailed Description

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

The main sparse matrix class.

This class implements a sparse matrix using the very common compressed row/column storage scheme.

Parameters:
_Scalarthe scalar type, i.e. the type of the coefficients
_OptionsUnion of bit flags controlling the storage scheme. Currently the only possibility is RowMajor. The default is 0 which means column-major.
_Indexthe type of the indices. Default is int.

See http://www.netlib.org/linalg/html_templates/node91.html for details on the storage scheme.

Definition at line 67 of file SparseMatrix.h.

#include <src/Sparse/SparseMatrix.h>

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

List of all members.

Classes

struct  default_prunning_func
class  InnerIterator

Public Types

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

Public Member Functions

Index rows () const
Index cols () const
Index innerSize () const
Index outerSize () const
Index innerNonZeros (Index j) const
const Scalar_valuePtr () const
Scalar_valuePtr ()
const Index_innerIndexPtr () const
Index_innerIndexPtr ()
const Index_outerIndexPtr () const
Index_outerIndexPtr ()
Storagedata ()
const Storagedata () const
Scalar coeff (Index row, Index col) const
ScalarcoeffRef (Index row, Index col)
void setZero ()
 Removes all non zeros.
Index nonZeros () const
void reserve (Index reserveSize)
 Preallocates reserveSize non zeros.
ScalarinsertBack (Index row, Index col)
ScalarinsertBackByOuterInner (Index outer, Index inner)
ScalarinsertBackByOuterInnerUnordered (Index outer, Index inner)
void startVec (Index outer)
EIGEN_DONT_INLINE Scalarinsert (Index row, Index col)
void finalize ()
 Must be called after inserting a set of non zero entries.
void prune (Scalar reference, RealScalar epsilon=NumTraits< RealScalar >::dummy_precision())
 Suppress all nonzeros which are smaller than reference under the tolerence epsilon.
template<typename KeepFunc >
void prune (const KeepFunc &keep=KeepFunc())
 Suppress all nonzeros which do not satisfy the predicate keep.
void resize (Index rows, Index cols)
 Resizes the matrix to a rows x cols matrix and initializes it to zero.
void resizeNonZeros (Index size)
 Low level API Resize the nonzero vector to size.
 SparseMatrix ()
 Default constructor yielding an empty 0 x 0 matrix.
 SparseMatrix (Index rows, Index cols)
 Constructs a rows x cols empty matrix.
template<typename OtherDerived >
 SparseMatrix (const SparseMatrixBase< OtherDerived > &other)
 Constructs a sparse matrix from the sparse expression other.
 SparseMatrix (const SparseMatrix &other)
 Copy constructor.
void swap (SparseMatrix &other)
 Swap the content of two sparse matrices of same type (optimization)
SparseMatrixoperator= (const SparseMatrix &other)
template<typename OtherDerived >
EIGEN_DONT_INLINE SparseMatrixoperator= (const SparseMatrixBase< OtherDerived > &other)
 ~SparseMatrix ()
 Destructor.
Scalar sum () const
 Overloaded for performance.
EIGEN_DEPRECATED void startFill (Index reserveSize=1000)
EIGEN_DEPRECATED Scalarfillrand (Index row, Index col)
EIGEN_DEPRECATED Scalarfill (Index row, Index col)
EIGEN_DEPRECATED void endFill ()

Protected Types

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

Protected Attributes

Index m_outerSize
Index m_innerSize
Indexm_outerIndex
CompressedStorage< Scalar, Indexm_data

Friends

std::ostream & operator<< (std::ostream &s, const SparseMatrix &m)

Member Typedef Documentation

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

Definition at line 79 of file SparseMatrix.h.

template<typename _Scalar, int _Options, typename _Index>
typedef CompressedStorage<Scalar,Index> SparseMatrix< _Scalar, _Options, _Index >::Storage

Definition at line 81 of file SparseMatrix.h.

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

Definition at line 88 of file SparseMatrix.h.


Member Enumeration Documentation

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

Definition at line 82 of file SparseMatrix.h.


Constructor & Destructor Documentation

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

Default constructor yielding an empty 0 x 0 matrix.

Definition at line 396 of file SparseMatrix.h.

References SparseMatrix< _Scalar, _Options, _Index >::resize().

template<typename _Scalar, int _Options, typename _Index>
SparseMatrix< _Scalar, _Options, _Index >::SparseMatrix ( Index  rows,
Index  cols 
) [inline]

Constructs a rows x cols empty matrix.

Definition at line 403 of file SparseMatrix.h.

References SparseMatrix< _Scalar, _Options, _Index >::resize().

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

Constructs a sparse matrix from the sparse expression other.

Definition at line 411 of file SparseMatrix.h.

References EigenBase< Derived >::derived().

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

Copy constructor.

Definition at line 418 of file SparseMatrix.h.

References EigenBase< Derived >::derived().

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

Destructor.

Definition at line 541 of file SparseMatrix.h.

References SparseMatrix< _Scalar, _Options, _Index >::m_outerIndex.


Member Function Documentation

template<typename _Scalar, int _Options, typename _Index>
const Index* SparseMatrix< _Scalar, _Options, _Index >::_innerIndexPtr (  ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
Index* SparseMatrix< _Scalar, _Options, _Index >::_innerIndexPtr (  ) [inline]
template<typename _Scalar, int _Options, typename _Index>
const Index* SparseMatrix< _Scalar, _Options, _Index >::_outerIndexPtr (  ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
Index* SparseMatrix< _Scalar, _Options, _Index >::_outerIndexPtr (  ) [inline]
template<typename _Scalar, int _Options, typename _Index>
const Scalar* SparseMatrix< _Scalar, _Options, _Index >::_valuePtr (  ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
Scalar* SparseMatrix< _Scalar, _Options, _Index >::_valuePtr (  ) [inline]
template<typename _Scalar, int _Options, typename _Index>
Scalar SparseMatrix< _Scalar, _Options, _Index >::coeff ( Index  row,
Index  col 
) const [inline]
template<typename _Scalar, int _Options, typename _Index>
Scalar& SparseMatrix< _Scalar, _Options, _Index >::coeffRef ( Index  row,
Index  col 
) [inline]
template<typename _Scalar, int _Options, typename _Index>
Index SparseMatrix< _Scalar, _Options, _Index >::cols ( void   ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
Storage& SparseMatrix< _Scalar, _Options, _Index >::data (  ) [inline]
template<typename _Scalar, int _Options, typename _Index>
const Storage& SparseMatrix< _Scalar, _Options, _Index >::data (  ) const [inline]

Definition at line 114 of file SparseMatrix.h.

References SparseMatrix< _Scalar, _Options, _Index >::m_data.

template<typename _Scalar, int _Options, typename _Index>
EIGEN_DEPRECATED void SparseMatrix< _Scalar, _Options, _Index >::endFill (  ) [inline]
Deprecated:
use finalize

Definition at line 602 of file SparseMatrix.h.

References SparseMatrix< _Scalar, _Options, _Index >::finalize().

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

Definition at line 565 of file SparseMatrix.h.

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

template<typename _Scalar, int _Options, typename _Index>
void SparseMatrix< _Scalar, _Options, _Index >::finalize (  ) [inline]
template<typename _Scalar, int _Options, typename _Index>
Index SparseMatrix< _Scalar, _Options, _Index >::innerNonZeros ( Index  j ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
Index SparseMatrix< _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< SparseMatrix< _Scalar, _Options, _Index > >.

Definition at line 100 of file SparseMatrix.h.

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

template<typename _Scalar, int _Options, typename _Index>
EIGEN_DONT_INLINE Scalar& SparseMatrix< _Scalar, _Options, _Index >::insert ( Index  row,
Index  col 
) [inline]
template<typename _Scalar, int _Options, typename _Index>
Scalar& SparseMatrix< _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 according to the storage order

Before filling a given inner vector you must call the statVec(Index) function.

After an insertion session, you should call the finalize() function.

See also:
insert, insertBackByOuterInner, startVec

Definition at line 168 of file SparseMatrix.h.

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

template<typename _Scalar, int _Options, typename _Index>
Scalar& SparseMatrix< _Scalar, _Options, _Index >::insertBackByOuterInner ( Index  outer,
Index  inner 
) [inline]
template<typename _Scalar, int _Options, typename _Index>
Scalar& SparseMatrix< _Scalar, _Options, _Index >::insertBackByOuterInnerUnordered ( Index  outer,
Index  inner 
) [inline]
template<typename _Scalar, int _Options, typename _Index>
Index SparseMatrix< _Scalar, _Options, _Index >::nonZeros (  ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
template<typename OtherDerived >
EIGEN_DONT_INLINE SparseMatrix& SparseMatrix< _Scalar, _Options, _Index >::operator= ( const SparseMatrixBase< OtherDerived > &  other ) [inline]
template<typename _Scalar, int _Options, typename _Index>
SparseMatrix& SparseMatrix< _Scalar, _Options, _Index >::operator= ( const SparseMatrix< _Scalar, _Options, _Index > &  other ) [inline]
template<typename _Scalar, int _Options, typename _Index>
Index SparseMatrix< _Scalar, _Options, _Index >::outerSize (  ) const [inline]
Returns:
the size of the storage major dimension, i.e., the number of columns for a columns major matrix, and the number of rows otherwise

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

Definition at line 101 of file SparseMatrix.h.

References SparseMatrix< _Scalar, _Options, _Index >::m_outerSize.

Referenced by SparseMatrix< _Scalar, _Options, _Index >::operator=(), SparseMatrix< _Scalar, _Options, _Index >::resize(), and SparseInnerVectorSet< SparseMatrix< _Scalar, _Options, _Index >, Size >::SparseInnerVectorSet().

template<typename _Scalar, int _Options, typename _Index>
void SparseMatrix< _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 336 of file SparseMatrix.h.

template<typename _Scalar, int _Options, typename _Index>
template<typename KeepFunc >
void SparseMatrix< _Scalar, _Options, _Index >::prune ( const KeepFunc &  keep = KeepFunc() ) [inline]
template<typename _Scalar, int _Options, typename _Index>
void SparseMatrix< _Scalar, _Options, _Index >::reserve ( Index  reserveSize ) [inline]

Preallocates reserveSize non zeros.

Definition at line 152 of file SparseMatrix.h.

References SparseMatrix< _Scalar, _Options, _Index >::m_data, and CompressedStorage< _Scalar, _Index >::reserve().

template<typename _Scalar, int _Options, typename _Index>
void SparseMatrix< _Scalar, _Options, _Index >::resize ( Index  rows,
Index  cols 
) [inline]
template<typename _Scalar, int _Options, typename _Index>
void SparseMatrix< _Scalar, _Options, _Index >::resizeNonZeros ( Index  size ) [inline]

Low level API Resize the nonzero vector to size.

Definition at line 390 of file SparseMatrix.h.

References SparseMatrix< _Scalar, _Options, _Index >::m_data, and CompressedStorage< _Scalar, _Index >::resize().

template<typename _Scalar, int _Options, typename _Index>
Index SparseMatrix< _Scalar, _Options, _Index >::rows ( void   ) const [inline]
template<typename _Scalar, int _Options, typename _Index>
void SparseMatrix< _Scalar, _Options, _Index >::setZero (  ) [inline]
template<typename _Scalar, int _Options, typename _Index>
EIGEN_DEPRECATED void SparseMatrix< _Scalar, _Options, _Index >::startFill ( Index  reserveSize = 1000 ) [inline]
Deprecated:
use setZero() and reserve() Initializes the filling process of *this.
Parameters:
reserveSizeapproximate number of nonzeros Note that the matrix *this is zero-ed.

Definition at line 556 of file SparseMatrix.h.

References SparseMatrix< _Scalar, _Options, _Index >::m_data, CompressedStorage< _Scalar, _Index >::reserve(), and SparseMatrix< _Scalar, _Options, _Index >::setZero().

template<typename _Scalar, int _Options, typename _Index>
void SparseMatrix< _Scalar, _Options, _Index >::startVec ( Index  outer ) [inline]
template<typename _Scalar , int _Options, typename _Index >
internal::traits< SparseMatrix< _Scalar, _Options, _Index > >::Scalar SparseMatrix< _Scalar, _Options, _Index >::sum (  ) const
template<typename _Scalar, int _Options, typename _Index>
void SparseMatrix< _Scalar, _Options, _Index >::swap ( SparseMatrix< _Scalar, _Options, _Index > &  other ) [inline]

Friends And Related Function Documentation

template<typename _Scalar, int _Options, typename _Index>
std::ostream& operator<< ( std::ostream &  s,
const SparseMatrix< _Scalar, _Options, _Index > &  m 
) [friend]

Definition at line 518 of file SparseMatrix.h.


Member Data Documentation

template<typename _Scalar, int _Options, typename _Index>
CompressedStorage<Scalar,Index> SparseMatrix< _Scalar, _Options, _Index >::m_data [protected]
template<typename _Scalar, int _Options, typename _Index>
Index SparseMatrix< _Scalar, _Options, _Index >::m_innerSize [protected]
template<typename _Scalar, int _Options, typename _Index>
Index* SparseMatrix< _Scalar, _Options, _Index >::m_outerIndex [protected]
template<typename _Scalar, int _Options, typename _Index>
Index SparseMatrix< _Scalar, _Options, _Index >::m_outerSize [protected]



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