EigenBase.h
Go to the documentation of this file.
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 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
31 template<typename Derived> struct EigenBase
32 {
33 // typedef typename internal::plain_matrix_type<Derived>::type PlainObject;
34 
42 
43  // FIXME is it needed?
44  typedef typename internal::traits<Derived>::StorageKind StorageKind;
45 
48  Derived& derived() { return *static_cast<Derived*>(this); }
51  const Derived& derived() const { return *static_cast<const Derived*>(this); }
52 
54  inline Derived& const_cast_derived() const
55  { return *static_cast<Derived*>(const_cast<EigenBase*>(this)); }
57  inline const Derived& const_derived() const
58  { return *static_cast<const Derived*>(this); }
59 
62  inline Index rows() const EIGEN_NOEXCEPT { return derived().rows(); }
65  inline Index cols() const EIGEN_NOEXCEPT { return derived().cols(); }
69  inline Index size() const EIGEN_NOEXCEPT { return rows() * cols(); }
70 
72  template<typename Dest>
74  inline void evalTo(Dest& dst) const
75  { derived().evalTo(dst); }
76 
78  template<typename Dest>
80  inline void addTo(Dest& dst) const
81  {
82  // This is the default implementation,
83  // derived class can reimplement it in a more optimized way.
84  typename Dest::PlainObject res(rows(),cols());
85  evalTo(res);
86  dst += res;
87  }
88 
90  template<typename Dest>
92  inline void subTo(Dest& dst) const
93  {
94  // This is the default implementation,
95  // derived class can reimplement it in a more optimized way.
96  typename Dest::PlainObject res(rows(),cols());
97  evalTo(res);
98  dst -= res;
99  }
100 
102  template<typename Dest>
103  EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const
104  {
105  // This is the default implementation,
106  // derived class can reimplement it in a more optimized way.
107  dst = dst * this->derived();
108  }
109 
111  template<typename Dest>
112  EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const
113  {
114  // This is the default implementation,
115  // derived class can reimplement it in a more optimized way.
116  dst = this->derived() * dst;
117  }
118 
119 };
120 
121 
133 template<typename Derived>
134 template<typename OtherDerived>
137 {
138  call_assignment(derived(), other.derived());
139  return derived();
140 }
141 
142 template<typename Derived>
143 template<typename OtherDerived>
146 {
147  call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
148  return derived();
149 }
150 
151 template<typename Derived>
152 template<typename OtherDerived>
155 {
156  call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
157  return derived();
158 }
159 
160 } // end namespace Eigen
161 
162 #endif // EIGEN_EIGENBASE_H
#define EIGEN_NOEXCEPT
Definition: Macros.h:1260
#define EIGEN_CONSTEXPR
Definition: Macros.h:747
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Derived & operator+=(const EigenBase< OtherDerived > &other)
Definition: EigenBase.h:145
Derived & operator=(const DenseBase< OtherDerived > &other)
Definition: Assign.h:41
Derived & operator-=(const EigenBase< OtherDerived > &other)
Definition: EigenBase.h:154
void call_assignment(Dst &dst, const Src &src)
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
Derived & derived()
Definition: EigenBase.h:48
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: EigenBase.h:65
void evalTo(Dest &dst) const
Definition: EigenBase.h:74
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41
void applyThisOnTheRight(Dest &dst) const
Definition: EigenBase.h:103
internal::traits< Derived >::StorageKind StorageKind
Definition: EigenBase.h:44
void addTo(Dest &dst) const
Definition: EigenBase.h:80
const Derived & const_derived() const
Definition: EigenBase.h:57
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: EigenBase.h:62
void subTo(Dest &dst) const
Definition: EigenBase.h:92
Derived & const_cast_derived() const
Definition: EigenBase.h:54
EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Definition: EigenBase.h:69
void applyThisOnTheLeft(Dest &dst) const
Definition: EigenBase.h:112
const Derived & derived() const
Definition: EigenBase.h:51