11#ifndef EIGEN_SPARSEUTIL_H
12#define EIGEN_SPARSEUTIL_H
15#include "./InternalHeaderCheck.h"
20#define EIGEN_DBG_SPARSE(X)
22#define EIGEN_DBG_SPARSE(X) X
25#define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \
26 template <typename OtherDerived> \
27 EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::SparseMatrixBase<OtherDerived>& other) { \
28 return Base::operator Op(other.derived()); \
30 EIGEN_STRONG_INLINE Derived& operator Op(const Derived & other) { return Base::operator Op(other); }
32#define EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \
33 template <typename Other> \
34 EIGEN_STRONG_INLINE Derived& operator Op(const Other & scalar) { \
35 return Base::operator Op(scalar); \
38#define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATORS(Derived) EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =)
40#define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
42const int CoherentAccessPattern = 0x1;
43const int InnerRandomAccessPattern = 0x2 | CoherentAccessPattern;
44const int OuterRandomAccessPattern = 0x4 | CoherentAccessPattern;
45const int RandomAccessPattern = 0x8 | OuterRandomAccessPattern | InnerRandomAccessPattern;
47template <
typename Scalar_,
int Flags_ = 0,
typename StorageIndex_ =
int>
49template <
typename Scalar_,
int Flags_ = 0,
typename StorageIndex_ =
int>
52template <
typename MatrixType,
unsigned int UpLo>
54template <
typename MatrixType>
57template <
typename MatrixType,
int UpLo>
58class SparseSymmetricPermutationProduct;
63template <
typename LhsScalar,
typename RhsScalar,
bool Reverse,
64 bool Commutative = functor_is_commutative<scalar_product_op<LhsScalar, RhsScalar>>::value>
65struct sparse_scalar_product_op {
66 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
auto operator()(
const LhsScalar& lhs,
const RhsScalar& rhs)
const {
70 template <
typename Acc>
71 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void accumulate(Acc& acc,
const LhsScalar& lhs,
const RhsScalar& rhs)
const {
76template <
typename LhsScalar,
typename RhsScalar>
77struct sparse_scalar_product_op<LhsScalar, RhsScalar, true, false> {
78 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
auto operator()(
const LhsScalar& lhs,
const RhsScalar& rhs)
const {
81 template <
typename Acc>
82 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void accumulate(Acc& acc,
const LhsScalar& lhs,
const RhsScalar& rhs)
const {
94template <
typename Derived>
95struct has_compressed_access : bool_constant<(int(traits<Derived>::Flags) & CompressedAccessBit) != 0> {};
98template <typename Scalar, bool = use_scaled_comparison<Scalar>::value>
99struct sparse_approx_comparison;
101template <
typename T,
int Rows,
int Cols,
int Flags>
105struct eval<T, Sparse> : sparse_eval<T, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime, traits<T>::Flags> {
108template <
typename T,
int Cols,
int Flags>
109struct sparse_eval<T, 1, Cols, Flags> {
110 using Scalar_ =
typename traits<T>::Scalar;
111 using StorageIndex_ =
typename traits<T>::StorageIndex;
114 using type = SparseVector<Scalar_, RowMajor, StorageIndex_>;
117template <
typename T,
int Rows,
int Flags>
118struct sparse_eval<T, Rows, 1, Flags> {
119 using Scalar_ =
typename traits<T>::Scalar;
120 using StorageIndex_ =
typename traits<T>::StorageIndex;
123 using type = SparseVector<Scalar_, ColMajor, StorageIndex_>;
127template <
typename T,
int Rows,
int Cols,
int Flags>
129 using Scalar_ =
typename traits<T>::Scalar;
130 using StorageIndex_ =
typename traits<T>::StorageIndex;
134 using type = SparseMatrix<Scalar_, Options_, StorageIndex_>;
137template <
typename T,
int Flags>
138struct sparse_eval<T, 1, 1, Flags> {
139 using Scalar_ =
typename traits<T>::Scalar;
142 using type = Matrix<Scalar_, 1, 1>;
146struct plain_matrix_type<T, Sparse> {
147 using Scalar_ =
typename traits<T>::Scalar;
148 using StorageIndex_ =
typename traits<T>::StorageIndex;
152 using type = SparseMatrix<Scalar_, Options_, StorageIndex_>;
156struct plain_object_eval<T, Sparse>
157 : sparse_eval<T, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime, evaluator<T>::Flags> {};
159template <
typename Decomposition,
typename RhsType>
160struct solve_traits<Decomposition, RhsType, Sparse> {
161 using PlainObject =
typename sparse_eval<RhsType, RhsType::RowsAtCompileTime, RhsType::ColsAtCompileTime,
162 traits<RhsType>::Flags>::type;
165template <
typename Derived>
166struct generic_xpr_base<Derived, MatrixXpr, Sparse> {
167 using type = SparseMatrixBase<Derived>;
170struct SparseTriangularShape {
171 static std::string debugName() {
return "SparseTriangularShape"; }
173struct SparseSelfAdjointShape {
174 static std::string debugName() {
return "SparseSelfAdjointShape"; }
178struct glue_shapes<SparseShape, SelfAdjointShape> {
179 using type = SparseSelfAdjointShape;
182struct glue_shapes<SparseShape, TriangularShape> {
183 using type = SparseTriangularShape;
187struct LowerBoundIndex {
188 LowerBoundIndex() =
default;
189 LowerBoundIndex(Index val,
bool ok) : value(val), found(ok) {}
204template <typename Scalar, typename StorageIndex = typename SparseMatrix<Scalar>::StorageIndex>
209 Triplet(
const StorageIndex& i,
const StorageIndex& j,
const Scalar& v = Scalar(0)) : m_row(i), m_col(j), m_value(v) {}
212 const StorageIndex&
row()
const {
return m_row; }
215 const StorageIndex&
col()
const {
return m_col; }
218 const Scalar&
value()
const {
return m_value; }
221 StorageIndex m_row = 0;
222 StorageIndex m_col = 0;
223 Scalar m_value = Scalar(0);
A versatile sparse matrix representation.
Definition SparseMatrix.h:121
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition SparseSelfAdjointView.h:53
a sparse vector class
Definition SparseVector.h:63
Expression of a dense or sparse matrix with zero or too small values removed.
Definition SparseView.h:46
const StorageIndex & col() const
Definition SparseUtil.h:215
const Scalar & value() const
Definition SparseUtil.h:218
const StorageIndex & row() const
Definition SparseUtil.h:212
@ ColMajor
Definition Constants.h:319
@ RowMajor
Definition Constants.h:321
constexpr unsigned int RowMajorBit
Definition Constants.h:71