compbio
EigenBase.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_EIGENBASE_H
12 #define EIGEN_EIGENBASE_H
13 
14 namespace Eigen {
15 
28 template<typename Derived> struct EigenBase
29 {
30 // typedef typename internal::plain_matrix_type<Derived>::type PlainObject;
31 
38 
39  // FIXME is it needed?
40  typedef typename internal::traits<Derived>::StorageKind StorageKind;
41 
43  EIGEN_DEVICE_FUNC
44  Derived& derived() { return *static_cast<Derived*>(this); }
46  EIGEN_DEVICE_FUNC
47  const Derived& derived() const { return *static_cast<const Derived*>(this); }
48 
49  EIGEN_DEVICE_FUNC
50  inline Derived& const_cast_derived() const
51  { return *static_cast<Derived*>(const_cast<EigenBase*>(this)); }
52  EIGEN_DEVICE_FUNC
53  inline const Derived& const_derived() const
54  { return *static_cast<const Derived*>(this); }
55 
57  EIGEN_DEVICE_FUNC
58  inline Index rows() const { return derived().rows(); }
60  EIGEN_DEVICE_FUNC
61  inline Index cols() const { return derived().cols(); }
64  EIGEN_DEVICE_FUNC
65  inline Index size() const { return rows() * cols(); }
66 
68  template<typename Dest>
69  EIGEN_DEVICE_FUNC
70  inline void evalTo(Dest& dst) const
71  { derived().evalTo(dst); }
72 
74  template<typename Dest>
75  EIGEN_DEVICE_FUNC
76  inline void addTo(Dest& dst) const
77  {
78  // This is the default implementation,
79  // derived class can reimplement it in a more optimized way.
80  typename Dest::PlainObject res(rows(),cols());
81  evalTo(res);
82  dst += res;
83  }
84 
86  template<typename Dest>
87  EIGEN_DEVICE_FUNC
88  inline void subTo(Dest& dst) const
89  {
90  // This is the default implementation,
91  // derived class can reimplement it in a more optimized way.
92  typename Dest::PlainObject res(rows(),cols());
93  evalTo(res);
94  dst -= res;
95  }
96 
98  template<typename Dest>
99  EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const
100  {
101  // This is the default implementation,
102  // derived class can reimplement it in a more optimized way.
103  dst = dst * this->derived();
104  }
105 
107  template<typename Dest>
108  EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const
109  {
110  // This is the default implementation,
111  // derived class can reimplement it in a more optimized way.
112  dst = this->derived() * dst;
113  }
114 
115 };
116 
117 /***************************************************************************
118 * Implementation of matrix base methods
119 ***************************************************************************/
120 
129 template<typename Derived>
130 template<typename OtherDerived>
132 {
133  call_assignment(derived(), other.derived());
134  return derived();
135 }
136 
137 template<typename Derived>
138 template<typename OtherDerived>
140 {
142  return derived();
143 }
144 
145 template<typename Derived>
146 template<typename OtherDerived>
148 {
150  return derived();
151 }
152 
153 } // end namespace Eigen
154 
155 #endif // EIGEN_EIGENBASE_H
EIGEN_DEVICE_FUNC Index rows() const
Definition: EigenBase.h:58
Definition: AssignmentFunctors.h:67
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
EIGEN_DEVICE_FUNC const Derived & derived() const
Definition: EigenBase.h:47
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:28
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & operator=(const DenseBase< OtherDerived > &other)
Copies other into *this.
Definition: Assign.h:39
EIGEN_DEVICE_FUNC Index cols() const
Definition: EigenBase.h:61
Definition: AssignmentFunctors.h:46
EIGEN_DEVICE_FUNC Index size() const
Definition: EigenBase.h:65
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:44
Definition: ForwardDeclarations.h:17