$darkmode
Eigen  5.0.1-dev
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 // IWYU pragma: private
15 #include "./InternalHeaderCheck.h"
16 
17 namespace Eigen {
18 
32 template <typename Derived>
33 struct EigenBase {
34  // typedef typename internal::plain_matrix_type<Derived>::type PlainObject;
35 
44 
45  // FIXME is it needed?
46  typedef typename internal::traits<Derived>::StorageKind StorageKind;
47 
49  EIGEN_DEVICE_FUNC constexpr Derived& derived() { return *static_cast<Derived*>(this); }
51  EIGEN_DEVICE_FUNC constexpr const Derived& derived() const { return *static_cast<const Derived*>(this); }
52 
53  EIGEN_DEVICE_FUNC inline constexpr Derived& const_cast_derived() const {
54  return *static_cast<Derived*>(const_cast<EigenBase*>(this));
55  }
56  EIGEN_DEVICE_FUNC inline const Derived& const_derived() const { return *static_cast<const Derived*>(this); }
57 
59  EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept { return derived().rows(); }
61  EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return derived().cols(); }
64  EIGEN_DEVICE_FUNC constexpr Index size() const noexcept { return rows() * cols(); }
65 
67  template <typename Dest>
68  EIGEN_DEVICE_FUNC inline void evalTo(Dest& dst) const {
69  derived().evalTo(dst);
70  }
71 
73  template <typename Dest>
74  EIGEN_DEVICE_FUNC inline void addTo(Dest& dst) const {
75  // This is the default implementation,
76  // derived class can reimplement it in a more optimized way.
77  typename Dest::PlainObject res(rows(), cols());
78  evalTo(res);
79  dst += res;
80  }
81 
83  template <typename Dest>
84  EIGEN_DEVICE_FUNC inline void subTo(Dest& dst) const {
85  // This is the default implementation,
86  // derived class can reimplement it in a more optimized way.
87  typename Dest::PlainObject res(rows(), cols());
88  evalTo(res);
89  dst -= res;
90  }
91 
93  template <typename Dest>
94  EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const {
95  // This is the default implementation,
96  // derived class can reimplement it in a more optimized way.
97  dst = dst * this->derived();
98  }
99 
101  template <typename Dest>
102  EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const {
103  // This is the default implementation,
104  // derived class can reimplement it in a more optimized way.
105  dst = this->derived() * dst;
106  }
107 
108  template <typename Device>
109  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DeviceWrapper<Derived, Device> device(Device& device);
110  template <typename Device>
111  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DeviceWrapper<const Derived, Device> device(Device& device) const;
112 };
113 
114 /***************************************************************************
115  * Implementation of matrix base methods
116  ***************************************************************************/
117 
126 template <typename Derived>
127 template <typename OtherDerived>
128 EIGEN_DEVICE_FUNC Derived& DenseBase<Derived>::operator=(const EigenBase<OtherDerived>& other) {
129  call_assignment(derived(), other.derived());
130  return derived();
131 }
132 
133 template <typename Derived>
134 template <typename OtherDerived>
135 EIGEN_DEVICE_FUNC Derived& DenseBase<Derived>::operator+=(const EigenBase<OtherDerived>& other) {
136  call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar, typename OtherDerived::Scalar>());
137  return derived();
138 }
139 
140 template <typename Derived>
141 template <typename OtherDerived>
142 EIGEN_DEVICE_FUNC Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived>& other) {
143  call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar, typename OtherDerived::Scalar>());
144  return derived();
145 }
146 
147 } // end namespace Eigen
148 
149 #endif // EIGEN_EIGENBASE_H
constexpr Index size() const noexcept
Definition: EigenBase.h:64
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Derived & operator=(const DenseBase< OtherDerived > &other)
Definition: Assign.h:39
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:38
constexpr Index rows() const noexcept
Definition: EigenBase.h:59
Definition: EigenBase.h:33
constexpr Index cols() const noexcept
Definition: EigenBase.h:61
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
constexpr Derived & derived()
Definition: EigenBase.h:49