|
||||
File indexing completed on 2025-01-18 09:56:13
0001 // This file is part of Eigen, a lightweight C++ template library 0002 // for linear algebra. 0003 // 0004 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> 0005 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> 0006 // 0007 // This Source Code Form is subject to the terms of the Mozilla 0008 // Public License v. 2.0. If a copy of the MPL was not distributed 0009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 0010 0011 #ifndef EIGEN_EIGENBASE_H 0012 #define EIGEN_EIGENBASE_H 0013 0014 namespace Eigen { 0015 0016 /** \class EigenBase 0017 * \ingroup Core_Module 0018 * 0019 * Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T). 0020 * 0021 * In other words, an EigenBase object is an object that can be copied into a MatrixBase. 0022 * 0023 * Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc. 0024 * 0025 * Notice that this class is trivial, it is only used to disambiguate overloaded functions. 0026 * 0027 * \sa \blank \ref TopicClassHierarchy 0028 */ 0029 template<typename Derived> struct EigenBase 0030 { 0031 // typedef typename internal::plain_matrix_type<Derived>::type PlainObject; 0032 0033 /** \brief The interface type of indices 0034 * \details To change this, \c \#define the preprocessor symbol \c EIGEN_DEFAULT_DENSE_INDEX_TYPE. 0035 * \sa StorageIndex, \ref TopicPreprocessorDirectives. 0036 * DEPRECATED: Since Eigen 3.3, its usage is deprecated. Use Eigen::Index instead. 0037 * Deprecation is not marked with a doxygen comment because there are too many existing usages to add the deprecation attribute. 0038 */ 0039 typedef Eigen::Index Index; 0040 0041 // FIXME is it needed? 0042 typedef typename internal::traits<Derived>::StorageKind StorageKind; 0043 0044 /** \returns a reference to the derived object */ 0045 EIGEN_DEVICE_FUNC 0046 Derived& derived() { return *static_cast<Derived*>(this); } 0047 /** \returns a const reference to the derived object */ 0048 EIGEN_DEVICE_FUNC 0049 const Derived& derived() const { return *static_cast<const Derived*>(this); } 0050 0051 EIGEN_DEVICE_FUNC 0052 inline Derived& const_cast_derived() const 0053 { return *static_cast<Derived*>(const_cast<EigenBase*>(this)); } 0054 EIGEN_DEVICE_FUNC 0055 inline const Derived& const_derived() const 0056 { return *static_cast<const Derived*>(this); } 0057 0058 /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ 0059 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR 0060 inline Index rows() const EIGEN_NOEXCEPT { return derived().rows(); } 0061 /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ 0062 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR 0063 inline Index cols() const EIGEN_NOEXCEPT { return derived().cols(); } 0064 /** \returns the number of coefficients, which is rows()*cols(). 0065 * \sa rows(), cols(), SizeAtCompileTime. */ 0066 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR 0067 inline Index size() const EIGEN_NOEXCEPT { return rows() * cols(); } 0068 0069 /** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */ 0070 template<typename Dest> 0071 EIGEN_DEVICE_FUNC 0072 inline void evalTo(Dest& dst) const 0073 { derived().evalTo(dst); } 0074 0075 /** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */ 0076 template<typename Dest> 0077 EIGEN_DEVICE_FUNC 0078 inline void addTo(Dest& dst) const 0079 { 0080 // This is the default implementation, 0081 // derived class can reimplement it in a more optimized way. 0082 typename Dest::PlainObject res(rows(),cols()); 0083 evalTo(res); 0084 dst += res; 0085 } 0086 0087 /** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */ 0088 template<typename Dest> 0089 EIGEN_DEVICE_FUNC 0090 inline void subTo(Dest& dst) const 0091 { 0092 // This is the default implementation, 0093 // derived class can reimplement it in a more optimized way. 0094 typename Dest::PlainObject res(rows(),cols()); 0095 evalTo(res); 0096 dst -= res; 0097 } 0098 0099 /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */ 0100 template<typename Dest> 0101 EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const 0102 { 0103 // This is the default implementation, 0104 // derived class can reimplement it in a more optimized way. 0105 dst = dst * this->derived(); 0106 } 0107 0108 /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */ 0109 template<typename Dest> 0110 EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const 0111 { 0112 // This is the default implementation, 0113 // derived class can reimplement it in a more optimized way. 0114 dst = this->derived() * dst; 0115 } 0116 0117 }; 0118 0119 /*************************************************************************** 0120 * Implementation of matrix base methods 0121 ***************************************************************************/ 0122 0123 /** \brief Copies the generic expression \a other into *this. 0124 * 0125 * \details The expression must provide a (templated) evalTo(Derived& dst) const 0126 * function which does the actual job. In practice, this allows any user to write 0127 * its own special matrix without having to modify MatrixBase 0128 * 0129 * \returns a reference to *this. 0130 */ 0131 template<typename Derived> 0132 template<typename OtherDerived> 0133 EIGEN_DEVICE_FUNC 0134 Derived& DenseBase<Derived>::operator=(const EigenBase<OtherDerived> &other) 0135 { 0136 call_assignment(derived(), other.derived()); 0137 return derived(); 0138 } 0139 0140 template<typename Derived> 0141 template<typename OtherDerived> 0142 EIGEN_DEVICE_FUNC 0143 Derived& DenseBase<Derived>::operator+=(const EigenBase<OtherDerived> &other) 0144 { 0145 call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>()); 0146 return derived(); 0147 } 0148 0149 template<typename Derived> 0150 template<typename OtherDerived> 0151 EIGEN_DEVICE_FUNC 0152 Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived> &other) 0153 { 0154 call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>()); 0155 return derived(); 0156 } 0157 0158 } // end namespace Eigen 0159 0160 #endif // EIGEN_EIGENBASE_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |