SparseUtil.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_SPARSEUTIL_H
11 #define EIGEN_SPARSEUTIL_H
12 
13 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 #ifdef NDEBUG
19 #define EIGEN_DBG_SPARSE(X)
20 #else
21 #define EIGEN_DBG_SPARSE(X) X
22 #endif
23 
24 #define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \
25  template <typename OtherDerived> \
26  EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::SparseMatrixBase<OtherDerived>& other) { \
27  return Base::operator Op(other.derived()); \
28  } \
29  EIGEN_STRONG_INLINE Derived& operator Op(const Derived & other) { return Base::operator Op(other); }
30 
31 #define EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \
32  template <typename Other> \
33  EIGEN_STRONG_INLINE Derived& operator Op(const Other & scalar) { \
34  return Base::operator Op(scalar); \
35  }
36 
37 #define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATORS(Derived) EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =)
38 
39 #define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
40 
41 const int CoherentAccessPattern = 0x1;
45 
46 template <typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
47 class SparseMatrix;
48 template <typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
49 class SparseVector;
50 
51 template <typename MatrixType, unsigned int UpLo>
53 template <typename Lhs, typename Rhs>
55 template <typename MatrixType>
56 class SparseView;
57 
58 template <typename Lhs, typename Rhs>
60 template <typename Lhs, typename Rhs>
62 template <typename Lhs, typename Rhs>
64 template <typename Lhs, typename Rhs, bool Transpose>
66 
67 template <typename Lhs, typename Rhs>
69 template <typename Lhs, typename Rhs,
73 
74 template <typename Lhs, typename Rhs,
78 template <typename MatrixType, int UpLo>
80 
81 namespace internal {
82 
83 template <typename T, int Rows, int Cols, int Flags>
84 struct sparse_eval;
85 
86 template <typename T>
87 struct eval<T, Sparse> : sparse_eval<T, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime, traits<T>::Flags> {
88 };
89 
90 template <typename T, int Cols, int Flags>
91 struct sparse_eval<T, 1, Cols, Flags> {
92  typedef typename traits<T>::Scalar Scalar_;
94 
95  public:
97 };
98 
99 template <typename T, int Rows, int Flags>
100 struct sparse_eval<T, Rows, 1, Flags> {
101  typedef typename traits<T>::Scalar Scalar_;
103 
104  public:
106 };
107 
108 // TODO this seems almost identical to plain_matrix_type<T, Sparse>
109 template <typename T, int Rows, int Cols, int Flags>
110 struct sparse_eval {
111  typedef typename traits<T>::Scalar Scalar_;
114 
115  public:
117 };
118 
119 template <typename T, int Flags>
120 struct sparse_eval<T, 1, 1, Flags> {
121  typedef typename traits<T>::Scalar Scalar_;
122 
123  public:
125 };
126 
127 template <typename T>
129  typedef typename traits<T>::Scalar Scalar_;
131  enum { Options_ = ((evaluator<T>::Flags & RowMajorBit) == RowMajorBit) ? RowMajor : ColMajor };
132 
133  public:
135 };
136 
137 template <typename T>
139  : sparse_eval<T, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime, evaluator<T>::Flags> {};
140 
141 template <typename Decomposition, typename RhsType>
142 struct solve_traits<Decomposition, RhsType, Sparse> {
143  typedef typename sparse_eval<RhsType, RhsType::RowsAtCompileTime, RhsType::ColsAtCompileTime,
145 };
146 
147 template <typename Derived>
148 struct generic_xpr_base<Derived, MatrixXpr, Sparse> {
150 };
151 
153  static std::string debugName() { return "SparseTriangularShape"; }
154 };
156  static std::string debugName() { return "SparseSelfAdjointShape"; }
157 };
158 
159 template <>
162 };
163 template <>
166 };
167 
168 // return type of SparseCompressedBase::lower_bound;
170  LowerBoundIndex() : value(-1), found(false) {}
171  LowerBoundIndex(Index val, bool ok) : value(val), found(ok) {}
173  bool found;
174 };
175 
176 } // end namespace internal
177 
186 template <typename Scalar, typename StorageIndex = typename SparseMatrix<Scalar>::StorageIndex>
187 class Triplet {
188  public:
189  Triplet() : m_row(0), m_col(0), m_value(0) {}
190 
191  Triplet(const StorageIndex& i, const StorageIndex& j, const Scalar& v = Scalar(0)) : m_row(i), m_col(j), m_value(v) {}
192 
194  const StorageIndex& row() const { return m_row; }
195 
197  const StorageIndex& col() const { return m_col; }
198 
200  const Scalar& value() const { return m_value; }
201 
202  protected:
203  StorageIndex m_row, m_col;
205 };
206 
207 } // end namespace Eigen
208 
209 #endif // EIGEN_SPARSEUTIL_H
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
SCALAR Scalar
Definition: bench_gemm.cpp:45
Definition: SparseUtil.h:63
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Definition: SparseUtil.h:65
Definition: SparseUtil.h:54
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:30
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
Definition: SparseUtil.h:59
Definition: SparseSelfAdjointView.h:556
Definition: SparseUtil.h:61
a sparse vector class
Definition: SparseVector.h:62
Expression of a dense or sparse matrix with zero or too small values removed.
Definition: SparseView.h:45
const Scalar & value() const
Definition: SparseUtil.h:200
StorageIndex m_row
Definition: SparseUtil.h:203
const StorageIndex & col() const
Definition: SparseUtil.h:197
Triplet()
Definition: SparseUtil.h:189
StorageIndex m_col
Definition: SparseUtil.h:203
Triplet(const StorageIndex &i, const StorageIndex &j, const Scalar &v=Scalar(0))
Definition: SparseUtil.h:191
Scalar m_value
Definition: SparseUtil.h:204
const StorageIndex & row() const
Definition: SparseUtil.h:194
@ ColMajor
Definition: Constants.h:318
@ RowMajor
Definition: Constants.h:320
const unsigned int RowMajorBit
Definition: Constants.h:70
@ Lhs
Definition: TensorContractionMapper.h:20
@ Rhs
Definition: TensorContractionMapper.h:20
constexpr int min_size_prefer_fixed(A a, B b)
Definition: Meta.h:683
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
const int OuterRandomAccessPattern
Definition: SparseUtil.h:43
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
const int InnerRandomAccessPattern
Definition: SparseUtil.h:42
const int RandomAccessPattern
Definition: SparseUtil.h:44
const int CoherentAccessPattern
Definition: SparseUtil.h:41
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56
val
Definition: calibrate.py:119
type
Definition: compute_granudrum_aor.py:141
Definition: Eigen_Colamd.h:49
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
Definition: SparseUtil.h:72
Definition: Constants.h:534
Definition: Constants.h:561
Definition: SparseUtil.h:77
Definition: Constants.h:570
Definition: SparseUtil.h:68
Definition: Constants.h:522
Definition: Constants.h:558
Definition: SparseUtil.h:169
bool found
Definition: SparseUtil.h:173
LowerBoundIndex(Index val, bool ok)
Definition: SparseUtil.h:171
LowerBoundIndex()
Definition: SparseUtil.h:170
Index value
Definition: SparseUtil.h:172
Definition: SparseUtil.h:155
static std::string debugName()
Definition: SparseUtil.h:156
Definition: SparseUtil.h:152
static std::string debugName()
Definition: SparseUtil.h:153
Definition: XprHelper.h:427
Definition: CoreEvaluators.h:104
SparseMatrixBase< Derived > type
Definition: SparseUtil.h:149
Definition: XprHelper.h:575
SparseSelfAdjointShape type
Definition: SparseUtil.h:161
SparseTriangularShape type
Definition: SparseUtil.h:165
Definition: XprHelper.h:854
traits< T >::StorageIndex StorageIndex_
Definition: SparseUtil.h:130
traits< T >::Scalar Scalar_
Definition: SparseUtil.h:129
SparseMatrix< Scalar_, Options_, StorageIndex_ > type
Definition: SparseUtil.h:134
Definition: XprHelper.h:389
Definition: XprHelper.h:465
sparse_eval< RhsType, RhsType::RowsAtCompileTime, RhsType::ColsAtCompileTime, traits< RhsType >::Flags >::type PlainObject
Definition: SparseUtil.h:144
Definition: Solve.h:37
traits< T >::Scalar Scalar_
Definition: SparseUtil.h:121
Matrix< Scalar_, 1, 1 > type
Definition: SparseUtil.h:124
traits< T >::StorageIndex StorageIndex_
Definition: SparseUtil.h:93
SparseVector< Scalar_, RowMajor, StorageIndex_ > type
Definition: SparseUtil.h:96
traits< T >::Scalar Scalar_
Definition: SparseUtil.h:92
SparseVector< Scalar_, ColMajor, StorageIndex_ > type
Definition: SparseUtil.h:105
traits< T >::StorageIndex StorageIndex_
Definition: SparseUtil.h:102
traits< T >::Scalar Scalar_
Definition: SparseUtil.h:101
Definition: SparseUtil.h:110
SparseMatrix< Scalar_, Options_, StorageIndex_ > type
Definition: SparseUtil.h:116
@ Options_
Definition: SparseUtil.h:113
traits< T >::Scalar Scalar_
Definition: SparseUtil.h:111
traits< T >::StorageIndex StorageIndex_
Definition: SparseUtil.h:112
Definition: ForwardDeclarations.h:21
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2