Merge of itasc branch. Project files, scons and cmake should be working. Makefile...
[blender.git] / extern / Eigen2 / Eigen / src / Sparse / SparseUtil.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra. Eigen itself is part of the KDE project.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
5 //
6 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24
25 #ifndef EIGEN_SPARSEUTIL_H
26 #define EIGEN_SPARSEUTIL_H
27
28 #ifdef NDEBUG
29 #define EIGEN_DBG_SPARSE(X)
30 #else
31 #define EIGEN_DBG_SPARSE(X) X
32 #endif
33
34 #define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \
35 template<typename OtherDerived> \
36 EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::SparseMatrixBase<OtherDerived>& other) \
37 { \
38   return Base::operator Op(other.derived()); \
39 } \
40 EIGEN_STRONG_INLINE Derived& operator Op(const Derived& other) \
41 { \
42   return Base::operator Op(other); \
43 }
44
45 #define EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \
46 template<typename Other> \
47 EIGEN_STRONG_INLINE Derived& operator Op(const Other& scalar) \
48 { \
49   return Base::operator Op(scalar); \
50 }
51
52 #define EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
53 EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) \
54 EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, +=) \
55 EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \
56 EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \
57 EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=)
58
59 #define _EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived, BaseClass) \
60 typedef BaseClass Base; \
61 typedef typename Eigen::ei_traits<Derived>::Scalar Scalar; \
62 typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
63 typedef typename Eigen::ei_nested<Derived>::type Nested; \
64 enum { RowsAtCompileTime = Eigen::ei_traits<Derived>::RowsAtCompileTime, \
65        ColsAtCompileTime = Eigen::ei_traits<Derived>::ColsAtCompileTime, \
66        Flags = Eigen::ei_traits<Derived>::Flags, \
67        CoeffReadCost = Eigen::ei_traits<Derived>::CoeffReadCost, \
68        SizeAtCompileTime = Base::SizeAtCompileTime, \
69        IsVectorAtCompileTime = Base::IsVectorAtCompileTime };
70
71 #define EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived) \
72 _EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SparseMatrixBase<Derived>)
73
74 enum SparseBackend {
75   DefaultBackend,
76   Taucs,
77   Cholmod,
78   SuperLU,
79   UmfPack
80 };
81
82 // solver flags
83 enum {
84   CompleteFactorization       = 0x0000,  // the default
85   IncompleteFactorization     = 0x0001,
86   MemoryEfficient             = 0x0002,
87
88   // For LLT Cholesky:
89   SupernodalMultifrontal      = 0x0010,
90   SupernodalLeftLooking       = 0x0020,
91
92   // Ordering methods:
93   NaturalOrdering             = 0x0100, // the default
94   MinimumDegree_AT_PLUS_A     = 0x0200,
95   MinimumDegree_ATA           = 0x0300,
96   ColApproxMinimumDegree      = 0x0400,
97   Metis                       = 0x0500,
98   Scotch                      = 0x0600,
99   Chaco                       = 0x0700,
100   OrderingMask                = 0x0f00
101 };
102
103 template<typename Derived> class SparseMatrixBase;
104 template<typename _Scalar, int _Flags = 0> class SparseMatrix;
105 template<typename _Scalar, int _Flags = 0> class DynamicSparseMatrix;
106 template<typename _Scalar, int _Flags = 0> class SparseVector;
107 template<typename _Scalar, int _Flags = 0> class MappedSparseMatrix;
108
109 template<typename MatrixType>                            class SparseTranspose;
110 template<typename MatrixType, int Size>                  class SparseInnerVectorSet;
111 template<typename Derived>                               class SparseCwise;
112 template<typename UnaryOp,   typename MatrixType>        class SparseCwiseUnaryOp;
113 template<typename BinaryOp,  typename Lhs, typename Rhs> class SparseCwiseBinaryOp;
114 template<typename ExpressionType,
115          unsigned int Added, unsigned int Removed>       class SparseFlagged;
116 template<typename Lhs, typename Rhs>                     class SparseDiagonalProduct;
117
118 template<typename Lhs, typename Rhs> struct ei_sparse_product_mode;
119 template<typename Lhs, typename Rhs, int ProductMode = ei_sparse_product_mode<Lhs,Rhs>::value> struct SparseProductReturnType;
120
121 const int CoherentAccessPattern  = 0x1;
122 const int InnerRandomAccessPattern  = 0x2 | CoherentAccessPattern;
123 const int OuterRandomAccessPattern  = 0x4 | CoherentAccessPattern;
124 const int RandomAccessPattern       = 0x8 | OuterRandomAccessPattern | InnerRandomAccessPattern;
125
126 // const int AccessPatternNotSupported = 0x0;
127 // const int AccessPatternSupported    = 0x1;
128 // 
129 // template<typename MatrixType, int AccessPattern> struct ei_support_access_pattern
130 // {
131 //   enum { ret = (int(ei_traits<MatrixType>::SupportedAccessPatterns) & AccessPattern) == AccessPattern
132 //              ? AccessPatternSupported
133 //              : AccessPatternNotSupported
134 //   };
135 // };
136
137 template<typename T> class ei_eval<T,IsSparse>
138 {
139     typedef typename ei_traits<T>::Scalar _Scalar;
140     enum {
141           _Flags = ei_traits<T>::Flags
142     };
143
144   public:
145     typedef SparseMatrix<_Scalar, _Flags> type;
146 };
147
148 #endif // EIGEN_SPARSEUTIL_H