Medial Code Documentation
Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends
Eigen::SparseMatrix< _Scalar, _Options, _Index > Class Template Reference

A versatible sparse matrix representation. More...

#include <SparseMatrix.h>

Inheritance diagram for Eigen::SparseMatrix< _Scalar, _Options, _Index >:
Eigen::SparseCompressedBase< SparseMatrix< _Scalar, _Options, _Index > > Eigen::SparseMatrixBase< Derived > Eigen::internal::special_scalar_op_base< Derived, internal::traits< Derived >::Scalar, NumTraits< internal::traits< Derived >::Scalar >::Real, EigenBase< Derived > > Eigen::EigenBase< Derived >

Data Structures

class  SingletonVector
 

Public Types

enum  { Options = _Options }
 
typedef MappedSparseMatrix< Scalar, FlagsMap
 
typedef Diagonal< SparseMatrixDiagonalReturnType
 
typedef Diagonal< const SparseMatrixConstDiagonalReturnType
 
typedef Base::InnerIterator InnerIterator
 
typedef Base::ReverseInnerIterator ReverseInnerIterator
 
typedef internal::CompressedStorage< Scalar, StorageIndex > Storage
 
typedef Base::IndexVector IndexVector
 
typedef Base::ScalarVector ScalarVector
 
- Public Types inherited from Eigen::SparseCompressedBase< SparseMatrix< _Scalar, _Options, _Index > >
typedef SparseMatrixBase< SparseMatrix< _Scalar, _Options, _Index > > Base
 
- Public Types inherited from Eigen::SparseMatrixBase< Derived >
enum  {
  RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime , ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime , SizeAtCompileTime , MaxRowsAtCompileTime = RowsAtCompileTime ,
  MaxColsAtCompileTime = ColsAtCompileTime , MaxSizeAtCompileTime , IsVectorAtCompileTime = RowsAtCompileTime == 1 || ColsAtCompileTime == 1 , Flags = internal::traits<Derived>::Flags ,
  IsRowMajor = Flags&RowMajorBit ? 1 : 0 , InnerSizeAtCompileTime , _HasDirectAccess = (int(Flags)&DirectAccessBit) ? 1 : 0
}
 
typedef internal::traits< Derived >::Scalar Scalar
 
typedef Scalar value_type
 The numeric type of the expression' coefficients, e.g.
 
typedef internal::packet_traits< Scalar >::type PacketScalar
 
typedef internal::traits< Derived >::StorageKind StorageKind
 
typedef internal::traits< Derived >::StorageIndex StorageIndex
 
typedef internal::add_const_on_value_type_if_arithmetic< typenameinternal::packet_traits< Scalar >::type >::type PacketReturnType
 
typedef SparseMatrixBase StorageBaseType
 
typedef Matrix< StorageIndex, Dynamic, 1 > IndexVector
 
typedef Matrix< Scalar, Dynamic, 1 > ScalarVector
 
typedef internal::conditional< NumTraits< Scalar >::IsComplex, CwiseUnaryOp< internal::scalar_conjugate_op< Scalar >, Eigen::Transpose< constDerived > >, Transpose< constDerived > >::type AdjointReturnType
 
typedef Transpose< Derived > TransposeReturnType
 
typedef internal::add_const< Transpose< constDerived > >::type ConstTransposeReturnType
 
typedef SparseMatrix< Scalar, Flags &RowMajorBit ? RowMajor :ColMajor, StorageIndex > PlainObject
 
