Eigen  5.0.1
 
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// SPDX-License-Identifier: MPL-2.0
11
12#ifndef EIGEN_EIGENBASE_H
13#define EIGEN_EIGENBASE_H
14
15// IWYU pragma: private
16#include "./InternalHeaderCheck.h"
17
18namespace Eigen {
19
33template <typename Derived>
34struct EigenBase {
35 // typedef typename internal::plain_matrix_type<Derived>::type PlainObject;
36
44 using Index = Eigen::Index;
45
46 // FIXME is it needed?
47 using StorageKind = typename internal::traits<Derived>::StorageKind;
48
50 EIGEN_DEVICE_FUNC constexpr Derived& derived() { return *static_cast<Derived*>(this); }
52 EIGEN_DEVICE_FUNC constexpr const Derived& derived() const { return *static_cast<const Derived*>(this); }
53
54 EIGEN_DEVICE_FUNC inline constexpr Derived& const_cast_derived() const {
55 return *static_cast<Derived*>(const_cast<EigenBase*>(this));
56 }
57 EIGEN_DEVICE_FUNC constexpr inline const Derived& const_derived() const { return *static_cast<const Derived*>(this); }
58
60 EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept { return derived().rows(); }
62 EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return derived().cols(); }
65 EIGEN_DEVICE_FUNC constexpr Index size() const noexcept { return rows() * cols(); }
66
68 template <typename Dest>
69 EIGEN_DEVICE_FUNC constexpr inline void evalTo(Dest& dst) const {
70 derived().evalTo(dst);
71 }
72
74 template <typename Dest>
75 EIGEN_DEVICE_FUNC constexpr inline void addTo(Dest& dst) const {
76 // This is the default implementation,
77 // derived class can reimplement it in a more optimized way.
78 typename Dest::PlainObject res(rows(), cols());
79 evalTo(res);
80 dst += res;
81 }
82
84 template <typename Dest>
85 EIGEN_DEVICE_FUNC constexpr inline void subTo(Dest& dst) const {
86 // This is the default implementation,
87 // derived class can reimplement it in a more optimized way.
88 typename Dest::PlainObject res(rows(), cols());
89 evalTo(res);
90 dst -= res;
91 }
92
94 template <typename Dest>
95 EIGEN_DEVICE_FUNC constexpr inline void applyThisOnTheRight(Dest& dst) const {
96 // This is the default implementation,
97 // derived class can reimplement it in a more optimized way.
98 dst = dst * this->derived();
99 }
100
102 template <typename Dest>
103 EIGEN_DEVICE_FUNC constexpr inline void applyThisOnTheLeft(Dest& dst) const {
104 // This is the default implementation,
105 // derived class can reimplement it in a more optimized way.
106 dst = this->derived() * dst;
107 }
109 template <typename Device>
110 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DeviceWrapper<Derived, Device> device(Device& device);
111 template <typename Device>
112 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DeviceWrapper<const Derived, Device> device(Device& device) const;
113};
114
115/***************************************************************************
116 * Implementation of matrix base methods
117 ***************************************************************************/
118
127template <typename Derived>
128template <typename OtherDerived>
129EIGEN_DEVICE_FUNC constexpr Derived& DenseBase<Derived>::operator=(const EigenBase<OtherDerived>& other) {
130 call_assignment(derived(), other.derived());
131 return derived();
132}
133
134template <typename Derived>
135template <typename OtherDerived>
136EIGEN_DEVICE_FUNC constexpr Derived& DenseBase<Derived>::operator+=(const EigenBase<OtherDerived>& other) {
137 call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar, typename OtherDerived::Scalar>());
138 return derived();
139}
140
141template <typename Derived>
142template <typename OtherDerived>
143EIGEN_DEVICE_FUNC constexpr Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived>& other) {
144 call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar, typename OtherDerived::Scalar>());
145 return derived();
146}
147
148} // end namespace Eigen
149
150#endif // EIGEN_EIGENBASE_H
constexpr Derived & operator=(const DenseBase< OtherDerived > &other)
Definition Assign.h:41
Definition EigenBase.h:34
constexpr Index cols() const noexcept
Definition EigenBase.h:62
constexpr Derived & derived()
Definition EigenBase.h:50
constexpr Index rows() const noexcept
Definition EigenBase.h:60
constexpr Index size() const noexcept
Definition EigenBase.h:65
constexpr const Derived & derived() const
Definition EigenBase.h:52
Eigen::Index Index
Definition EigenBase.h:44