Eigen  3.3.0
 
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
28template<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
129template<typename Derived>
130template<typename OtherDerived>
132{
133 call_assignment(derived(), other.derived());
134 return derived();
135}
136
137template<typename Derived>
138template<typename OtherDerived>
140{
141 call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
142 return derived();
143}
144
145template<typename Derived>
146template<typename OtherDerived>
147Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived> &other)
148{
149 call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
150 return derived();
151}
152
153} // end namespace Eigen
154
155#endif // EIGEN_EIGENBASE_H
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:47
Namespace containing all symbols from the Eigen library.
Definition: Core:287
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: EigenBase.h:29
Index cols() const
Definition: EigenBase.h:61
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
Derived & derived()
Definition: EigenBase.h:44
Index rows() const
Definition: EigenBase.h:58
Index size() const
Definition: EigenBase.h:65
const Derived & derived() const
Definition: EigenBase.h:47