Eigen::SparseCompressedBase< Derived > Class Template Reference

Common base class for sparse [compressed]-{row|column}-storage format. More...

+ Inheritance diagram for Eigen::SparseCompressedBase< Derived >:

Public Types

typedef SparseMatrixBase< Derived > Base
 
- Public Types inherited from Eigen::SparseMatrixBase< Derived >
enum  {
  RowsAtCompileTime ,
  ColsAtCompileTime ,
  SizeAtCompileTime ,
  MaxRowsAtCompileTime ,
  MaxColsAtCompileTime ,
  MaxSizeAtCompileTime ,
  IsVectorAtCompileTime ,
  NumDimensions ,
  Flags ,
  IsRowMajor ,
  InnerSizeAtCompileTime
}
 
typedef std::conditional_t< NumTraits< Scalar >::IsComplex, CwiseUnaryOp< internal::scalar_conjugate_op< Scalar >, Eigen::Transpose< const Derived > >, Transpose< const Derived > > AdjointReturnType
 
typedef Transpose< const Derived > ConstTransposeReturnType
 
typedef Matrix< StorageIndex, Dynamic, 1 > IndexVector
 
typedef internal::add_const_on_value_type_if_arithmetic< typename internal::packet_traits< Scalar >::type >::type PacketReturnType
 
typedef internal::packet_traits< Scalar >::type PacketScalar
 
typedef SparseMatrix< Scalar, Flags &RowMajorBit ? RowMajor :ColMajor, StorageIndexPlainObject
 
typedef internal::traits< Derived >::Scalar Scalar
 
typedef Matrix< Scalar, Dynamic, 1 > ScalarVector
 
typedef SparseMatrixBase StorageBaseType
 
typedef internal::traits< Derived >::StorageIndex StorageIndex
 
typedef internal::traits< Derived >::StorageKind StorageKind
 
typedef Transpose< Derived > TransposeReturnType
 
typedef Scalar value_type
 
- Public Types inherited from Eigen::EigenBase< Derived >
typedef Eigen::Index Index
 The interface type of indices. More...
 
typedef internal::traits< Derived >::StorageKind StorageKind
 

Public Member Functions

Map< Array< Scalar, Dynamic, 1 > > coeffs ()
 
const Map< const Array< Scalar, Dynamic, 1 > > coeffs () const
 
StorageIndexinnerIndexPtr ()
 
const StorageIndexinnerIndexPtr () const
 
template<class Comp = std::less<>>
Index innerIndicesAreSorted () const
 
template<class Comp = std::less<>>
Index innerIndicesAreSorted (Index begin, Index end) const
 
StorageIndexinnerNonZeroPtr ()
 
const StorageIndexinnerNonZeroPtr () const
 
bool isCompressed () const
 
Index nonZeros () const
 
Derived & operator= (const Derived &other)
 
template<typename OtherDerived >
Derived & operator= (const EigenBase< OtherDerived > &other)
 
template<typename OtherDerived >
Derived & operator= (const ReturnByValue< OtherDerived > &other)
 
template<typename OtherDerived >
Derived & operator= (const SparseMatrixBase< OtherDerived > &other)
 
StorageIndexouterIndexPtr ()
 
const StorageIndexouterIndexPtr () const
 
template<class Comp = std::less<>>
void sortInnerIndices ()
 
template<class Comp = std::less<>>
void sortInnerIndices (Index begin, Index end)
 
ScalarvaluePtr ()
 
const ScalarvaluePtr () const
 
- Public Member Functions inherited from Eigen::SparseMatrixBase< Derived >
const AdjointReturnType adjoint () const
 
RealScalar blueNorm () const
 
Index cols () const
 
template<typename OtherDerived >
const SparseMatrixBase< Derived >::template CwiseProductDenseReturnType< OtherDerived >::Type cwiseProduct (const MatrixBase< OtherDerived > &other) const
 
template<typename OtherDerived >
const 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 >
Scalar dot (const MatrixBase< OtherDerived > &other) const
 
template<typename OtherDerived >
internal::traits< Derived >::Scalar dot (const SparseMatrixBase< OtherDerived > &other) const
 
template<typename OtherDerived >
Scalar dot (const SparseMatrixBase< OtherDerived > &other) const
 
