SkylineUtil.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009 Guillaume Saupin <guillaume.saupin@cea.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_SKYLINEUTIL_H
26 #define EIGEN_SKYLINEUTIL_H
27 
28 namespace Eigen {
29 
30 #ifdef NDEBUG
31 #define EIGEN_DBG_SKYLINE(X)
32 #else
33 #define EIGEN_DBG_SKYLINE(X) X
34 #endif
35 
36 const unsigned int SkylineBit = 0x1200;
37 template<typename Lhs, typename Rhs, int ProductMode> class SkylineProduct;
38 enum AdditionalProductEvaluationMode {SkylineTimeDenseProduct, SkylineTimeSkylineProduct, DenseTimeSkylineProduct};
39 enum {IsSkyline = SkylineBit};
40 
41 
42 #define EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \
43 template<typename OtherDerived> \
44 EIGEN_STRONG_INLINE Derived& operator Op(const Eigen::SkylineMatrixBase<OtherDerived>& other) \
45 { \
46  return Base::operator Op(other.derived()); \
47 } \
48 EIGEN_STRONG_INLINE Derived& operator Op(const Derived& other) \
49 { \
50  return Base::operator Op(other); \
51 }
52 
53 #define EIGEN_SKYLINE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \
54 template<typename Other> \
55 EIGEN_STRONG_INLINE Derived& operator Op(const Other& scalar) \
56 { \
57  return Base::operator Op(scalar); \
58 }
59 
60 #define EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
61  EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, =) \
62  EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, +=) \
63  EIGEN_SKYLINE_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \
64  EIGEN_SKYLINE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \
65  EIGEN_SKYLINE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=)
66 
67 #define _EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived, BaseClass) \
68  typedef BaseClass Base; \
69  typedef typename Eigen::internal::traits<Derived>::Scalar Scalar; \
70  typedef typename Eigen::NumTraits<Scalar>::Real RealScalar; \
71  typedef typename Eigen::internal::traits<Derived>::StorageKind StorageKind; \
72  typedef typename Eigen::internal::index<StorageKind>::type Index; \
73  enum { Flags = Eigen::internal::traits<Derived>::Flags, };
74 
75 #define EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived) \
76  _EIGEN_SKYLINE_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::SkylineMatrixBase<Derived>)
77 
78 template<typename Derived> class SkylineMatrixBase;
79 template<typename _Scalar, int _Flags = 0> class SkylineMatrix;
80 template<typename _Scalar, int _Flags = 0> class DynamicSkylineMatrix;
81 template<typename _Scalar, int _Flags = 0> class SkylineVector;
82 template<typename _Scalar, int _Flags = 0> class MappedSkylineMatrix;
83 
84 namespace internal {
85 
86 template<typename Lhs, typename Rhs> struct skyline_product_mode;
87 template<typename Lhs, typename Rhs, int ProductMode = skyline_product_mode<Lhs,Rhs>::value> struct SkylineProductReturnType;
88 
89 template<typename T> class eval<T,IsSkyline>
90 {
91  typedef typename traits<T>::Scalar _Scalar;
92  enum {
93  _Flags = traits<T>::Flags
94  };
95 
96  public:
97  typedef SkylineMatrix<_Scalar, _Flags> type;
98 };
99 
100 } // end namespace internal
101 
102 } // end namespace Eigen
103 
104 #endif // EIGEN_SKYLINEUTIL_H