typedef NumTraits< Scalar >::Real RealScalar
 This is the "real scalar" type; if the Scalar type is already real numbers (e.g.
 
typedef internal::conditional< _HasDirectAccess, constScalar &, Scalar >::type CoeffReturnType
 
typedef CwiseNullaryOp< internal::scalar_constant_op< Scalar >, Matrix< Scalar, Dynamic, Dynamic > > ConstantReturnType
 
typedef Matrix< Scalar, RowsAtCompileTime, ColsAtCompileTimeDenseMatrixType
 type of the equivalent dense matrix
 
typedef Matrix< Scalar, EIGEN_SIZE_MAX(RowsAtCompileTime, ColsAtCompileTime), EIGEN_SIZE_MAX(RowsAtCompileTime, ColsAtCompileTime)> SquareMatrixType
 type of the equivalent square matrix
 
typedef internal::special_scalar_op_base< Derived, Scalar, RealScalar, EigenBase< Derived > > Base
 
typedef Block< Derived, IsRowMajor?1:Dynamic, IsRowMajor?Dynamic:1, trueInnerVectorReturnType
 
typedef Block< const Derived, IsRowMajor?1:Dynamic, IsRowMajor?Dynamic:1, trueConstInnerVectorReturnType
 
typedef Block< Derived, Dynamic, Dynamic, trueInnerVectorsReturnType
 
typedef Block< const Derived, Dynamic, Dynamic, trueConstInnerVectorsReturnType
 
- Public Types inherited from Eigen::EigenBase< Derived >
typedef Eigen::Index Index
 The interface type of indices.
 
typedef internal::traits< Derived >::StorageKind StorageKind
 

Public Member Functions

Index rows () const
 
Index cols () const
 
Index innerSize () const
 
Index outerSize () const
 
const Scalar * valuePtr () const
 
Scalar * valuePtr ()
 
const StorageIndex * innerIndexPtr () const
 
StorageIndex * innerIndexPtr ()
 
const StorageIndex * outerIndexPtr () const
 
StorageIndex * outerIndexPtr ()
 
const StorageIndex * innerNonZeroPtr () const
 
StorageIndex * innerNonZeroPtr ()
 
Storagedata ()
 
const Storagedata () const
 
Scalar coeff (Index row, Index col) const
 
Scalar & coeffRef (Index row, Index col)
 
Scalar & insert (Index row, Index col)
 
void setZero ()
 Removes all non zeros but keep allocated memory.
 
void reserve (Index reserveSize)
 Preallocates reserveSize non zeros.
 
template<class SizesType >
void reserve (const SizesType &reserveSizes, const typename SizesType::value_type &enableif=typename SizesType::value_type())
 
Scalar & insertBack (Index row, Index col)
 
Scalar & insertBackByOuterInner (Index outer, Index inner)
 
Scalar & insertBackByOuterInnerUnordered (Index outer, Index inner)
 
void startVec (Index outer)
 
void finalize ()
 
template<typename InputIterators >
void setFromTriplets (const InputIterators &begin, const InputIterators &end)
 Fill the matrix *this with the list of triplets defined by the iterator range begin - end.
 
template<typename InputIterators , typename DupFunctor >
void setFromTriplets (const InputIterators &begin, const InputIterators &end, DupFunctor dup_func)
 The same as setFromTriplets but when duplicates are met the functor dup_func is applied:
 
void sumupDuplicates ()
 
template<typename DupFunctor >
void collapseDuplicates (DupFunctor dup_func=DupFunctor())
 
Scalar & insertByOuterInner (Index j, Index i)
 
void makeCompressed ()
 Turns the matrix into the compressed format.
 
void uncompress ()
 Turns the matrix into the uncompressed mode.
 
void prune (const Scalar &reference, const RealScalar &epsilon=NumTraits< RealScalar >::dummy_precision())
 Suppresses all nonzeros which are much smaller than reference under the tolerence epsilon.
 
template<typename KeepFunc >
void prune (const KeepFunc &keep=KeepFunc())
 Turns the matrix into compressed format, and suppresses all nonzeros which do not satisfy the predicate keep.
 
void conservativeResize (Index rows, Index cols)
 Resizes the matrix to a rows x cols matrix leaving old values untouched.
 
void resize (Index rows, Index cols)
 Resizes the matrix to a rows x cols matrix and initializes it to zero.
 
void resizeNonZeros (Index size)
 
const ConstDiagonalReturnType diagonal () const
 
DiagonalReturnType diagonal ()
 
 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.
 
template<typename OtherDerived , unsigned int UpLo>
 SparseMatrix (const SparseSelfAdjointView< OtherDerived, UpLo > &other)
 Constructs a sparse matrix from the sparse selfadjoint view other.
 
 SparseMatrix (const SparseMatrix &other)
 Copy constructor (it performs a deep copy)
 
template<typename OtherDerived >
 SparseMatrix (const ReturnByValue< OtherDerived > &other)
 Copy constructor with in-place evaluation.
 
template<typename OtherDerived >
 SparseMatrix (const DiagonalBase< OtherDerived > &other)
 Copy constructor with in-place evaluation.
 
void swap (SparseMatrix &other)
 Swaps the content of two sparse matrices of the same type.
 
void setIdentity ()
 Sets *this to the identity matrix.
 
SparseMatrixoperator= (const SparseMatrix &other)
 
template<typename OtherDerived >
SparseMatrixoperator= (const EigenBase< OtherDerived > &other)
 
template<typename OtherDerived >
EIGEN_DONT_INLINE SparseMatrixoperator= (const SparseMatrixBase< OtherDerived > &other)
 
 ~SparseMatrix ()
 Destructor.
 
Scalar sum () const
 Overloaded for performance.
 
EIGEN_STRONG_INLINE Scalar & insertBackUncompressed (Index row, Index col)
 
template<typename OtherDerived >
EIGEN_DONT_INLINE SparseMatrix< Scalar, _Options, _Index > & operator= (const SparseMatrixBase< OtherDerived > &other)
 
bool isCompressed () const
 
Index nonZeros () const
 
- Public Member Functions inherited from Eigen::SparseCompressedBase< SparseMatrix< _Scalar, _Options, _Index > >
Index nonZeros () const
 
const Scalar * valuePtr () const
 
Scalar * valuePtr ()
 
const StorageIndex * innerIndexPtr () const
 
StorageIndex * innerIndexPtr ()
 
const StorageIndex * outerIndexPtr () const
 
StorageIndex * outerIndexPtr ()
 
const StorageIndex * innerNonZeroPtr () const
 
StorageIndex * innerNonZeroPtr ()
 
bool isCompressed () const
 
SparseMatrix< _Scalar, _Options, _Index > & operator= (const EigenBase< OtherDerived > &other)
 
SparseMatrix< _Scalar, _Options, _Index > & operator= (const ReturnByValue< OtherDerived > &other)
 
SparseMatrix< _Scalar, _Options, _Index > & operator= (const SparseMatrixBase< OtherDerived > &other)
 
SparseMatrix< _Scalar, _Options, _Index > & operator= (const SparseMatrix< _Scalar, _Options, _Index > &other)
 
- Public Member Functions inherited from Eigen::SparseMatrixBase< Derived >
template<typename OtherDerived >
Derived & operator= (const EigenBase< OtherDerived > &other)
 
const Derived & derived () const
 
Derived & derived ()
 
Derived & const_cast_derived () const
 
Index rows () const
 
Index cols () const
 
Index size () const
 
bool isVector () const
 
Index outerSize () const
 
Index innerSize () const
 
bool isRValue () const
 
Derived & markAsRValue ()
 
template<typename OtherDerived >
Derived & operator= (const ReturnByValue< OtherDerived > &other)
 
template<typename OtherDerived >
Derived & operator= (const SparseMatrixBase< OtherDerived > &other)
 
Derived & operator= (const Derived &other)
 
template<typename OtherDerived >
Derived & operator+= (const SparseMatrixBase< OtherDerived > &other)
 
template<typename OtherDerived >
Derived & operator-= (const SparseMatrixBase< OtherDerived > &other)
 
template<typename OtherDerived >
Derived & operator+= (const DiagonalBase< OtherDerived > &other)
 
template<typename OtherDerived >
Derived & operator-= (const DiagonalBase< OtherDerived > &other)
 
Derived & operator*= (const Scalar &other)
 
Derived & operator/= (const Scalar &other)
 
template<typename OtherDerived >
EIGEN_STRONG_INLINE const CwiseProductDenseReturnType< OtherDerived >::Type cwiseProduct (const MatrixBase< OtherDerived > &other) const
 
template<typename OtherDerived >
const Product< Derived, OtherDerivedoperator* (const DiagonalBase< OtherDerived > &other) const
 
template<typename OtherDerived >
const Product< Derived, OtherDerived, AliasFreeProduct > operator* (const SparseMatrixBase< OtherDerived > &other) const
 
template<typename OtherDerived >
const Product< Derived, OtherDerivedoperator* (const MatrixBase< OtherDerived > &other) const
 
SparseSymmetricPermutationProduct< Derived, Upper|LowertwistedBy (const PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm) const
 
template<typename OtherDerived >
Derived & operator*= (const SparseMatrixBase< OtherDerived > &other)
 
template<int Mode>
const TriangularView< const Derived, Mode > triangularView () const
 
template<unsigned int UpLo>
ConstSelfAdjointViewReturnType< UpLo >::Type selfadjointView () const
 
template<unsigned int UpLo>
SelfAdjointViewReturnType< UpLo >::Type selfadjointView ()
 
template<typename OtherDerived >
Scalar dot (const MatrixBase< OtherDerived > &other) const
 
template<typename OtherDerived >
Scalar dot (const SparseMatrixBase< OtherDerived > &other) const
 
RealScalar squaredNorm () const
 
RealScalar norm () const
 
RealScalar blueNorm () const
 
TransposeReturnType transpose ()
 
const ConstTransposeReturnType transpose () const
 
const AdjointReturnType adjoint () const
 
InnerVectorReturnType innerVector (Index outer)
 
const ConstInnerVectorReturnType innerVector (Index outer) const
 
InnerVectorsReturnType innerVectors (Index outerStart, Index outerSize)
 
const ConstInnerVectorsReturnType innerVectors (Index outerStart, Index outerSize) const
 
DenseMatrixType toDense () const
 
template<typename OtherDerived >
bool isApprox (const SparseMatrixBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
 
template<typename OtherDerived >
bool isApprox (const MatrixBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
 
const internal::eval< Derived >::type eval () const
 
Scalar sum () const
 
const SparseView< Derived > pruned (const Scalar &reference=Scalar(0), const RealScalar &epsilon=NumTraits< Scalar >::dummy_precision()) const
 
template<typename OtherDerived >
EIGEN_STRONG_INLINE Derived & operator-= (const SparseMatrixBase< OtherDerived > &other)
 
template<typename OtherDerived >
EIGEN_STRONG_INLINE Derived & operator+= (const SparseMatrixBase< OtherDerived > &other)
 
template<typename OtherDerived >
EIGEN_STRONG_INLINE const SparseMatrixBase< Derived >::template CwiseProductDenseReturnType< OtherDerived >::Type cwiseProduct (const MatrixBase< OtherDerived > &other) const
 
template<typename OtherDerived >
internal::traits< Derived >::Scalar dot (const MatrixBase< OtherDerived > &other) const
 
template<typename OtherDerived >
internal::traits< Derived >::Scalar dot (const SparseMatrixBase< OtherDerived > &other) const
 
template<unsigned int UpLo>
SparseMatrixBase< Derived >::template ConstSelfAdjointViewReturnType< UpLo >::Type selfadjointView () const
 
template<unsigned int UpLo>
SparseMatrixBase< Derived >::template SelfAdjointViewReturnType< UpLo >::Type selfadjointView ()
 
void operator* (dummy) const
 
void operator/ (dummy) const
 
- Public Member Functions inherited from Eigen::internal::special_scalar_op_base< Derived, internal::traits< Derived >::Scalar, NumTraits< internal::traits< Derived >::Scalar >::Real, EigenBase< Derived > >
void operator* (dummy) const
 
void operator/ (dummy) const
 
- Public Member Functions inherited from Eigen::EigenBase< Derived >
EIGEN_DEVICE_FUNC Derived & derived ()
 
EIGEN_DEVICE_FUNC const Derived & derived () const
 
EIGEN_DEVICE_FUNC Derived & const_cast_derived () const
 
EIGEN_DEVICE_FUNC const Derived & const_derived () const
 
EIGEN_DEVICE_FUNC Index rows () const
 
EIGEN_DEVICE_FUNC Index cols () const
 
EIGEN_DEVICE_FUNC Index size () const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void evalTo (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void addTo (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void subTo (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void applyThisOnTheRight (Dest &dst) const
 
template<typename Dest >
EIGEN_DEVICE_FUNC void applyThisOnTheLeft (Dest &dst) const
 

Protected Types

typedef SparseMatrix< Scalar,(Flags &~RowMajorBit)|(IsRowMajor?RowMajorBit:0)> TransposedSparseMatrix
 
- Protected Types inherited from Eigen::SparseCompressedBase< SparseMatrix< _Scalar, _Options, _Index > >
typedef Base::IndexVector IndexVector
 

Protected Member Functions

template<class SizesType >
void reserveInnerVectors (const SizesType &reserveSizes)
 
template<typename Other >
void initAssignment (const Other &other)
 
EIGEN_DONT_INLINE Scalar & insertCompressed (Index row, Index col)
 
EIGEN_DONT_INLINE Scalar & insertUncompressed (Index row, Index col)
 
- Protected Member Functions inherited from Eigen::SparseCompressedBase< SparseMatrix< _Scalar, _Options, _Index > >
Eigen::Map< IndexVectorinnerNonZeros ()
 
const Eigen::Map< const IndexVectorinnerNonZeros () const
 
 SparseCompressedBase ()
 Default constructor.
 
- Protected Member Functions inherited from Eigen::SparseMatrixBase< Derived >
template<typename OtherDerived >
Derived & assign (const OtherDerived &other)
 
template<typename OtherDerived >
void assignGeneric (const OtherDerived &other)
 

Protected Attributes

Index m_outerSize
 
Index m_innerSize
 
StorageIndex * m_outerIndex
 
StorageIndex * m_innerNonZeros
 
Storage m_data
 
- Protected Attributes inherited from Eigen::SparseMatrixBase< Derived >
bool m_isRValue
 

Friends

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

Additional Inherited Members

- Static Protected Member Functions inherited from Eigen::SparseMatrixBase< Derived >
static StorageIndex convert_index (const Index idx)
 

Detailed Description

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

A versatible sparse matrix representation.

This class implements a more versatile variants of the common compressed row/column storage format. Each colmun's (resp. row) non zeros are stored as a pair of value with associated row (resp. colmiun) index. All the non zeros are stored in a single large buffer. Unlike the compressed format, there might be extra space inbetween the nonzeros of two successive colmuns (resp. rows) such that insertion of new non-zero can be done with limited memory reallocation and copies.

A call to the function makeCompressed() turns the matrix into the standard compressed format compatible with many library.

More details on this storage sceheme are given in the manual pages.

Template Parameters
_Scalarthe scalar type, i.e. the type of the coefficients
_OptionsUnion of bit flags controlling the storage scheme. Currently the only possibility is ColMajor or RowMajor. The default is 0 which means column-major.
_Indexthe type of the indices. It has to be a signed type (e.g., short, int, std::ptrdiff_t). Default is int.

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 Function Documentation

◆ coeff()

template<typename _Scalar , int _Options, typename _Index >
Scalar Eigen::SparseMatrix< _Scalar, _Options, _Index >::coeff ( Index  row,
Index  col 
) const
inline
Returns
the value of the matrix at position i, j This function returns Scalar(0) if the element is an explicit zero

◆ coeffRef()

template<typename _Scalar , int _Options, typename _Index >
Scalar & Eigen::SparseMatrix< _Scalar, _Options, _Index >::coeffRef ( Index  row,
Index  col 
)
inline
Returns
a non-const reference to the value of the matrix at position i, j

If the element does not exist then it is inserted via the insert(Index,Index) function which itself turns the matrix into a non compressed form if that was not the case.

This is a O(log(nnz_j)) operation (binary search) plus the cost of insert(Index,Index) function if the element does not already exist.

◆ cols()

template<typename _Scalar , int _Options, typename _Index >
Index Eigen::SparseMatrix< _Scalar, _Options, _Index >::cols ( ) const
inline
Returns
the number of columns of the matrix

◆ conservativeResize()

template<typename _Scalar , int _Options, typename _Index >
void Eigen::SparseMatrix< _Scalar, _Options, _Index >::conservativeResize ( Index  rows,
Index  cols 
)
inline

Resizes the matrix to a rows x cols matrix leaving old values untouched.

See also
reserve(), setZero()

◆ diagonal() [1/2]

template<typename _Scalar , int _Options, typename _Index >
DiagonalReturnType Eigen::SparseMatrix< _Scalar, _Options, _Index >::diagonal ( )
inline
Returns
a read-write expression of the diagonal coefficients.
Warning
If the diagonal entries are written, then all diagonal entries must already exist, otherwise an assertion will be raised.

◆ diagonal() [2/2]

template<typename _Scalar , int _Options, typename _Index >
const ConstDiagonalReturnType Eigen::SparseMatrix< _Scalar, _Options, _Index >::diagonal ( ) const
inline
Returns
a const expression of the diagonal coefficients.

◆ innerIndexPtr() [1/2]

template<typename _Scalar , int _Options, typename _Index >
StorageIndex * Eigen::SparseMatrix< _Scalar, _Options, _Index >::innerIndexPtr ( )
inline
Returns
a non-const pointer to the array of inner indices. This function is aimed at interoperability with other libraries.
See also
valuePtr(), outerIndexPtr()

◆ innerIndexPtr() [2/2]

template<typename _Scalar , int _Options, typename _Index >
const StorageIndex * Eigen::SparseMatrix< _Scalar, _Options, _Index >::innerIndexPtr ( ) const
inline
Returns
a const pointer to the array of inner indices. This function is aimed at interoperability with other libraries.
See also
valuePtr(), outerIndexPtr()

◆ innerNonZeroPtr() [1/2]

template<typename _Scalar , int _Options, typename _Index >
StorageIndex * Eigen::SparseMatrix< _Scalar, _Options, _Index >::innerNonZeroPtr ( )
inline
Returns
a non-const pointer to the array of the number of non zeros of the inner vectors. This function is aimed at interoperability with other libraries.
Warning
it returns the null pointer 0 in compressed mode

◆ innerNonZeroPtr() [2/2]

template<typename _Scalar , int _Options, typename _Index >
const StorageIndex * Eigen::SparseMatrix< _Scalar, _Options, _Index >::innerNonZeroPtr ( ) const
inline
Returns
a const pointer to the array of the number of non zeros of the inner vectors. This function is aimed at interoperability with other libraries.
Warning
it returns the null pointer 0 in compressed mode

◆ innerSize()

template<typename _Scalar , int _Options, typename _Index >
Index Eigen::SparseMatrix< _Scalar, _Options, _Index >::innerSize ( ) const
inline
Returns
the number of rows (resp. columns) of the matrix if the storage order column major (resp. row major)

◆ insert()

template<typename _Scalar , int _Options, typename _Index >
SparseMatrix< _Scalar, _Options, _Index >::Scalar & Eigen::SparseMatrix< _Scalar, _Options, _Index >::insert ( Index  row,
Index  col 
)
Returns
a reference to a novel non zero coefficient with coordinates row x col. The non zero coefficient must not already exist.

If the matrix *this is in compressed mode, then *this is turned into uncompressed mode while reserving room for 2 x this->innerSize() non zeros if reserve(Index) has not been called earlier. In this case, the insertion procedure is optimized for a sequential insertion mode where elements are assumed to be inserted by increasing outer-indices.

If that's not the case, then it is strongly recommended to either use a triplet-list to assemble the matrix, or to first call reserve(const SizesType &) to reserve the appropriate number of non-zero elements per inner vector.

Assuming memory has been appropriately reserved, this function performs a sorted insertion in O(1) if the elements of each inner vector are inserted in increasing inner index order, and in O(nnz_j) for a random insertion.

◆ isCompressed()

template<typename _Scalar , int _Options, typename _Index >
bool Eigen::SparseCompressedBase< Derived >::isCompressed ( ) const
inline
Returns
whether *this is in compressed form.

◆ nonZeros()

template<typename _Scalar , int _Options, typename _Index >
Index Eigen::SparseCompressedBase< Derived >::nonZeros ( ) const
inline
Returns
the number of non zero coefficients

◆ outerIndexPtr() [1/2]

template<typename _Scalar , int _Options, typename _Index >
StorageIndex * Eigen::SparseMatrix< _Scalar, _Options, _Index >::outerIndexPtr ( )
inline
Returns
a non-const pointer to the array of the starting positions of the inner vectors. This function is aimed at interoperability with other libraries.
See also
valuePtr(), innerIndexPtr()

◆ outerIndexPtr() [2/2]

template<typename _Scalar , int _Options, typename _Index >
const StorageIndex * Eigen::SparseMatrix< _Scalar, _Options, _Index >::outerIndexPtr ( ) const
inline
Returns
a const pointer to the array of the starting positions of the inner vectors. This function is aimed at interoperability with other libraries.
See also
valuePtr(), innerIndexPtr()

◆ outerSize()

template<typename _Scalar , int _Options, typename _Index >
Index Eigen::SparseMatrix< _Scalar, _Options, _Index >::outerSize ( ) const
inline
Returns
the number of columns (resp. rows) of the matrix if the storage order column major (resp. row major)

◆ prune()

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

Turns the matrix into compressed format, and suppresses 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;
Pseudo expression representing a solving operation.
Definition Solve.h:63
See also
prune(Scalar,RealScalar)

◆ reserve()

template<typename _Scalar , int _Options, typename _Index >
void Eigen::SparseMatrix< _Scalar, _Options, _Index >::reserve ( Index  reserveSize)
inline

Preallocates reserveSize non zeros.

Precondition: the matrix must be in compressed mode.

◆ resize()

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

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

This function does not free the currently allocated memory. To release as much as memory as possible, call

mat.data().squeeze();

after resizing it.

See also
reserve(), setZero()

◆ rows()

template<typename _Scalar , int _Options, typename _Index >
Index Eigen::SparseMatrix< _Scalar, _Options, _Index >::rows ( ) const
inline
Returns
the number of rows of the matrix

◆ setFromTriplets() [1/2]

template<typename Scalar , int _Options, typename _Index >
void Eigen::SparseMatrix< Scalar, _Options, _Index >::setFromTriplets ( const InputIterators begin,
const InputIterators end 
)

Fill the matrix *this with the list of triplets defined by the iterator range begin - end.

A triplet is a tuple (i,j,value) defining a non-zero element. The input list of triplets does not have to be sorted, and can contains duplicated elements. In any case, the result is a sorted and compressed sparse matrix where the duplicates have been summed up. This is a O(n) operation, with n the number of triplet elements. The initial contents of *this is destroyed. The matrix *this must be properly resized beforehand using the SparseMatrix(Index,Index) constructor, or the resize(Index,Index) method. The sizes are not extracted from the triplet list.

The InputIterators value_type must provide the following interface:

Scalar value() const; // the value
Scalar row() const; // the row index i
Scalar col() const; // the column index j

See for instance the Eigen::Triplet template class.

Here is a typical usage example:

typedef Triplet<double> T;
std::vector<T> tripletList;
for(...)
{
// ...
tripletList.push_back(T(i,j,v_ij));
}
SparseMatrixType m(rows,cols);
m.setFromTriplets(tripletList.begin(), tripletList.end());
// m is ready to go!
Index rows() const
Definition SparseMatrix.h:131
Index cols() const
Definition SparseMatrix.h:133
Warning
The list of triplets is read multiple times (at least twice). Therefore, it is not recommended to define an abstract iterator over a complex data-structure that would be expensive to evaluate. The triplets should rather be explicitely stored into a std::vector for instance.

◆ setFromTriplets() [2/2]

template<typename Scalar , int _Options, typename _Index >
void Eigen::SparseMatrix< Scalar, _Options, _Index >::setFromTriplets ( const InputIterators begin,
const InputIterators end,
DupFunctor  dup_func 
)

The same as setFromTriplets but when duplicates are met the functor dup_func is applied:

Here is a C++11 example keeping the latest entry only:

mat.setFromTriplets(triplets.begin(), triplets.end(), [] (const Scalar&,const Scalar &b) { return b; });

◆ setIdentity()

template<typename _Scalar , int _Options, typename _Index >
void Eigen::SparseMatrix< _Scalar, _Options, _Index >::setIdentity ( )
inline

Sets *this to the identity matrix.

This function also turns the matrix into compressed mode, and drop any reserved memory.

◆ setZero()

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

Removes all non zeros but keep allocated memory.

This function does not free the currently allocated memory. To release as much as memory as possible, call

mat.data().squeeze();

after resizing it.

See also
resize(Index,Index), data()

◆ swap()

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

Swaps the content of two sparse matrices of the same type.

This is a fast operation that simply swaps the underlying pointers and parameters.

◆ valuePtr() [1/2]

template<typename _Scalar , int _Options, typename _Index >
Scalar * Eigen::SparseMatrix< _Scalar, _Options, _Index >::valuePtr ( )
inline
Returns
a non-const pointer to the array of values. This function is aimed at interoperability with other libraries.
See also
innerIndexPtr(), outerIndexPtr()

◆ valuePtr() [2/2]

template<typename _Scalar , int _Options, typename _Index >
const Scalar * Eigen::SparseMatrix< _Scalar, _Options, _Index >::valuePtr ( ) const
inline
Returns
a const pointer to the array of values. This function is aimed at interoperability with other libraries.
See also
innerIndexPtr(), outerIndexPtr()

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