10#ifndef EIGEN_SPARSEMATRIXBASE_H
11#define EIGEN_SPARSEMATRIXBASE_H
14#include "./InternalHeaderCheck.h"
29template <
typename Derived>
32 typedef typename internal::traits<Derived>::Scalar Scalar;
39 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
40 typedef typename internal::traits<Derived>::StorageKind StorageKind;
44 typedef typename internal::traits<Derived>::StorageIndex
StorageIndex;
46 typedef typename internal::add_const_on_value_type_if_arithmetic<typename internal::packet_traits<Scalar>::type>::type
49 typedef SparseMatrixBase StorageBaseType;
54 template <
typename OtherDerived>
79 MaxSizeAtCompileTime = internal::size_at_compile_time(MaxRowsAtCompileTime, MaxColsAtCompileTime),
94 Flags = internal::traits<Derived>::Flags,
105#ifndef EIGEN_PARSED_BY_DOXYGEN
111 typedef std::conditional_t<NumTraits<Scalar>::IsComplex,
129#ifndef EIGEN_PARSED_BY_DOXYGEN
132 typedef std::conditional_t<HasDirectAccess_, const Scalar&, Scalar> CoeffReturnType;
144 inline const Derived&
derived()
const {
return *
static_cast<const Derived*
>(
this); }
145 inline Derived&
derived() {
return *
static_cast<Derived*
>(
this); }
146 inline Derived& const_cast_derived()
const {
return *
static_cast<Derived*
>(
const_cast<SparseMatrixBase*
>(
this)); }
152#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::SparseMatrixBase
153#ifdef EIGEN_PARSED_BY_DOXYGEN
154#define EIGEN_DOC_UNARY_ADDONS(METHOD, \
157#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
160#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF( \
164#define EIGEN_DOC_UNARY_ADDONS(X, Y)
165#define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
166#define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND)
168#include "../plugins/CommonCwiseUnaryOps.inc"
169#include "../plugins/CommonCwiseBinaryOps.inc"
170#include "../plugins/MatrixCwiseUnaryOps.inc"
171#include "../plugins/MatrixCwiseBinaryOps.inc"
172#include "../plugins/BlockMethods.inc"
173#ifdef EIGEN_SPARSEMATRIXBASE_PLUGIN
174#include EIGEN_SPARSEMATRIXBASE_PLUGIN
176#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
177#undef EIGEN_DOC_UNARY_ADDONS
178#undef EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL
179#undef EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF
200 bool isRValue()
const {
return m_isRValue; }
201 Derived& markAsRValue() {
206 SparseMatrixBase() : m_isRValue(false) {
209 template <
typename OtherDerived>
210 Derived& operator=(
const ReturnByValue<OtherDerived>& other);
212 template <
typename OtherDerived>
213 inline Derived& operator=(
const SparseMatrixBase<OtherDerived>& other);
215 inline Derived& operator=(
const Derived& other);
218 template <
typename OtherDerived>
219 inline Derived& assign(
const OtherDerived& other);
221 template <
typename OtherDerived>
222 inline void assignGeneric(
const OtherDerived& other);
226 friend std::ostream& operator<<(std::ostream& s,
const SparseMatrixBase& m) {
227 using Nested =
typename Derived::Nested;
228 using NestedCleaned =
typename internal::remove_all<Nested>::type;
232 internal::evaluator<NestedCleaned> thisEval(nm);
235 std::size_t width = 0;
237 std::ostringstream ss0;
240 width = ss0.str().size();
242 for (
typename internal::evaluator<NestedCleaned>::InnerIterator it(thisEval,
row); it; ++it) {
243 std::ostringstream ss;
247 const std::size_t potential_width = ss.str().size();
248 if (potential_width > width) width = potential_width;
255 for (
typename internal::evaluator<NestedCleaned>::InnerIterator it(thisEval,
row); it; ++it) {
256 for (;
col < it.index(); ++
col) {
258 s << Scalar(0) <<
" ";
261 s << it.value() <<
" ";
272 internal::evaluator<NestedCleaned> thisEval(nm);
275 std::size_t width = 0;
277 std::ostringstream ss0;
280 width = ss0.str().size();
281 for (
typename internal::evaluator<NestedCleaned>::InnerIterator it(thisEval, 0); it; ++it) {
282 std::ostringstream ss;
286 const std::size_t potential_width = ss.str().size();
287 if (potential_width > width) width = potential_width;
292 for (
typename internal::evaluator<NestedCleaned>::InnerIterator it(thisEval, 0); it; ++it) {
293 for (;
row < it.index(); ++
row) {
295 s << Scalar(0) << std::endl;
298 s << it.value() << std::endl;
303 s << Scalar(0) << std::endl;
306 SparseMatrix<Scalar, RowMajorBit, StorageIndex> trans = m;
307 s << static_cast<const SparseMatrixBase<SparseMatrix<Scalar, RowMajorBit, StorageIndex> >&>(trans);
314 template <
typename OtherDerived>
315 Derived& operator+=(
const SparseMatrixBase<OtherDerived>& other);
316 template <
typename OtherDerived>
317 Derived& operator-=(
const SparseMatrixBase<OtherDerived>& other);
319 template <
typename OtherDerived>
320 Derived& operator+=(
const DiagonalBase<OtherDerived>& other);
321 template <
typename OtherDerived>
324 template <
typename OtherDerived>
326 template <
typename OtherDerived>
329 Derived& operator*=(
const Scalar& other);
330 Derived& operator/=(
const Scalar& other);
332 template <
typename OtherDerived>
333 struct CwiseProductDenseReturnType {
336 typename internal::traits<Derived>::Scalar,
typename internal::traits<OtherDerived>::Scalar>
::ReturnType>,
337 const Derived,
const OtherDerived>
341 template <
typename OtherDerived>
342 EIGEN_STRONG_INLINE
const typename CwiseProductDenseReturnType<OtherDerived>::Type
cwiseProduct(
346 template <
typename OtherDerived>
352 template <
typename OtherDerived>
354 const SparseMatrixBase& rhs) {
359 template <
typename OtherDerived>
363 template <
typename OtherDerived>
369 template <
typename OtherDerived>
376 SparseSymmetricPermutationProduct<Derived, Upper | Lower>
twistedBy(
378 return SparseSymmetricPermutationProduct<Derived, Upper | Lower>(
derived(), perm);
381 template <
typename OtherDerived>
387 template <
unsigned int UpLo>
388 struct SelfAdjointViewReturnType {
391 template <
unsigned int UpLo>
392 struct ConstSelfAdjointViewReturnType {
396 template <
unsigned int UpLo>
397 inline typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView()
const;
398 template <
unsigned int UpLo>
399 inline typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView();
401 template <
typename OtherDerived>
402 Scalar dot(
const MatrixBase<OtherDerived>& other)
const;
403 template <
typename OtherDerived>
404 Scalar dot(
const SparseMatrixBase<OtherDerived>& other)
const;
405 RealScalar squaredNorm()
const;
409 TransposeReturnType transpose() {
return TransposeReturnType(
derived()); }
410 const ConstTransposeReturnType transpose()
const {
return ConstTransposeReturnType(
derived()); }
411 const AdjointReturnType adjoint()
const {
return AdjointReturnType(transpose()); }
413 DenseMatrixType toDense()
const {
return DenseMatrixType(
derived()); }
415 template <
typename OtherDerived>
416 bool isApprox(
const SparseMatrixBase<OtherDerived>& other,
417 const RealScalar& prec = NumTraits<Scalar>::dummy_precision())
const;
419 template <
typename OtherDerived>
420 bool isApprox(
const MatrixBase<OtherDerived>& other,
421 const RealScalar& prec = NumTraits<Scalar>::dummy_precision())
const {
422 return toDense().isApprox(other, prec);
430 inline const typename internal::eval<Derived>::type
eval()
const {
431 return typename internal::eval<Derived>::type(
derived());
437 const RealScalar& epsilon = NumTraits<Scalar>::dummy_precision())
const;
442 static inline StorageIndex convert_index(
const Index idx) {
return internal::convert_index<StorageIndex>(idx); }
445 template <
typename Dest>
446 void evalTo(Dest&)
const;
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:79
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:64
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition CwiseUnaryOp.h:53
Base class for diagonal matrices and expressions.
Definition DiagonalMatrix.h:33
const Derived & derived() const
Definition DiagonalMatrix.h:57
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:186
Permutation matrix.
Definition PermutationMatrix.h:283
Base class of any sparse matrices or sparse expressions.
Definition SparseMatrixBase.h:30
internal::traits< BlockType >::StorageIndex StorageIndex
Definition SparseMatrixBase.h:44
Index size() const
Definition SparseMatrixBase.h:187
Index innerSize() const
Definition SparseMatrixBase.h:198
Index rows() const
Definition SparseMatrixBase.h:182
bool isVector() const
Definition SparseMatrixBase.h:192
RowXpr row(Index i)
Definition SparseMatrixBase.h:1085
const Product< Derived, OtherDerived, AliasFreeProduct > operator*(const SparseMatrixBase< OtherDerived > &other) const
Definition SparseProduct.h:31
const CwiseBinaryOp< internal::scalar_product_op< Derived ::Scalar, OtherDerived ::Scalar >, const Derived, const OtherDerived > cwiseProduct(const Eigen::SparseMatrixBase< OtherDerived > &other) const
Definition SparseMatrixBase.h:23
NumTraits< Scalar >::Real RealScalar
Definition SparseMatrixBase.h:127
Scalar value_type
Definition SparseMatrixBase.h:37
Index outerSize() const
Definition SparseMatrixBase.h:195
const SparseView< Derived > pruned(const Scalar &reference=Scalar(0), const RealScalar &epsilon=NumTraits< Scalar >::dummy_precision()) const
Definition SparseView.h:219
Index cols() const
Definition SparseMatrixBase.h:184
SparseSymmetricPermutationProduct< Derived, Upper|Lower > twistedBy(const PermutationMatrix< Dynamic, Dynamic, StorageIndex > &perm) const
Definition SparseMatrixBase.h:376
ColXpr col(Index i)
Definition SparseMatrixBase.h:1072
const internal::eval< Derived >::type eval() const
Definition SparseMatrixBase.h:430
@ IsVectorAtCompileTime
Definition SparseMatrixBase.h:81
@ NumDimensions
Definition SparseMatrixBase.h:87
@ ColsAtCompileTime
Definition SparseMatrixBase.h:65
@ Flags
Definition SparseMatrixBase.h:94
@ RowsAtCompileTime
Definition SparseMatrixBase.h:59
@ SizeAtCompileTime
Definition SparseMatrixBase.h:71
A versatible sparse matrix representation.
Definition SparseMatrix.h:121
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition SparseSelfAdjointView.h:52
Expression of a dense or sparse matrix with zero or too small values removed.
Definition SparseView.h:45
Expression of the transpose of a matrix.
Definition Transpose.h:56
Expression of a triangular part in a matrix.
Definition TriangularMatrix.h:167
const unsigned int DirectAccessBit
Definition Constants.h:159
const unsigned int RowMajorBit
Definition Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
const Product< MatrixDerived, PermutationDerived, DefaultProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition PermutationMatrix.h:474
Definition EigenBase.h:33
constexpr Derived & derived()
Definition EigenBase.h:49
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:43
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition XprHelper.h:1047