Eigen  3.4.90 (git rev 9589cc4e7fd8e4538bedef80dd36c7738977a8be)
 
Loading...
Searching...
No Matches
Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ > Class Template Reference

#include <Eigen/src/SparseCore/SparseMatrix.h>

Detailed Description

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
class Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >

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 in between 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
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 ColMajor or RowMajor. The default is 0 which means column-major.
StorageIndex_the type of the indices. It has to be a signed type (e.g., short, int, std::ptrdiff_t). Default is int.
Warning
In Eigen 3.2, the undocumented type SparseMatrix::Index was improperly defined as the storage index type (e.g., int), whereas it is now (starting from Eigen 3.3) deprecated and always defined as Eigen::Index. Codes making use of SparseMatrix::Index, might thus likely have to be changed to use SparseMatrix::StorageIndex instead.

This class can be extended with the help of the plugin mechanism described on the page Extending MatrixBase (and other classes) by defining the preprocessor symbol EIGEN_SPARSEMATRIX_PLUGIN.

+ Inheritance diagram for Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >:

Public Member Functions

Scalar coeff (Index row, Index col) const
 
ScalarcoeffRef (Index row, Index col)
 
Index cols () const
 
void conservativeResize (Index rows, Index cols)
 
DiagonalReturnType diagonal ()
 
const ConstDiagonalReturnType diagonal () const
 
ScalarfindOrInsertCoeff (Index row, Index col, bool *inserted)
 
StorageIndexinnerIndexPtr ()
 
const StorageIndexinnerIndexPtr () const
 
StorageIndexinnerNonZeroPtr ()
 
const StorageIndexinnerNonZeroPtr () const
 
Index innerSize () const
 
Scalarinsert (Index row, Index col)
 
template<typename InputIterators>
void insertFromSortedTriplets (const InputIterators &begin, const InputIterators &end)
 
template<typename InputIterators, typename DupFunctor>
void insertFromSortedTriplets (const InputIterators &begin, const InputIterators &end, DupFunctor dup_func)
 
template<typename InputIterators>
void insertFromTriplets (const InputIterators &begin, const InputIterators &end)
 
template<typename InputIterators, typename DupFunctor>
void insertFromTriplets (const InputIterators &begin, const InputIterators &end, DupFunctor dup_func)
 
bool isCompressed () const
 
void makeCompressed ()
 
Index nonZeros () const
 
StorageIndexouterIndexPtr ()
 
const StorageIndexouterIndexPtr () const
 
Index outerSize () const
 
template<typename KeepFunc>
void prune (const KeepFunc &keep=KeepFunc())
 
void prune (const Scalar &reference, const RealScalar &epsilon=NumTraits< RealScalar >::dummy_precision())
 
template<class SizesType>
void reserve (const SizesType &reserveSizes)
 
void reserve (Index reserveSize)
 
void resize (Index rows, Index cols)
 
Index rows () const
 
template<typename InputIterators>
void setFromSortedTriplets (const InputIterators &begin, const InputIterators &end)
 
template<typename InputIterators, typename DupFunctor>
void setFromSortedTriplets (const InputIterators &begin, const InputIterators &end, DupFunctor dup_func)
 
template<typename InputIterators>
void setFromTriplets (const InputIterators &begin, const InputIterators &end)
 
template<typename InputIterators, typename DupFunctor>
void setFromTriplets (const InputIterators &begin, const InputIterators &end, DupFunctor dup_func)
 
void setIdentity ()
 
void setZero ()
 
 SparseMatrix ()
 
template<typename OtherDerived>
 SparseMatrix (const DiagonalBase< OtherDerived > &other)
 Copy constructor with in-place evaluation.
 
template<typename OtherDerived>
 SparseMatrix (const ReturnByValue< OtherDerived > &other)
 Copy constructor with in-place evaluation.
 
 SparseMatrix (const SparseMatrix &other)
 
