11#ifndef EIGEN_SPARSEMATRIXBASE_H
12#define EIGEN_SPARSEMATRIXBASE_H
15#include "./InternalHeaderCheck.h"
30template <
typename Derived>
33 using Scalar =
typename internal::traits<Derived>::Scalar;
40 using PacketScalar =
typename internal::packet_traits<Scalar>::type;
41 using StorageKind =
typename internal::traits<Derived>::StorageKind;
45 using StorageIndex =
typename internal::traits<Derived>::StorageIndex;
47 using PacketReturnType = std::conditional_t<internal::is_arithmetic<PacketScalar>::value, PacketScalar,
48 internal::add_const_on_value_type_t<PacketScalar>>;
50 using StorageBaseType = SparseMatrixBase;
55 template <
typename OtherDerived>
80 MaxSizeAtCompileTime = internal::size_at_compile_time(MaxRowsAtCompileTime, MaxColsAtCompileTime),
95 Flags = internal::traits<Derived>::Flags,
106#ifndef EIGEN_PARSED_BY_DOXYGEN
112 using AdjointReturnType =
113 std::conditional_t<NumTraits<Scalar>::IsComplex,
130#ifndef EIGEN_PARSED_BY_DOXYGEN
133 using CoeffReturnType = std::conditional_t<HasDirectAccess_, const Scalar&, Scalar>;
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() {
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 = internal::remove_all_t<Nested>;
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) {
258 s << Scalar(0) <<
" ";
261 s << it.value() <<
" ";
264 for (; col < m.
cols(); ++col) {
266 s << Scalar(0) <<
" ";
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>
322 Derived& operator-=(
const DiagonalBase<OtherDerived>& other);
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>;
340 template <
typename OtherDerived>
341 EIGEN_STRONG_INLINE
const typename CwiseProductDenseReturnType<OtherDerived>::Type
cwiseProduct(
345 template <
typename OtherDerived>
351 template <
typename OtherDerived>
352 friend const Product<OtherDerived, Derived> operator*(
const DiagonalBase<OtherDerived>& lhs,
353 const SparseMatrixBase& rhs) {
354 return Product<OtherDerived, Derived>(lhs.derived(), rhs.derived());
358 template <
typename OtherDerived>
362 template <
typename OtherDerived>
368 template <
typename OtherDerived>
375 SparseSymmetricPermutationProduct<Derived, Upper | Lower>
twistedBy(
377 return SparseSymmetricPermutationProduct<Derived, Upper | Lower>(
derived(), perm);
380 template <
typename OtherDerived>
386 template <
unsigned int UpLo>
387 struct SelfAdjointViewReturnType {
390 template <
unsigned int UpLo>
391 struct ConstSelfAdjointViewReturnType {
392 using Type =
const SparseSelfAdjointView<const Derived, UpLo>;
395 template <
unsigned int UpLo>
396 inline typename ConstSelfAdjointViewReturnType<UpLo>::Type selfadjointView()
const;
397 template <
unsigned int UpLo>
398 inline typename SelfAdjointViewReturnType<UpLo>::Type selfadjointView();
400 template <
typename OtherDerived>
402 template <
typename OtherDerived>
404 RealScalar squaredNorm()
const;
405 RealScalar norm()
const;
406 RealScalar blueNorm()
const;
408 TransposeReturnType transpose() {
return TransposeReturnType(
derived()); }
409 const ConstTransposeReturnType transpose()
const {
return ConstTransposeReturnType(
derived()); }
410 const AdjointReturnType adjoint()
const {
return AdjointReturnType(transpose()); }
412 DenseMatrixType toDense()
const {
return DenseMatrixType(
derived()); }
414 template <
typename OtherDerived>
415 bool isApprox(
const SparseMatrixBase<OtherDerived>& other,
416 const RealScalar& prec = NumTraits<Scalar>::dummy_precision())
const;
418 template <
typename OtherDerived>
419 bool isApprox(
const MatrixBase<OtherDerived>& other,
420 const RealScalar& prec = NumTraits<Scalar>::dummy_precision())
const {
421 return toDense().isApprox(other, prec);
429 inline const typename internal::eval<Derived>::type
eval()
const {
430 return typename internal::eval<Derived>::type(
derived());
436 const RealScalar& epsilon = NumTraits<Scalar>::dummy_precision())
const;
441 static inline StorageIndex convert_index(
const Index idx) {
return internal::convert_index<StorageIndex>(idx); }
444 template <
typename Dest>
445 void evalTo(Dest&)
const;
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:80
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:65
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition CwiseUnaryOp.h:55
Base class for diagonal matrices and expressions.
Definition DiagonalMatrix.h:34
const Derived & derived() const
Definition DiagonalMatrix.h:60
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
Permutation matrix.
Definition PermutationMatrix.h:346
Expression of the product of two arbitrary matrices or vectors.
Definition Product.h:203
Base class of any sparse matrices or sparse expressions.
Definition SparseMatrixBase.h:31
Index size() const
Definition SparseMatrixBase.h:187
Index innerSize() const
Definition SparseMatrixBase.h:198
Index rows() const
Definition SparseMatrixBase.h:182
typename NumTraits< Scalar >::Real RealScalar
Definition SparseMatrixBase.h:128
bool isVector() const
Definition SparseMatrixBase.h:192
Scalar value_type
Definition SparseMatrixBase.h:38
const Product< Derived, OtherDerived, AliasFreeProduct > operator*(const SparseMatrixBase< OtherDerived > &other) const
Definition SparseProduct.h:32
constexpr RowXpr row(Index i)
Definition SparseMatrixBase.h:1094
constexpr const CwiseBinaryOp< internal::scalar_product_op< Derived ::Scalar, OtherDerived ::Scalar >, const Derived, const OtherDerived > cwiseProduct(const Eigen::SparseMatrixBase< OtherDerived > &other) const
Definition SparseMatrixBase.h:25
typename internal::traits< BlockType >::StorageIndex StorageIndex
Definition SparseMatrixBase.h:45
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:375
const internal::eval< Derived >::type eval() const
Definition SparseMatrixBase.h:429
constexpr ColXpr col(Index i)
Definition SparseMatrixBase.h:1081
@ IsVectorAtCompileTime
Definition SparseMatrixBase.h:82
@ NumDimensions
Definition SparseMatrixBase.h:88
@ ColsAtCompileTime
Definition SparseMatrixBase.h:66
@ Flags
Definition SparseMatrixBase.h:95
@ RowsAtCompileTime
Definition SparseMatrixBase.h:60
@ SizeAtCompileTime
Definition SparseMatrixBase.h:72
A versatile sparse matrix representation.
Definition SparseMatrix.h:122
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition SparseSelfAdjointView.h:53
Expression of a dense or sparse matrix with zero or too small values removed.
Definition SparseView.h:46
Expression of the transpose of a matrix.
Definition Transpose.h:57
Expression of a triangular part in a matrix.
Definition TriangularMatrix.h:426
constexpr unsigned int DirectAccessBit
Definition Constants.h:160
constexpr unsigned int RowMajorBit
Definition Constants.h:71
Definition EigenBase.h:34
constexpr Derived & derived()
Definition EigenBase.h:50
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:44
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition XprHelper.h:1062