Eigen  3.3.9
 
Loading...
Searching...
No Matches
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
14namespace Eigen {
15
29template<typename Derived> struct EigenBase
30{
31// typedef typename internal::plain_matrix_type<Derived>::type PlainObject;
32
39
40 // FIXME is it needed?
41 typedef typename internal::traits<Derived>::StorageKind StorageKind;
42
44 EIGEN_DEVICE_FUNC
45 Derived& derived() { return *static_cast<Derived*>(this); }
47 EIGEN_DEVICE_FUNC
48 const Derived& derived() const { return *static_cast<const Derived*>(this); }
49
50 EIGEN_DEVICE_FUNC
51 inline Derived& const_cast_derived() const
52 { return *static_cast<Derived*>(const_cast<EigenBase*>(this)); }
53 EIGEN_DEVICE_FUNC
54 inline const Derived& const_derived() const
55 { return *static_cast<const Derived*>(this); }
56
58 EIGEN_DEVICE_FUNC
59 inline Index rows() const { return derived().rows(); }
61 EIGEN_DEVICE_FUNC
62 inline Index cols() const { return derived().cols(); }
65 EIGEN_DEVICE_FUNC
66 inline Index size() const { return rows() * cols(); }
67
69 template<typename Dest>
70 EIGEN_DEVICE_FUNC
71 inline void evalTo(Dest& dst) const
72 { derived().evalTo(dst); }
73
75 template<typename Dest>
76 EIGEN_DEVICE_FUNC
77 inline void addTo(Dest& dst) const
78 {
79 // This is the default implementation,
80 // derived class can reimplement it in a more optimized way.
81 typename Dest::PlainObject res(rows(),cols());
82 evalTo(res);
83 dst += res;
84 }
85
87 template<typename Dest>
88 EIGEN_DEVICE_FUNC
89 inline void subTo(Dest& dst) const
90 {
91 // This is the default implementation,
92 // derived class can reimplement it in a more optimized way.
93 typename Dest::PlainObject res(rows(),cols());
94 evalTo(res);
95 dst -= res;
96 }
97
99 template<typename Dest>
100 EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const
101 {
102 // This is the default implementation,
103 // derived class can reimplement it in a more optimized way.
104 dst = dst * this->derived();
105 }
106
108 template<typename Dest>
109 EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const
110 {
111 // This is the default implementation,
112 // derived class can reimplement it in a more optimized way.
113 dst = this->derived() * dst;
114 }
115
116};
117
118/***************************************************************************
119* Implementation of matrix base methods
120***************************************************************************/
121
130template<typename Derived>
131template<typename OtherDerived>
132EIGEN_DEVICE_FUNC
134{
135 call_assignment(derived(), other.derived());
136 return derived();
137}
138
139template<typename Derived>
140template<typename OtherDerived>
141EIGEN_DEVICE_FUNC
142Derived& DenseBase<Derived>::operator+=(const EigenBase<OtherDerived> &other)
143{
144 call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
145 return derived();
146}
147
148template<typename Derived>
149template<typename OtherDerived>
150EIGEN_DEVICE_FUNC
151Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived> &other)
152{
153 call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
154 return derived();
155}
156
157} // end namespace Eigen
158
159#endif // EIGEN_EIGENBASE_H
Derived & operator=(const DenseBase< OtherDerived > &other)
Definition Assign.h:39
Namespace containing all symbols from the Eigen library.
Definition A05_PortingFrom2To3.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:65
Definition EigenBase.h:30
Index cols() const
Definition EigenBase.h:62
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:38
Derived & derived()
Definition EigenBase.h:45
Index rows() const
Definition EigenBase.h:59
Index size() const
Definition EigenBase.h:66
const Derived & derived() const
Definition EigenBase.h:48