template<typename OtherDerived>
 SparseMatrix (const SparseMatrixBase< OtherDerived > &other)
 
template<typename OtherDerived, unsigned int UpLo>
 SparseMatrix (const SparseSelfAdjointView< OtherDerived, UpLo > &other)
 
 SparseMatrix (Index rows, Index cols)
 
 SparseMatrix (SparseMatrix &&other)
 
Scalar sum () const
 
void swap (SparseMatrix &other)
 
void uncompress ()
 
ScalarvaluePtr ()
 
const ScalarvaluePtr () const
 
 ~SparseMatrix ()
 
- Public Member Functions inherited from Eigen::SparseCompressedBase< SparseMatrix< Scalar_, Options_, int > >
Map< Array< Scalar, Dynamic, 1 > > coeffs ()
 
const Map< const Array< Scalar, Dynamic, 1 > > coeffs () const
 
StorageIndexinnerIndexPtr ()
 
const StorageIndexinnerIndexPtr () const
 
Index innerIndicesAreSorted () const
 
Index innerIndicesAreSorted (Index begin, Index end) const
 
StorageIndexinnerNonZeroPtr ()
 
const StorageIndexinnerNonZeroPtr () const
 
bool isCompressed () const
 
Index nonZeros () const
 
StorageIndexouterIndexPtr ()
 
const StorageIndexouterIndexPtr () const
 
void sortInnerIndices ()
 
void sortInnerIndices (Index begin, Index end)
 
Scalar * valuePtr ()
 
const Scalar * valuePtr () const
 
- Public Member Functions inherited from Eigen::SparseMatrixBase< SparseMatrix< Scalar_, Options_, int > >
const CwiseBinaryOp< CustomBinaryOp, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > binaryExpr (const Eigen::SparseMatrixBase< OtherDerived > &other, const CustomBinaryOp &func=CustomBinaryOp()) const
 
FixedBlockXpr< NRows, NCols >::Type block (Index startRow, Index startCol)
 
const ConstFixedBlockXpr< NRows, NCols >::Type block (Index startRow, Index startCol) const
 This is the const version of block<>(Index, Index). *‍/.
 
FixedBlockXpr< NRows, NCols >::Type block (Index startRow, Index startCol, Index blockRows, Index blockCols)
 
const ConstFixedBlockXpr< NRows, NCols >::Type block (Index startRow, Index startCol, Index blockRows, Index blockCols) const
 This is the const version of block<>(Index, Index, Index, Index).
 
FixedBlockXpr<...,... >::Type block (Index startRow, Index startCol, NRowsType blockRows, NColsType blockCols)
 
const ConstFixedBlockXpr<...,... >::Type block (Index startRow, Index startCol, NRowsType blockRows, NColsType blockCols) const
 This is the const version of block(Index,Index,NRowsType,NColsType)
 
FixedBlockXpr< CRows, CCols >::Type bottomLeftCorner ()
 
const ConstFixedBlockXpr< CRows, CCols >::Type bottomLeftCorner () const
 This is the const version of bottomLeftCorner<int, int>().
 
FixedBlockXpr< CRows, CCols >::Type bottomLeftCorner (Index cRows, Index cCols)
 
const ConstFixedBlockXpr< CRows, CCols >::Type bottomLeftCorner (Index cRows, Index cCols) const
 This is the const version of bottomLeftCorner<int, int>(Index, Index).
 
FixedBlockXpr<...,... >::Type bottomLeftCorner (NRowsType cRows, NColsType cCols)
 
ConstFixedBlockXpr<...,... >::Type bottomLeftCorner (NRowsType cRows, NColsType cCols) const
 This is the const version of bottomLeftCorner(NRowsType, NColsType).
 
FixedBlockXpr< CRows, CCols >::Type bottomRightCorner ()
 
const ConstFixedBlockXpr< CRows, CCols >::Type bottomRightCorner () const
 This is the const version of bottomRightCorner<int, int>().
 
