1 | // This file is part of Eigen, a lightweight C++ template library
|
---|
2 | // for linear algebra.
|
---|
3 | //
|
---|
4 | // Copyright (C) 2008 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 | namespace Eigen {
|
---|
14 |
|
---|
15 | #ifdef NDEBUG
|
---|
16 | #define EIGEN_DBG_SPARSE(X)
|
---|
17 | #else
|
---|
18 | #define EIGEN_DBG_SPARSE(X) X
|
---|
19 | #endif
|
---|
20 |
|
---|
21 | #define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \
|
---|
22 | template<typename OtherDerived> \
|
---|
23 | EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::SparseMatrixBase<OtherDerived>& other) \
|
---|
24 | { \
|
---|
25 | return Base::operator Op(other.derived()); \
|
---|
26 | } \
|
---|
27 | EIGEN_STRONG_INLINE Derived& operator Op(const Derived& other) \
|
---|
28 | { \
|
---|
29 | return Base::operator Op(other); \
|
---|
30 | }
|
---|
31 |
|
---|
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 | { \
|
---|
36 | return Base::operator Op(scalar); \
|
---|
37 | }
|
---|
38 |
|
---|
39 | #define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
|
---|
40 | EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) \
|
---|
41 | EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, +=) \
|
---|
42 | EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \
|
---|
43 | EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \
|
---|
44 | EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=)
|
---|
45 |
|
---|
46 | #define _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, BaseClass) \
|
---|
47 | typedef BaseClass Base; \
|
---|
48 | typedef typename Eigen::internal::traits<Derived >::Scalar Scalar; \
|
---|
49 | typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
|
---|
50 | typedef typename Eigen::internal::nested<Derived >::type Nested; \
|
---|
51 | typedef typename Eigen::internal::traits<Derived >::StorageKind StorageKind; \
|
---|
52 | typedef typename Eigen::internal::traits<Derived >::Index Index; \
|
---|
53 | enum { RowsAtCompileTime = Eigen::internal::traits<Derived >::RowsAtCompileTime, \
|
---|
54 | ColsAtCompileTime = Eigen::internal::traits<Derived >::ColsAtCompileTime, \
|
---|
55 | Flags = Eigen::internal::traits<Derived >::Flags, \
|
---|
56 | CoeffReadCost = Eigen::internal::traits<Derived >::CoeffReadCost, \
|
---|
57 | SizeAtCompileTime = Base::SizeAtCompileTime, \
|
---|
58 | IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; \
|
---|
59 | using Base::derived; \
|
---|
60 | using Base::const_cast_derived;
|
---|
61 |
|
---|
62 | #define EIGEN_SPARSE_PUBLIC_INTERFACE(Derived) \
|
---|
63 | _EIGEN_SPARSE_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived >)
|
---|
64 |
|
---|
65 | const int CoherentAccessPattern = 0x1;
|
---|
66 | const int InnerRandomAccessPattern = 0x2 | CoherentAccessPattern;
|
---|
67 | const int OuterRandomAccessPattern = 0x4 | CoherentAccessPattern;
|
---|
68 | const int RandomAccessPattern = 0x8 | OuterRandomAccessPattern | InnerRandomAccessPattern;
|
---|
69 |
|
---|
70 | template<typename _Scalar, int _Flags = 0, typename _Index = int> class SparseMatrix;
|
---|
71 | template<typename _Scalar, int _Flags = 0, typename _Index = int> class DynamicSparseMatrix;
|
---|
72 | template<typename _Scalar, int _Flags = 0, typename _Index = int> class SparseVector;
|
---|
73 | template<typename _Scalar, int _Flags = 0, typename _Index = int> class MappedSparseMatrix;
|
---|
74 |
|
---|
75 | template<typename MatrixType, int Mode> class SparseTriangularView;
|
---|
76 | template<typename MatrixType, unsigned int UpLo> class SparseSelfAdjointView;
|
---|
77 | template<typename Lhs, typename Rhs> class SparseDiagonalProduct;
|
---|
78 | template<typename MatrixType> class SparseView;
|
---|
79 |
|
---|
80 | template<typename Lhs, typename Rhs> class SparseSparseProduct;
|
---|
81 | template<typename Lhs, typename Rhs> class SparseTimeDenseProduct;
|
---|
82 | template<typename Lhs, typename Rhs> class DenseTimeSparseProduct;
|
---|
83 | template<typename Lhs, typename Rhs, bool Transpose> class SparseDenseOuterProduct;
|
---|
84 |
|
---|
85 | template<typename Lhs, typename Rhs> struct SparseSparseProductReturnType;
|
---|
86 | template<typename Lhs, typename Rhs,
|
---|
87 | int InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(internal::traits<Lhs>::ColsAtCompileTime,internal::traits<Rhs>::RowsAtCompileTime)> struct DenseSparseProductReturnType;
|
---|
88 | template<typename Lhs, typename Rhs,
|
---|
89 | int InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(internal::traits<Lhs>::ColsAtCompileTime,internal::traits<Rhs>::RowsAtCompileTime)> struct SparseDenseProductReturnType;
|
---|
90 | template<typename MatrixType,int UpLo> class SparseSymmetricPermutationProduct;
|
---|
91 |
|
---|
92 | namespace internal {
|
---|
93 |
|
---|
94 | template<typename T,int Rows,int Cols> struct sparse_eval;
|
---|
95 |
|
---|
96 | template<typename T> struct eval<T,Sparse>
|
---|
97 | : public sparse_eval<T, traits<T>::RowsAtCompileTime,traits<T>::ColsAtCompileTime>
|
---|
98 | {};
|
---|
99 |
|
---|
100 | template<typename T,int Cols> struct sparse_eval<T,1,Cols> {
|
---|
101 | typedef typename traits<T>::Scalar _Scalar;
|
---|
102 | typedef typename traits<T>::Index _Index;
|
---|
103 | public:
|
---|
104 | typedef SparseVector<_Scalar, RowMajor, _Index> type;
|
---|
105 | };
|
---|
106 |
|
---|
107 | template<typename T,int Rows> struct sparse_eval<T,Rows,1> {
|
---|
108 | typedef typename traits<T>::Scalar _Scalar;
|
---|
109 | typedef typename traits<T>::Index _Index;
|
---|
110 | public:
|
---|
111 | typedef SparseVector<_Scalar, ColMajor, _Index> type;
|
---|
112 | };
|
---|
113 |
|
---|
114 | template<typename T,int Rows,int Cols> struct sparse_eval {
|
---|
115 | typedef typename traits<T>::Scalar _Scalar;
|
---|
116 | typedef typename traits<T>::Index _Index;
|
---|
117 | enum { _Options = ((traits<T>::Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor };
|
---|
118 | public:
|
---|
119 | typedef SparseMatrix<_Scalar, _Options, _Index> type;
|
---|
120 | };
|
---|
121 |
|
---|
122 | template<typename T> struct sparse_eval<T,1,1> {
|
---|
123 | typedef typename traits<T>::Scalar _Scalar;
|
---|
124 | public:
|
---|
125 | typedef Matrix<_Scalar, 1, 1> type;
|
---|
126 | };
|
---|
127 |
|
---|
128 | template<typename T> struct plain_matrix_type<T,Sparse>
|
---|
129 | {
|
---|
130 | typedef typename traits<T>::Scalar _Scalar;
|
---|
131 | typedef typename traits<T>::Index _Index;
|
---|
132 | enum { _Options = ((traits<T>::Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor };
|
---|
133 | public:
|
---|
134 | typedef SparseMatrix<_Scalar, _Options, _Index> type;
|
---|
135 | };
|
---|
136 |
|
---|
137 | } // end namespace internal
|
---|
138 |
|
---|
139 | /** \ingroup SparseCore_Module
|
---|
140 | *
|
---|
141 | * \class Triplet
|
---|
142 | *
|
---|
143 | * \brief A small structure to hold a non zero as a triplet (i,j,value).
|
---|
144 | *
|
---|
145 | * \sa SparseMatrix::setFromTriplets()
|
---|
146 | */
|
---|
147 | template<typename Scalar, typename Index=typename SparseMatrix<Scalar>::Index >
|
---|
148 | class Triplet
|
---|
149 | {
|
---|
150 | public:
|
---|
151 | Triplet() : m_row(0), m_col(0), m_value(0) {}
|
---|
152 |
|
---|
153 | Triplet(const Index& i, const Index& j, const Scalar& v = Scalar(0))
|
---|
154 | : m_row(i), m_col(j), m_value(v)
|
---|
155 | {}
|
---|
156 |
|
---|
157 | /** \returns the row index of the element */
|
---|
158 | const Index& row() const { return m_row; }
|
---|
159 |
|
---|
160 | /** \returns the column index of the element */
|
---|
161 | const Index& col() const { return m_col; }
|
---|
162 |
|
---|
163 | /** \returns the value of the element */
|
---|
164 | const Scalar& value() const { return m_value; }
|
---|
165 | protected:
|
---|
166 | Index m_row, m_col;
|
---|
167 | Scalar m_value;
|
---|
168 | };
|
---|
169 |
|
---|
170 | } // end namespace Eigen
|
---|
171 |
|
---|
172 | #endif // EIGEN_SPARSEUTIL_H
|
---|