WPILibC++ 2023.4.3
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
14namespace Eigen {
15
16/** \class EigenBase
17 * \ingroup Core_Module
18 *
19 * Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T).
20 *
21 * In other words, an EigenBase object is an object that can be copied into a MatrixBase.
22 *
23 * Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc.
24 *
25 * Notice that this class is trivial, it is only used to disambiguate overloaded functions.
26 *
27 * \sa \blank \ref TopicClassHierarchy
28 */
29template<typename Derived> struct EigenBase
30{
31// typedef typename internal::plain_matrix_type<Derived>::type PlainObject;
32
33 /** \brief The interface type of indices
34 * \details To change this, \c \#define the preprocessor symbol \c EIGEN_DEFAULT_DENSE_INDEX_TYPE.
35 * \sa StorageIndex, \ref TopicPreprocessorDirectives.
36 * DEPRECATED: Since Eigen 3.3, its usage is deprecated. Use Eigen::Index instead.
37 * Deprecation is not marked with a doxygen comment because there are too many existing usages to add the deprecation attribute.
38 */
40
41 // FIXME is it needed?
43
44 /** \returns a reference to the derived object */
46 Derived& derived() { return *static_cast<Derived*>(this); }
47 /** \returns a const reference to the derived object */
49 const Derived& derived() const { return *static_cast<const Derived*>(this); }
52 inline Derived& const_cast_derived() const
53 { return *static_cast<Derived*>(const_cast<EigenBase*>(this)); }
55 inline const Derived& const_derived() const
56 { return *static_cast<const Derived*>(this); }
57
58 /** \returns the number of rows. \sa cols(), RowsAtCompileTime */
60 inline Index rows() const EIGEN_NOEXCEPT { return derived().rows(); }
61 /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/
63 inline Index cols() const EIGEN_NOEXCEPT { return derived().cols(); }
64 /** \returns the number of coefficients, which is rows()*cols().
65 * \sa rows(), cols(), SizeAtCompileTime. */
67 inline Index size() const EIGEN_NOEXCEPT { return rows() * cols(); }
68
69 /** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */
70 template<typename Dest>
72 inline void evalTo(Dest& dst) const
73 { derived().evalTo(dst); }
74
75 /** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */
76 template<typename Dest>
78 inline void addTo(Dest& dst) const
79 {
80 // This is the default implementation,
81 // derived class can reimplement it in a more optimized way.
82 typename Dest::PlainObject res(rows(),cols());
83 evalTo(res);
84 dst += res;
85 }
86
87 /** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */
88 template<typename Dest>
90 inline void subTo(Dest& dst) const
91 {
92 // This is the default implementation,
93 // derived class can reimplement it in a more optimized way.
94 typename Dest::PlainObject res(rows(),cols());
95 evalTo(res);
96 dst -= res;
97 }
98
99 /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */
100 template<typename Dest>
101 EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const
102 {
103 // This is the default implementation,
104 // derived class can reimplement it in a more optimized way.
105 dst = dst * this->derived();
106 }
107
108 /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */
109 template<typename Dest>
110 EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const
111 {
112 // This is the default implementation,
113 // derived class can reimplement it in a more optimized way.
114 dst = this->derived() * dst;
115 }
116
117};
118
119/***************************************************************************
120* Implementation of matrix base methods
121***************************************************************************/
122
123/** \brief Copies the generic expression \a other into *this.
124 *
125 * \details The expression must provide a (templated) evalTo(Derived& dst) const
126 * function which does the actual job. In practice, this allows any user to write
127 * its own special matrix without having to modify MatrixBase
128 *
129 * \returns a reference to *this.
130 */
131template<typename Derived>
132template<typename OtherDerived>
135{
136 call_assignment(derived(), other.derived());
137 return derived();
138}
139
140template<typename Derived>
141template<typename OtherDerived>
144{
146 return derived();
147}
148
149template<typename Derived>
150template<typename OtherDerived>
153{
155 return derived();
156}
157
158} // end namespace Eigen
159
160#endif // EIGEN_EIGENBASE_H
#define EIGEN_NOEXCEPT
Definition: Macros.h:1428
#define EIGEN_CONSTEXPR
Definition: Macros.h:797
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:986
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & operator=(const DenseBase< OtherDerived > &other)
Copies other into *this.
Definition: Assign.h:39
EIGEN_DEVICE_FUNC Derived & operator-=(const EigenBase< OtherDerived > &other)
Definition: EigenBase.h:152
EIGEN_DEVICE_FUNC Derived & operator+=(const EigenBase< OtherDerived > &other)
Definition: EigenBase.h:143
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment(Dst &dst, const Src &src)
Definition: AssignEvaluator.h:834
Namespace containing all symbols from the Eigen library.
Definition: MatrixExponential.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:30
EIGEN_DEVICE_FUNC Derived & const_cast_derived() const
Definition: EigenBase.h:52
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: EigenBase.h:63
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:39
EIGEN_DEVICE_FUNC void subTo(Dest &dst) const
Definition: EigenBase.h:90
EIGEN_DEVICE_FUNC const Derived & derived() const
Definition: EigenBase.h:49
internal::traits< Derived >::StorageKind StorageKind
Definition: EigenBase.h:42
EIGEN_DEVICE_FUNC void evalTo(Dest &dst) const
Definition: EigenBase.h:72
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Definition: EigenBase.h:67
EIGEN_DEVICE_FUNC void applyThisOnTheRight(Dest &dst) const
Definition: EigenBase.h:101
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:46
EIGEN_DEVICE_FUNC const Derived & const_derived() const
Definition: EigenBase.h:55
EIGEN_DEVICE_FUNC void applyThisOnTheLeft(Dest &dst) const
Definition: EigenBase.h:110
EIGEN_DEVICE_FUNC void addTo(Dest &dst) const
Definition: EigenBase.h:78
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: EigenBase.h:60
Definition: AssignmentFunctors.h:46
Definition: AssignmentFunctors.h:67
Definition: ForwardDeclarations.h:17