FixedBlockXpr< CRows, CCols >::Type bottomRightCorner (Index cRows, Index cCols)
 
const ConstFixedBlockXpr< CRows, CCols >::Type bottomRightCorner (Index cRows, Index cCols) const
 This is the const version of bottomRightCorner<int, int>(Index, Index).
 
FixedBlockXpr<...,... >::Type bottomRightCorner (NRowsType cRows, NColsType cCols)
 
const ConstFixedBlockXpr<...,... >::Type bottomRightCorner (NRowsType cRows, NColsType cCols) const
 This is the const version of bottomRightCorner(NRowsType, NColsType).
 
NRowsBlockXpr< N >::Type bottomRows (Index n=N)
 
ConstNRowsBlockXpr< N >::Type bottomRows (Index n=N) const
 This is the const version of bottomRows<int>().
 
NRowsBlockXpr<... >::Type bottomRows (NRowsType n)
 
const ConstNRowsBlockXpr<... >::Type bottomRows (NRowsType n) const
 This is the const version of bottomRows(NRowsType).
 
CastXpr< NewType >::Type cast () const
 
ColXpr col (Index i)
 
ConstColXpr col (Index i) const
 This is the const version of col().
 
Index cols () const
 
ConjugateReturnType conjugate () const
 
std::conditional_t< Cond, ConjugateReturnType, const SparseMatrix< Scalar_, Options_, int > & > conjugateIf () const
 
const CwiseAbsReturnType cwiseAbs () const
 
const CwiseAbs2ReturnType cwiseAbs2 () const
 
const CwiseArgReturnType cwiseArg () const
 
const CwiseCbrtReturnType cwiseCbrt () const
 
