Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
SparseUtil.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2014 Gael Guennebaud <[email protected]>
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
16namespace 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
41const int CoherentAccessPattern = 0x1;
42const int InnerRandomAccessPattern = 0x2 | CoherentAccessPattern;
43const int OuterRandomAccessPattern = 0x4 | CoherentAccessPattern;
44const int RandomAccessPattern = 0x8 | OuterRandomAccessPattern | InnerRandomAccessPattern;
45
46template <typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
48template <typename Scalar_, int Flags_ = 0, typename StorageIndex_ = int>
49class SparseVector;
50
51template <typename MatrixType, unsigned int UpLo>
53template <typename Lhs, typename Rhs>
54class SparseDiagonalProduct;
55template <typename MatrixType>
56class SparseView;
57
58template <typename Lhs, typename Rhs>
59class SparseSparseProduct;
60template <typename Lhs, typename Rhs>
61class SparseTimeDenseProduct;
62template <typename Lhs, typename Rhs>
63class DenseTimeSparseProduct;
64template <typename Lhs, typename Rhs, bool Transpose>
65class SparseDenseOuterProduct;
66
67template <typename Lhs, typename Rhs>
68struct SparseSparseProductReturnType;
69template <typename Lhs, typename Rhs,
70 int InnerSize = internal::min_size_prefer_fixed(internal::traits<Lhs>::ColsAtCompileTime,
71 internal::traits<Rhs>::RowsAtCompileTime)>
72struct DenseSparseProductReturnType;
73
74template <typename Lhs, typename Rhs,
75 int InnerSize = internal::min_size_prefer_fixed(internal::traits<Lhs>::ColsAtCompileTime,
76 internal::traits<Rhs>::RowsAtCompileTime)>
77struct SparseDenseProductReturnType;
78template <typename MatrixType, int UpLo>
79class SparseSymmetricPermutationProduct;
80
81namespace internal {
82
83template <typename T, int Rows, int Cols, int Flags>
84struct sparse_eval;
85
86template <typename T>
87struct eval<T, Sparse> : sparse_eval<T, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime, traits<T>::Flags> {
88};
89
90template <typename T, int Cols, int Flags>
91struct sparse_eval<T, 1, Cols, Flags> {
92 typedef typename traits<T>::Scalar Scalar_;
93 typedef typename traits<T>::StorageIndex StorageIndex_;
94
95 public:
97};
98
99template <typename T, int Rows, int Flags>
100struct sparse_eval<T, Rows, 1, Flags> {
101 typedef typename traits<T>::Scalar Scalar_;
102 typedef typename traits<T>::StorageIndex StorageIndex_;
103
104 public:
105 typedef SparseVector<Scalar_, ColMajor, StorageIndex_> type;
106};
107
108// TODO this seems almost identical to plain_matrix_type<T, Sparse>
109template <typename T, int Rows, int Cols, int Flags>
110struct sparse_eval {
111 typedef typename traits<T>::Scalar Scalar_;
112 typedef typename traits<T>::StorageIndex StorageIndex_;
113 enum { Options_ = ((Flags & RowMajorBit) == RowMajorBit) ? RowMajor : ColMajor };
114
115 public:
116 typedef SparseMatrix<Scalar_, Options_, StorageIndex_> type;
117};
118
119template <typename T, int Flags>
120struct sparse_eval<T, 1, 1, Flags> {
121 typedef typename traits<T>::Scalar Scalar_;
122
123 public:
124 typedef Matrix<Scalar_, 1, 1> type;
125};
126
127template <typename T>
128struct plain_matrix_type<T, Sparse> {
129 typedef typename traits<T>::Scalar Scalar_;
130 typedef typename traits<T>::StorageIndex StorageIndex_;
131 enum { Options_ = ((evaluator<T>::Flags & RowMajorBit) == RowMajorBit) ? RowMajor : ColMajor };
132
133 public:
134 typedef SparseMatrix<Scalar_, Options_, StorageIndex_> type;
135};
136
137template <typename T>
138struct plain_object_eval<T, Sparse>
139 : sparse_eval<T, traits<T>::RowsAtCompileTime, traits<T>::ColsAtCompileTime, evaluator<T>::Flags> {};
140
141template <typename Decomposition, typename RhsType>
142struct solve_traits<Decomposition, RhsType, Sparse> {
143 typedef typename sparse_eval<RhsType, RhsType::RowsAtCompileTime, RhsType::ColsAtCompileTime,
144 traits<RhsType>::Flags>::type PlainObject;
145};
146
147template <typename Derived>
148struct generic_xpr_base<Derived, MatrixXpr, Sparse> {
149 typedef SparseMatrixBase<Derived> type;
150};
151
152struct SparseTriangularShape {
153 static std::string debugName() { return "SparseTriangularShape"; }
154};
155struct SparseSelfAdjointShape {
156 static std::string debugName() { return "SparseSelfAdjointShape"; }
157};
158
159template <>
160struct glue_shapes<SparseShape, SelfAdjointShape> {
161 typedef SparseSelfAdjointShape type;
162};
163template <>
164struct glue_shapes<SparseShape, TriangularShape> {
165 typedef SparseTriangularShape type;
166};
167
168// return type of SparseCompressedBase::lower_bound;
169struct LowerBoundIndex {
170 LowerBoundIndex() : value(-1), found(false) {}
171 LowerBoundIndex(Index val, bool ok) : value(val), found(ok) {}
172 Index value;
173 bool found;
174};
175
176} // end namespace internal
177
186template <typename Scalar, typename StorageIndex = typename SparseMatrix<Scalar>::StorageIndex>
187class 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;
204 Scalar m_value;
205};
206
207} // end namespace Eigen
208
209#endif // EIGEN_SPARSEUTIL_H
A versatible sparse matrix representation.
Definition SparseUtil.h:47
Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix.
Definition SparseUtil.h:52
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
A small structure to hold a non zero as a triplet (i,j,value).
Definition SparseUtil.h:187
const StorageIndex & col() const
Definition SparseUtil.h:197
const Scalar & value() const
Definition SparseUtil.h:200
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
Namespace containing all symbols from the Eigen library.
Definition Core:137
Definition Constants.h:519