const internal::eval< Derived >::type eval () const
 
Index innerSize () const
 
template<typename OtherDerived >
bool isApprox (const MatrixBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
 
template<typename OtherDerived >
bool isApprox (const SparseMatrixBase< OtherDerived > &other, const RealScalar &prec=NumTraits< Scalar >::dummy_precision()) const
 
bool isRValue () const
 
bool isVector () const
 
Derived & markAsRValue ()
 
RealScalar norm () const
 
template<typename OtherDerived >
const Product< Derived, OtherDerived > operator* (const DiagonalBase< OtherDerived > &other) const
 
template<typename OtherDerived >
const Product< Derived, OtherDerived > operator* (const MatrixBase< OtherDerived > &other) const
 
template<typename OtherDerived >
const Product< Derived, OtherDerived, AliasFreeProductoperator* (const SparseMatrixBase< OtherDerived > &other) const
 
Derived & operator*= (const Scalar &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 EigenBase< 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 EigenBase< OtherDerived > &other)
 
template<typename OtherDerived >
Derived & operator-= (const SparseMatrixBase< OtherDerived > &other)
 
Derived & operator/= (const Scalar &other)
 
Derived & operator= (const Derived &other)
 
template<typename OtherDerived >
Derived & operator= (const EigenBase< OtherDerived > &other)
 
template<typename OtherDerived >
Derived & operator= (const ReturnByValue< OtherDerived > &other)
 
template<typename OtherDerived >
Derived & operator= (const SparseMatrixBase< OtherDerived > &other)
 
Index outerSize () const
 
const SparseView< Derived > pruned (const Scalar &reference=Scalar(0), const RealScalar &epsilon=NumTraits< Scalar >::dummy_precision()) const
 
Index rows () const
 
template<unsigned int UpLo>
SelfAdjointViewReturnType< UpLo >::Type selfadjointView ()
 
template<unsigned int UpLo>
SparseMatrixBase< Derived >::template SelfAdjointViewReturnType< UpLo >::Type selfadjointView ()
 
template<unsigned int UpLo>
ConstSelfAdjointViewReturnType< UpLo >::Type selfadjointView () const
 
template<unsigned int UpLo>
SparseMatrixBase< Derived >::template ConstSelfAdjointViewReturnType< UpLo >::Type selfadjointView () const
 
Index size () const
 
 SparseMatrixBase ()
 
RealScalar squaredNorm () const
 
Scalar sum () const
 
DenseMatrixType toDense () const
 
TransposeReturnType transpose ()
 
const ConstTransposeReturnType transpose () const
 
template<int Mode>
const TriangularView< const Derived, Mode > triangularView () const
 
SparseSymmetricPermutationProduct< Derived, Upper|LowertwistedBy (const PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm) const
 
- Public Member Functions inherited from Eigen::EigenBase< Derived >
template<typename Dest >
void addTo (Dest &dst) const
 
template<typename Dest >
void applyThisOnTheLeft (Dest &dst) const
 
template<typename Dest >
void applyThisOnTheRight (Dest &dst) const
 
EIGEN_CONSTEXPR Index cols () const EIGEN_NOEXCEPT
 
Derived & const_cast_derived () const
 
const Derived & const_derived () const
 
Derived & derived ()
 
const Derived & derived () const
 
template<typename Dest >
void evalTo (Dest &dst) const
 
EIGEN_CONSTEXPR Index rows () const EIGEN_NOEXCEPT
 
EIGEN_CONSTEXPR Index size () const EIGEN_NOEXCEPT
 
template<typename Dest >
void subTo (Dest &dst) const
 

Protected Types

typedef Base::IndexVector IndexVector
 

Protected Member Functions

Eigen::Map< IndexVectorinnerNonZeros ()
 
const Eigen::Map< const IndexVectorinnerNonZeros () const
 
internal::LowerBoundIndex lower_bound (Index row, Index col) const
 
 SparseCompressedBase ()
 
- Protected Member Functions inherited from Eigen::SparseMatrixBase< Derived >
template<typename OtherDerived >
Derived & assign (const OtherDerived &other)
 
template<typename OtherDerived >
void assignGeneric (const OtherDerived &other)
 

Private Member Functions

template<typename OtherDerived >
 SparseCompressedBase (const SparseCompressedBase< OtherDerived > &)
 

Additional Inherited Members

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

Detailed Description

template<typename Derived>
class Eigen::SparseCompressedBase< Derived >

Common base class for sparse [compressed]-{row|column}-storage format.

This class defines the common interface for all derived classes implementing the compressed sparse storage format, such as:

Definition at line 41 of file SparseCompressedBase.h.

Member Typedef Documentation

◆ Base

template<typename Derived >
typedef SparseMatrixBase<Derived> Eigen::SparseCompressedBase< Derived >::Base

Definition at line 45 of file SparseCompressedBase.h.

◆ IndexVector

template<typename Derived >
typedef Base::IndexVector Eigen::SparseCompressedBase< Derived >::IndexVector
protected

Definition at line 54 of file SparseCompressedBase.h.

Constructor & Destructor Documentation

◆ SparseCompressedBase() [1/2]

template<typename Derived >
Eigen::SparseCompressedBase< Derived >::SparseCompressedBase ( )
inlineprotected

Default constructor. Do nothing.

Definition at line 169 of file SparseCompressedBase.h.

169 {}

◆ SparseCompressedBase() [2/2]

template<typename Derived >
template<typename OtherDerived >
Eigen::SparseCompressedBase< Derived >::SparseCompressedBase ( const SparseCompressedBase< OtherDerived > &  )
explicitprivate

Member Function Documentation

◆ coeffs() [1/2]

template<typename Derived >
Map<Array<Scalar,Dynamic,1> > Eigen::SparseCompressedBase< Derived >::coeffs ( )
inline
Returns
a read-write view of the stored coefficients as a 1D array expression
Warning
this method is for compressed storage only, and it will trigger an assertion otherwise.

Here is an example:

SparseMatrix<double> A(3,3);
A.insert(1,2) = 0;
A.insert(0,1) = 1;
A.insert(2,0) = 2;
A.makeCompressed();
cout << "The matrix A is:" << endl << MatrixXd(A) << endl;
cout << "it has " << A.nonZeros() << " stored non zero coefficients that are: " << A.coeffs().transpose() << endl;
A.coeffs() += 10;
cout << "After adding 10 to every stored non zero coefficient, the matrix A is:" << endl << MatrixXd(A) << endl;
MatrixXcf A
Matrix< double, Dynamic, Dynamic > MatrixXd
Dynamic×Dynamic matrix of type double.
Definition: Matrix.h:502

and the output is:

The matrix A is:
0 1 0
0 0 0
2 0 0
it has 3 stored non zero coefficients that are: 2 1 0
After adding 10 to every stored non zero coefficient, the matrix A is:
0 11 0
0 0 10
12 0 0
See also
valuePtr(), isCompressed()

Definition at line 131 of file SparseCompressedBase.h.

◆ coeffs() [2/2]

template<typename Derived >
const Map<const Array<Scalar,Dynamic,1> > Eigen::SparseCompressedBase< Derived >::coeffs ( ) const
inline
Returns
a read-only view of the stored coefficients as a 1D array expression.
Warning
this method is for compressed storage only, and it will trigger an assertion otherwise.
See also
valuePtr(), isCompressed()

Definition at line 119 of file SparseCompressedBase.h.

◆ innerIndexPtr() [1/2]

template<typename Derived >
StorageIndex* Eigen::SparseCompressedBase< Derived >::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()

Definition at line 89 of file SparseCompressedBase.h.

89 { return derived().innerIndexPtr(); }
Derived & derived()
Definition: EigenBase.h:48

◆ innerIndexPtr() [2/2]

template<typename Derived >
const StorageIndex* Eigen::SparseCompressedBase< Derived >::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()

Definition at line 85 of file SparseCompressedBase.h.

85 { return derived().innerIndexPtr(); }

◆ innerIndicesAreSorted() [1/2]

template<typename Derived >
template<class Comp = std::less<>>
Index Eigen::SparseCompressedBase< Derived >::innerIndicesAreSorted ( ) const
inline
Returns
the index of the first inner vector in the range [0,outerSize) that is not sorted with respect to Comp, or outerSize if the range is fully sorted
See also
sortInnerIndices()

Definition at line 161 of file SparseCompressedBase.h.

161  {
162  Index begin = 0;
163  Index end = derived().outerSize();
164  return internal::inner_sort_impl<Derived, Comp, IsVectorAtCompileTime>::check(*this, begin, end);
165  }
static const lastp1_t end
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41

◆ innerIndicesAreSorted() [2/2]

template<typename Derived >
template<class Comp = std::less<>>
Index Eigen::SparseCompressedBase< Derived >::innerIndicesAreSorted ( Index  begin,
Index  end 
) const
inline
Returns
the index of the first inner vector in the range [begin,end) that is not sorted with respect to Comp, or end if the range is fully sorted
See also
sortInnerIndices()

Definition at line 144 of file SparseCompressedBase.h.

144  {
145  eigen_assert(begin >= 0 && end <= derived().outerSize() && end >= begin);
146  return internal::inner_sort_impl<Derived, Comp, IsVectorAtCompileTime>::check(*this, begin, end);
147  }

◆ innerNonZeroPtr() [1/2]

template<typename Derived >
StorageIndex* Eigen::SparseCompressedBase< Derived >::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

Definition at line 109 of file SparseCompressedBase.h.

109 { return derived().innerNonZeroPtr(); }

◆ innerNonZeroPtr() [2/2]

template<typename Derived >
const StorageIndex* Eigen::SparseCompressedBase< Derived >::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

Definition at line 105 of file SparseCompressedBase.h.

105 { return derived().innerNonZeroPtr(); }

◆ innerNonZeros() [1/2]

template<typename Derived >
Eigen::Map<IndexVector> Eigen::SparseCompressedBase< Derived >::innerNonZeros ( )
inlineprotected

Definition at line 55 of file SparseCompressedBase.h.

A matrix or vector expression mapping an existing array of data.
Definition: Map.h:98
const StorageIndex * innerNonZeroPtr() const

◆ innerNonZeros() [2/2]

template<typename Derived >
const Eigen::Map<const IndexVector> Eigen::SparseCompressedBase< Derived >::innerNonZeros ( ) const
inlineprotected

Definition at line 56 of file SparseCompressedBase.h.

◆ isCompressed()

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

Definition at line 112 of file SparseCompressedBase.h.

112 { return innerNonZeroPtr()==0; }

◆ lower_bound()

template<typename Derived >
internal::LowerBoundIndex Eigen::SparseCompressedBase< Derived >::lower_bound ( Index  row,
Index  col 
) const
inlineprotected

Definition at line 174 of file SparseCompressedBase.h.

175  {
176  eigen_internal_assert(row>=0 && row<this->rows() && col>=0 && col<this->cols());
177 
178  const Index outer = Derived::IsRowMajor ? row : col;
179  const Index inner = Derived::IsRowMajor ? col : row;
180 
181  Index start = this->outerIndexPtr()[outer];
182  Index end = this->isCompressed() ? this->outerIndexPtr()[outer+1] : this->outerIndexPtr()[outer] + this->innerNonZeroPtr()[outer];
183  eigen_assert(end>=start && "you are using a non finalized sparse matrix or written coefficient does not exist");
184  internal::LowerBoundIndex p;
185  p.value = std::lower_bound(this->innerIndexPtr()+start, this->innerIndexPtr()+end,inner) - this->innerIndexPtr();
186  p.found = (p.value<end) && (this->innerIndexPtr()[p.value]==inner);
187  return p;
188  }
RowXpr row(Index i)
This is the const version of row(). *‍/.
ColXpr col(Index i)
This is the const version of col().
#define eigen_internal_assert(x)
Definition: Macros.h:908
float * p
const StorageIndex * outerIndexPtr() const
const StorageIndex * innerIndexPtr() const

◆ nonZeros()

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

Definition at line 61 of file SparseCompressedBase.h.

62  {
63  if (Derived::IsVectorAtCompileTime && outerIndexPtr() == 0)
64  return derived().nonZeros();
65  else if (derived().outerSize() == 0)
66  return 0;
67  else if (isCompressed())
68  return outerIndexPtr()[derived().outerSize()] - outerIndexPtr()[0];
69  else
70  return innerNonZeros().sum();
71  }
Eigen::Map< IndexVector > innerNonZeros()

◆ operator=() [1/4]

template<typename Derived >
Derived & Eigen::SparseMatrixBase< Derived >::operator=
inline

Definition at line 206 of file SparseAssign.h.

46 {
47  internal::call_assignment_no_alias(derived(), other.derived());
48  return derived();
49 }
EIGEN_CONSTEXPR void call_assignment_no_alias(Dst &dst, const Src &src, const Func &func)

◆ operator=() [2/4]

template<typename Derived >
template<typename OtherDerived >
Derived & Eigen::SparseMatrixBase< Derived >::operator= ( typename OtherDerived  )

Definition at line 57 of file SparseAssign.h.

20 {
21  internal::call_assignment_no_alias(derived(), other.derived());
22  return derived();
23 }

◆ operator=() [3/4]

template<typename Derived >
template<typename OtherDerived >
Derived & Eigen::SparseMatrixBase< Derived >::operator= ( typename OtherDerived  )

Definition at line 201 of file SparseAssign.h.

28 {
29  // TODO use the evaluator mechanism
30  other.evalTo(derived());
31  return derived();
32 }

◆ operator=() [4/4]

template<typename Derived >
template<typename OtherDerived >
Derived & Eigen::SparseMatrixBase< Derived >::operator= ( typename OtherDerived  )
inline

Definition at line 204 of file SparseAssign.h.

37 {
38  // by default sparse evaluation do not alias, so we can safely bypass the generic call_assignment routine
39  internal::Assignment<Derived,OtherDerived,internal::assign_op<Scalar,typename OtherDerived::Scalar> >
40  ::run(derived(), other.derived(), internal::assign_op<Scalar,typename OtherDerived::Scalar>());
41  return derived();
42 }

◆ outerIndexPtr() [1/2]

template<typename Derived >
StorageIndex* Eigen::SparseCompressedBase< Derived >::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.
Warning
it returns the null pointer 0 for SparseVector
See also
valuePtr(), innerIndexPtr()

Definition at line 100 of file SparseCompressedBase.h.

100 { return derived().outerIndexPtr(); }

◆ outerIndexPtr() [2/2]

template<typename Derived >
const StorageIndex* Eigen::SparseCompressedBase< Derived >::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.
Warning
it returns the null pointer 0 for SparseVector
See also
valuePtr(), innerIndexPtr()

Definition at line 95 of file SparseCompressedBase.h.

95 { return derived().outerIndexPtr(); }

◆ sortInnerIndices() [1/2]

template<typename Derived >
template<class Comp = std::less<>>
void Eigen::SparseCompressedBase< Derived >::sortInnerIndices ( )
inline

sorts the inner vectors in the range [0,outerSize) with respect to Comp

See also
innerIndicesAreSorted()

Definition at line 152 of file SparseCompressedBase.h.

152  {
153  Index begin = 0;
154  Index end = derived().outerSize();
155  internal::inner_sort_impl<Derived, Comp, IsVectorAtCompileTime>::run(*this, begin, end);
156  }

◆ sortInnerIndices() [2/2]

template<typename Derived >
template<class Comp = std::less<>>
void Eigen::SparseCompressedBase< Derived >::sortInnerIndices ( Index  begin,
Index  end 
)
inline

sorts the inner vectors in the range [begin,end) with respect to Comp

See also
innerIndicesAreSorted()

Definition at line 136 of file SparseCompressedBase.h.

136  {
137  eigen_assert(begin >= 0 && end <= derived().outerSize() && end >= begin);
138  internal::inner_sort_impl<Derived, Comp, IsVectorAtCompileTime>::run(*this, begin, end);
139  }

◆ valuePtr() [1/2]

template<typename Derived >
Scalar* Eigen::SparseCompressedBase< Derived >::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()

Definition at line 80 of file SparseCompressedBase.h.

80 { return derived().valuePtr(); }

◆ valuePtr() [2/2]

template<typename Derived >
const Scalar* Eigen::SparseCompressedBase< Derived >::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()

Definition at line 76 of file SparseCompressedBase.h.

76 { return derived().valuePtr(); }

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