const CwiseBinaryEqualReturnType< OtherDerived > cwiseEqual (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseScalarEqualReturnType cwiseEqual (const Scalar &s) const
 
const CwiseBinaryGreaterReturnType< OtherDerived > cwiseGreater (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseScalarGreaterReturnType cwiseGreater (const Scalar &s) const
 
const CwiseBinaryGreaterOrEqualReturnType< OtherDerived > cwiseGreaterOrEqual (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseScalarGreaterOrEqualReturnType cwiseGreaterOrEqual (const Scalar &s) const
 
const CwiseInverseReturnType cwiseInverse () const
 
const CwiseBinaryLessReturnType< OtherDerived > cwiseLess (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseScalarLessReturnType cwiseLess (const Scalar &s) const
 
const CwiseBinaryLessOrEqualReturnType< OtherDerived > cwiseLessOrEqual (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseScalarLessOrEqualReturnType cwiseLessOrEqual (const Scalar &s) const
 
const CwiseBinaryOp< internal::scalar_max_op< Scalar, Scalar, NaNPropagation >, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > cwiseMax (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseBinaryOp< internal::scalar_max_op< Scalar, Scalar, NaNPropagation >, const SparseMatrix< Scalar_, Options_, int >, const ConstantReturnType > cwiseMax (const Scalar &other) const
 
const CwiseBinaryOp< internal::scalar_min_op< Scalar, Scalar, NaNPropagation >, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > cwiseMin (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseBinaryOp< internal::scalar_min_op< Scalar, Scalar, NaNPropagation >, const SparseMatrix< Scalar_, Options_, int >, const ConstantReturnType > cwiseMin (const Scalar &other) const
 
const CwiseBinaryNotEqualReturnType< OtherDerived > cwiseNotEqual (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseScalarNotEqualReturnType cwiseNotEqual (const Scalar &s) const
 
const CwiseBinaryOp< internal::scalar_product_op< SparseMatrix< Scalar_, Options_, int > ::Scalar, OtherDerived ::Scalar >, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > cwiseProduct (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > cwiseQuotient (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseSignReturnType cwiseSign () const
 
const CwiseSqrtReturnType cwiseSqrt () const
 
const CwiseSquareReturnType cwiseSquare () const
 
const internal::eval< SparseMatrix< Scalar_, Options_, int > >::type eval () const
 
FixedSegmentReturnType< N >::Type head (Index n=N)
 
ConstFixedSegmentReturnType< N >::Type head (Index n=N) const
 This is the const version of head<int>().
 
FixedSegmentReturnType<... >::Type head (NType n)
 
const ConstFixedSegmentReturnType<... >::Type head (NType n) const
 This is the const version of head(NType).
 
NonConstImagReturnType imag ()
 
const ImagReturnType imag () const
 
Index innerSize () 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
 
bool isVector () const
 
NColsBlockXpr< N >::Type leftCols (Index n=N)
 
ConstNColsBlockXpr< N >::Type leftCols (Index n=N) const
 This is the const version of leftCols<int>().
 
NColsBlockXpr<... >::Type leftCols (NColsType n)
 
const ConstNColsBlockXpr<... >::Type leftCols (NColsType n) const
 This is the const version of leftCols(NColsType).
 
NColsBlockXpr< N >::Type middleCols (Index startCol, Index n=N)
 
ConstNColsBlockXpr< N >::Type middleCols (Index startCol, Index n=N) const
 This is the const version of middleCols<int>().
 
NColsBlockXpr<... >::Type middleCols (Index startCol, NColsType numCols)
 
const ConstNColsBlockXpr<... >::Type middleCols (Index startCol, NColsType numCols) const
 This is the const version of middleCols(Index,NColsType).
 
NRowsBlockXpr< N >::Type middleRows (Index startRow, Index n=N)
 
ConstNRowsBlockXpr< N >::Type middleRows (Index startRow, Index n=N) const
 This is the const version of middleRows<int>().
 
NRowsBlockXpr<... >::Type middleRows (Index startRow, NRowsType n)
 
const ConstNRowsBlockXpr<... >::Type middleRows (Index startRow, NRowsType n) const
 This is the const version of middleRows(Index,NRowsType).
 
const CwiseBinaryOp< internal::scalar_bitwise_and_op< Scalar >, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > operator& (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseBinaryOp< internal::scalar_boolean_and_op< Scalar >, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > operator&& (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const Product< SparseMatrix< Scalar_, Options_, int >, OtherDerived, AliasFreeProduct > operator* (const SparseMatrixBase< OtherDerived > &other) const
 
const CwiseBinaryOp< sum< Scalar >, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > operator+ (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const NegativeReturnType operator- () const
 
const CwiseBinaryOp< difference< Scalar >, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > operator- (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseBinaryOp< internal::scalar_bitwise_xor_op< Scalar >, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > operator^ (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseBinaryOp< internal::scalar_bitwise_or_op< Scalar >, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > operator| (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
const CwiseBinaryOp< internal::scalar_boolean_or_op< Scalar >, const SparseMatrix< Scalar_, Options_, int >, const OtherDerived > operator|| (const Eigen::SparseMatrixBase< OtherDerived > &other) const
 
Index outerSize () const
 
const SparseView< SparseMatrix< Scalar_, Options_, int > > pruned (const Scalar &reference=Scalar(0), const RealScalar &epsilon=NumTraits< Scalar >::dummy_precision()) const
 
NonConstRealReturnType real ()
 
RealReturnType real () const
 
NColsBlockXpr< N >::Type rightCols (Index n=N)
 
ConstNColsBlockXpr< N >::Type rightCols (Index n=N) const
 This is the const version of rightCols<int>().
 
NColsBlockXpr<... >::Type rightCols (NColsType n)
 
const ConstNColsBlockXpr<... >::Type rightCols (NColsType n) const
 This is the const version of rightCols(NColsType).
 
RowXpr row (Index i)
 
ConstRowXpr row (Index i) const
 This is the const version of row(). *‍/.
 
Index rows () const
 
FixedSegmentReturnType< N >::Type segment (Index start, Index n=N)
 
ConstFixedSegmentReturnType< N >::Type segment (Index start, Index n=N) const
 This is the const version of segment<int>(Index).
 
FixedSegmentReturnType<... >::Type segment (Index start, NType n)
 
const ConstFixedSegmentReturnType<... >::Type segment (Index start, NType n) const
 This is the const version of segment(Index,NType).
 
Index size () const
 
std::conditional_t< Direction==Vertical, ColXpr, RowXpr > subVector (Index i)
 
std::conditional_t< Direction==Vertical, ConstColXpr, ConstRowXpr > subVector (Index i) const
 
EIGEN_CONSTEXPR Index subVectors () const
 
FixedSegmentReturnType< N >::Type tail (Index n=N)
 
ConstFixedSegmentReturnType< N >::Type tail (Index n=N) const
 This is the const version of tail<int>.
 
FixedSegmentReturnType<... >::Type tail (NType n)
 
const ConstFixedSegmentReturnType<... >::Type tail (NType n) const
 This is the const version of tail(Index).
 
FixedBlockXpr< CRows, CCols >::Type topLeftCorner ()
 
const ConstFixedBlockXpr< CRows, CCols >::Type topLeftCorner () const
 This is the const version of topLeftCorner<int, int>().
 
FixedBlockXpr< CRows, CCols >::Type topLeftCorner (Index cRows, Index cCols)
 
const ConstFixedBlockXpr< CRows, CCols >::Type topLeftCorner (Index cRows, Index cCols) const
 This is the const version of topLeftCorner<int, int>(Index, Index).
 
FixedBlockXpr<...,... >::Type topLeftCorner (NRowsType cRows, NColsType cCols)
 
const ConstFixedBlockXpr<...,... >::Type topLeftCorner (NRowsType cRows, NColsType cCols) const
 This is the const version of topLeftCorner(Index, Index).
 
FixedBlockXpr< CRows, CCols >::Type topRightCorner ()
 
const ConstFixedBlockXpr< CRows, CCols >::Type topRightCorner () const
 This is the const version of topRightCorner<int, int>().
 
FixedBlockXpr< CRows, CCols >::Type topRightCorner (Index cRows, Index cCols)
 
const ConstFixedBlockXpr< CRows, CCols >::Type topRightCorner (Index cRows, Index cCols) const
 This is the const version of topRightCorner<int, int>(Index, Index).
 
FixedBlockXpr<...,... >::Type topRightCorner (NRowsType cRows, NColsType cCols)
 
const ConstFixedBlockXpr<...,... >::Type topRightCorner (NRowsType cRows, NColsType cCols) const
 This is the const version of topRightCorner(NRowsType, NColsType).
 
NRowsBlockXpr< N >::Type topRows (Index n=N)
 
ConstNRowsBlockXpr< N >::Type topRows (Index n=N) const
 This is the const version of topRows<int>().
 
NRowsBlockXpr<... >::Type topRows (NRowsType n)
 
const ConstNRowsBlockXpr<... >::Type topRows (NRowsType n) const
 This is the const version of topRows(NRowsType).
 
SparseSymmetricPermutationProduct< SparseMatrix< Scalar_, Options_, int >, Upper|LowertwistedBy (const PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm) const
 
const CwiseUnaryOp< CustomUnaryOp, const SparseMatrix< Scalar_, Options_, int > > unaryExpr (const CustomUnaryOp &func=CustomUnaryOp()) const
 Apply a unary operator coefficient-wise.
 
CwiseUnaryView< CustomViewOp, SparseMatrix< Scalar_, Options_, int > > unaryViewExpr (const CustomViewOp &func=CustomViewOp())
 
const CwiseUnaryView< CustomViewOp, const SparseMatrix< Scalar_, Options_, int > > unaryViewExpr (const CustomViewOp &func=CustomViewOp()) const
 
- Public Member Functions inherited from Eigen::EigenBase< SparseMatrix< Scalar_, Options_, int > >
EIGEN_CONSTEXPR Index cols () const EIGEN_NOEXCEPT
 
constexpr SparseMatrix< Scalar_, Options_, int > & derived ()
 
constexpr const SparseMatrix< Scalar_, Options_, int > & derived () const
 
EIGEN_CONSTEXPR Index rows () const EIGEN_NOEXCEPT
 
EIGEN_CONSTEXPR Index size () const EIGEN_NOEXCEPT
 

Additional Inherited Members

- Public Types inherited from Eigen::SparseMatrixBase< SparseMatrix< Scalar_, Options_, int > >
typedef NumTraits< Scalar >::Real RealScalar
 
typedef internal::traits< SparseMatrix< Scalar_, Options_, int > >::StorageIndex StorageIndex
 
typedef Scalar value_type
 
- Public Types inherited from Eigen::EigenBase< SparseMatrix< Scalar_, Options_, int > >
typedef Eigen::Index Index
 The interface type of indices.
 
- Protected Member Functions inherited from Eigen::SparseCompressedBase< SparseMatrix< Scalar_, Options_, int > >
 SparseCompressedBase ()
 

Constructor & Destructor Documentation

◆ SparseMatrix() [1/6]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::SparseMatrix ( )
inline

Default constructor yielding an empty 0 x 0 matrix

◆ SparseMatrix() [2/6]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::SparseMatrix ( Index rows,
Index cols )
inline

Constructs a rows x cols empty matrix

◆ SparseMatrix() [3/6]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
template<typename OtherDerived>
Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::SparseMatrix ( const SparseMatrixBase< OtherDerived > & other)
inline

Constructs a sparse matrix from the sparse expression other

◆ SparseMatrix() [4/6]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
template<typename OtherDerived, unsigned int UpLo>
Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::SparseMatrix ( const SparseSelfAdjointView< OtherDerived, UpLo > & other)
inline

Constructs a sparse matrix from the sparse selfadjoint view other

◆ SparseMatrix() [5/6]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::SparseMatrix ( SparseMatrix< Scalar_, Flags_, StorageIndex_ > && other)
inline

Move constructor

◆ SparseMatrix() [6/6]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::SparseMatrix ( const SparseMatrix< Scalar_, Flags_, StorageIndex_ > & other)
inline

Copy constructor (it performs a deep copy)

◆ ~SparseMatrix()

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::~SparseMatrix ( )
inline

Destructor

Member Function Documentation

◆ coeff()

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
Scalar Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
Scalar & Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
Index Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::cols ( ) const
inline
Returns
the number of columns of the matrix

◆ conservativeResize()

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
void Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::conservativeResize ( Index rows,
Index cols )
inline

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

If the sizes of the matrix are decreased, then the matrix is turned to uncompressed-mode and the storage of the out of bounds coefficients is kept and reserved. Call makeCompressed() to pack the entries and squeeze extra memory.

See also
reserve(), setZero(), makeCompressed()

◆ diagonal() [1/2]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
DiagonalReturnType Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
const ConstDiagonalReturnType Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::diagonal ( ) const
inline
Returns
a const expression of the diagonal coefficients.

◆ findOrInsertCoeff()

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
Scalar & Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::findOrInsertCoeff ( Index row,
Index col,
bool * inserted )
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. The output parameter inserted is set to true.

Otherwise, if the element does exist, inserted will be set to false.

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.

◆ innerIndexPtr() [1/2]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
StorageIndex * Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
const StorageIndex * Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
StorageIndex * Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
const StorageIndex * Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
Index Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 StorageIndex_>
SparseMatrix< Scalar_, Options_, StorageIndex_ >::Scalar & Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::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.

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.

◆ insertFromSortedTriplets() [1/2]

template<typename Scalar, int Options_, typename StorageIndex_>
template<typename InputIterators>
void Eigen::SparseMatrix< Scalar, Options_, StorageIndex_ >::insertFromSortedTriplets ( const InputIterators & begin,
const InputIterators & end )

The same as insertFromTriplets but triplets are assumed to be pre-sorted. This is faster and requires less temporary storage. Two triplets a and b are appropriately ordered if:

ColMajor: ((a.col() != b.col()) ? (a.col() <
b.col()) : (a.row() < b.row()) RowMajor: ((a.row() != b.row()) ? (a.row() < b.row()) : (a.col() < b.col())
@ ColMajor
Definition Constants.h:318
@ RowMajor
Definition Constants.h:320

◆ insertFromSortedTriplets() [2/2]

template<typename Scalar, int Options_, typename StorageIndex_>
template<typename InputIterators, typename DupFunctor>
void Eigen::SparseMatrix< Scalar, Options_, StorageIndex_ >::insertFromSortedTriplets ( const InputIterators & begin,
const InputIterators & end,
DupFunctor dup_func )

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

value = dup_func(OldValue, NewValue)

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

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

◆ insertFromTriplets() [1/2]

template<typename Scalar, int Options_, typename StorageIndex_>
template<typename InputIterators>
void Eigen::SparseMatrix< Scalar, Options_, StorageIndex_ >::insertFromTriplets ( const InputIterators & begin,
const InputIterators & end )

Insert a batch of elements into the matrix *this with the list of triplets defined in the half-open range from begin to 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 may contain 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 are preserved (except for the summation of duplicate elements). The matrix *this must be properly sized beforehand. The sizes are not extracted from the triplet list.

The InputIterators value_type must provide the following interface:

Scalar value() const; // the value
IndexType row() const; // the row index i
IndexType col() const; // the column index j
RowXpr row(Index i)
Definition SparseMatrixBase.h:1085
ColXpr col(Index i)
Definition SparseMatrixBase.h:1072

See for instance the Eigen::Triplet template class.

Here is a typical usage example:

SparseMatrixType m(rows,cols); // m contains nonzero entries
typedef Triplet<double> T;
std::vector<T> tripletList;
tripletList.reserve(estimation_of_entries);
for(...)
{
// ...
tripletList.push_back(T(i,j,v_ij));
}
m.insertFromTriplets(tripletList.begin(), tripletList.end());
// m is ready to go!
Index cols() const
Definition SparseMatrix.h:161
Index rows() const
Definition SparseMatrix.h:159
A small structure to hold a non zero as a triplet (i,j,value).
Definition SparseUtil.h:187
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 explicitly stored into a std::vector for instance.

◆ insertFromTriplets() [2/2]

template<typename Scalar, int Options_, typename StorageIndex_>
template<typename InputIterators, typename DupFunctor>
void Eigen::SparseMatrix< Scalar, Options_, StorageIndex_ >::insertFromTriplets ( const InputIterators & begin,
const InputIterators & end,
DupFunctor dup_func )

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

value = dup_func(OldValue, NewValue)

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

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

◆ isCompressed()

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
bool Eigen::SparseCompressedBase< SparseMatrix >::isCompressed ( ) const
inline
Returns
whether *this is in compressed form.

◆ makeCompressed()

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
void Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::makeCompressed ( )
inline

Turns the matrix into the compressed format.

◆ nonZeros()

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
Index Eigen::SparseCompressedBase< SparseMatrix >::nonZeros ( ) const
inline
Returns
the number of non zero coefficients

◆ outerIndexPtr() [1/2]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
StorageIndex * Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
const StorageIndex * Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
Index Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::outerSize ( ) const
inline
Returns
the number of columns (resp. rows) of the matrix if the storage order column major (resp. row major)

◆ prune() [1/2]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
template<typename KeepFunc>
void Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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;
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82
See also
prune(Scalar,RealScalar)

◆ prune() [2/2]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
void Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::prune ( const Scalar & reference,
const RealScalar & epsilon = NumTraits<RealScalar>::dummy_precision() )
inline

Suppresses all nonzeros which are much smaller than reference under the tolerance epsilon

◆ reserve() [1/2]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
template<class SizesType>
void Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::reserve ( const SizesType & reserveSizes)
inline

Preallocates reserveSize[j] non zeros for each column (resp. row) j.

This function turns the matrix in non-compressed mode.

The type SizesType must expose the following interface:

typedef value_type;
const value_type& operator[](i) const;

for i in the [0,this->outerSize()[ range. Typical choices include std::vector<int>, Eigen::VectorXi, Eigen::VectorXi::Constant, etc.

◆ reserve() [2/2]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
void Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::reserve ( Index reserveSize)
inline

Preallocates reserveSize non zeros.

Precondition: the matrix must be in compressed mode.

◆ resize()

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
void Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
Index Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::rows ( ) const
inline
Returns
the number of rows of the matrix

◆ setFromSortedTriplets() [1/2]

template<typename Scalar, int Options_, typename StorageIndex_>
template<typename InputIterators>
void Eigen::SparseMatrix< Scalar, Options_, StorageIndex_ >::setFromSortedTriplets ( const InputIterators & begin,
const InputIterators & end )

The same as setFromTriplets but triplets are assumed to be pre-sorted. This is faster and requires less temporary storage. Two triplets a and b are appropriately ordered if:

ColMajor: ((a.col() != b.col()) ? (a.col() <
b.col()) : (a.row() < b.row()) RowMajor: ((a.row() != b.row()) ? (a.row() < b.row()) : (a.col() < b.col())

◆ setFromSortedTriplets() [2/2]

template<typename Scalar, int Options_, typename StorageIndex_>
template<typename InputIterators, typename DupFunctor>
void Eigen::SparseMatrix< Scalar, Options_, StorageIndex_ >::setFromSortedTriplets ( const InputIterators & begin,
const InputIterators & end,
DupFunctor dup_func )

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

value = dup_func(OldValue, NewValue)

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

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

◆ setFromTriplets() [1/2]

template<typename Scalar, int Options_, typename StorageIndex_>
template<typename InputIterators>
void Eigen::SparseMatrix< Scalar, Options_, StorageIndex_ >::setFromTriplets ( const InputIterators & begin,
const InputIterators & end )

Fill the matrix *this with the list of triplets defined in the half-open range from begin to 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 may contain 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 are 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
IndexType row() const; // the row index i
IndexType 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;
tripletList.reserve(estimation_of_entries);
for(...)
{
// ...
tripletList.push_back(T(i,j,v_ij));
}
SparseMatrixType m(rows,cols);
m.setFromTriplets(tripletList.begin(), tripletList.end());
// m is ready to go!
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 explicitly stored into a std::vector for instance.

◆ setFromTriplets() [2/2]

template<typename Scalar, int Options_, typename StorageIndex_>
template<typename InputIterators, typename DupFunctor>
void Eigen::SparseMatrix< Scalar, Options_, StorageIndex_ >::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:

value = dup_func(OldValue, NewValue)

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 Flags_ = 0, typename StorageIndex_ = int>
void Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
void Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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()

◆ sum()

template<typename Scalar_, int Options_, typename Index_>
internal::traits< SparseMatrix< Scalar_, Options_, Index_ > >::Scalar Eigen::SparseMatrix< Scalar_, Options_, Index_ >::sum ( ) const

Overloaded for performance

◆ swap()

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
void Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::swap ( SparseMatrix< Scalar_, Flags_, StorageIndex_ > & 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.

◆ uncompress()

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
void Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::uncompress ( )
inline

Turns the matrix into the uncompressed mode

◆ valuePtr() [1/2]

template<typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
Scalar * Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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 Flags_ = 0, typename StorageIndex_ = int>
const Scalar * Eigen::SparseMatrix< Scalar_, Flags_, StorageIndex_ >::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: