Classes | Public Types | Public Member Functions | Protected Types | Protected Attributes | Friends

SparseMatrix< _Scalar, _Options, _Index > Class Template Reference

The main sparse matrix class. More...

#include <SparseMatrix.h>

Inheritance diagram for SparseMatrix< _Scalar, _Options, _Index >:
SparseMatrixBase< SparseMatrix< _Scalar, _Options, _Index > > EigenBase< SparseMatrix< _Scalar, _Options, _Index > >

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 ()
Index nonZeros () const
void reserve (Index reserveSize)
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 ()
void prune (Scalar reference, RealScalar epsilon=NumTraits< RealScalar >::dummy_precision())
template<typename KeepFunc >
void prune (const KeepFunc &keep=KeepFunc())
void resize (Index rows, Index cols)
void resizeNonZeros (Index size)
 SparseMatrix ()
 SparseMatrix (Index rows, Index cols)
template<typename OtherDerived >
 SparseMatrix (const SparseMatrixBase< OtherDerived > &other)
 SparseMatrix (const SparseMatrix &other)
void swap (SparseMatrix &other)
SparseMatrixoperator= (const SparseMatrix &other)
template<typename Lhs , typename Rhs >
SparseMatrixoperator= (const SparseSparseProduct< Lhs, Rhs > &product)
template<typename OtherDerived >
SparseMatrixoperator= (const ReturnByValue< OtherDerived > &other)
template<typename OtherDerived >
SparseMatrixoperator= (const EigenBase< OtherDerived > &other)
template<typename OtherDerived >
EIGEN_DONT_INLINE SparseMatrixoperator= (const SparseMatrixBase< OtherDerived > &other)
 ~SparseMatrix ()
Scalar sum () const
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)

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.

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

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

This class can be extended with the help of the plugin mechanism described on the page TopicCustomizingEigen by defining the preprocessor symbol EIGEN_SPARSEMATRIX_PLUGIN.


Member Typedef Documentation

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

Member Enumeration Documentation

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

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

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

Constructs a rows x cols empty matrix

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

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

Copy constructor

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

Destructor


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]
Returns:
the number of columns.
See also:
rows(), ColsAtCompileTime

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

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]
template<typename _Scalar, int _Options, typename _Index>
EIGEN_DEPRECATED void SparseMatrix< _Scalar, _Options, _Index >::endFill (  )  [inline]
Deprecated:
use 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.
template<typename _Scalar, int _Options, typename _Index>
void SparseMatrix< _Scalar, _Options, _Index >::finalize (  )  [inline]

Must be called after inserting a set of non zero entries.

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

template<typename _Scalar, int _Options, typename _Index>
EIGEN_DONT_INLINE Scalar& SparseMatrix< _Scalar, _Options, _Index >::insert ( Index  row,
Index  col 
) [inline]
Returns:
a reference to a novel non zero coefficient with coordinates row x col. The non zero coefficient must not already exist.
Warning:
This function can be extremely slow if the non zero coefficients are not inserted in a coherent order.

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

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
template<typename _Scalar, int _Options, typename _Index>
Scalar& SparseMatrix< _Scalar, _Options, _Index >::insertBackByOuterInner ( Index  outer,
Index  inner 
) [inline]
See also:
insertBack, startVec
template<typename _Scalar, int _Options, typename _Index>
Scalar& SparseMatrix< _Scalar, _Options, _Index >::insertBackByOuterInnerUnordered ( Index  outer,
Index  inner 
) [inline]
Warning:
use it only if you know what you are doing
template<typename _Scalar, int _Options, typename _Index>
Index SparseMatrix< _Scalar, _Options, _Index >::nonZeros (  )  const [inline]
Returns:
the number of non zero coefficients

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

template<typename _Scalar, int _Options, typename _Index>
template<typename OtherDerived >
SparseMatrix& SparseMatrix< _Scalar, _Options, _Index >::operator= ( const ReturnByValue< OtherDerived > &  other  )  [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>
template<typename Lhs , typename Rhs >
SparseMatrix& SparseMatrix< _Scalar, _Options, _Index >::operator= ( const SparseSparseProduct< Lhs, Rhs > &  product  )  [inline]
template<typename _Scalar, int _Options, typename _Index>
template<typename OtherDerived >
SparseMatrix& SparseMatrix< _Scalar, _Options, _Index >::operator= ( const EigenBase< 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 > >.

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

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

Suppress all nonzeros which do not satisfy the predicate keep. The functor type KeepFunc must implement the following function:

 bool operator() (const Index& row, const Index& col, const Scalar& value) const;
See also:
prune(Scalar,RealScalar)
template<typename _Scalar, int _Options, typename _Index>
void SparseMatrix< _Scalar, _Options, _Index >::reserve ( Index  reserveSize  )  [inline]

Preallocates reserveSize non zeros

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

Resizes the matrix to a rows x cols matrix and initializes it to zero

See also:
resizeNonZeros(Index), reserve(), setZero()
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

template<typename _Scalar, int _Options, typename _Index>
Index SparseMatrix< _Scalar, _Options, _Index >::rows ( void   )  const [inline]
Returns:
the number of rows.
See also:
cols(), RowsAtCompileTime

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

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

Removes all non zeros

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:
reserveSize approximate number of nonzeros Note that the matrix *this is zero-ed.
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

Overloaded for performance

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

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

Swap the content of two sparse matrices of same type (optimization)


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]

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]

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