Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
EigenBase.h
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> 00005 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> 00006 // 00007 // This Source Code Form is subject to the terms of the Mozilla 00008 // Public License v. 2.0. If a copy of the MPL was not distributed 00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00010 00011 #ifndef EIGEN_EIGENBASE_H 00012 #define EIGEN_EIGENBASE_H 00013 00014 namespace Eigen { 00015 00016 /** Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T). 00017 * 00018 * In other words, an EigenBase object is an object that can be copied into a MatrixBase. 00019 * 00020 * Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc. 00021 * 00022 * Notice that this class is trivial, it is only used to disambiguate overloaded functions. 00023 * 00024 * \sa \ref TopicClassHierarchy 00025 */ 00026 template<typename Derived> struct EigenBase 00027 { 00028 // typedef typename internal::plain_matrix_type<Derived>::type PlainObject; 00029 00030 typedef typename internal::traits<Derived>::StorageKind StorageKind; 00031 typedef typename internal::traits<Derived>::Index Index; 00032 00033 /** \returns a reference to the derived object */ 00034 Derived& derived () { return *static_cast<Derived*>(this); } 00035 /** \returns a const reference to the derived object */ 00036 const Derived& derived () const { return *static_cast<const Derived*>(this); } 00037 00038 inline Derived& const_cast_derived() const 00039 { return *static_cast<Derived*>(const_cast<EigenBase*>(this)); } 00040 inline const Derived& const_derived() const 00041 { return *static_cast<const Derived*>(this); } 00042 00043 /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ 00044 inline Index rows () const { return derived ().rows(); } 00045 /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ 00046 inline Index cols () const { return derived ().cols(); } 00047 /** \returns the number of coefficients, which is rows()*cols(). 00048 * \sa rows(), cols(), SizeAtCompileTime. */ 00049 inline Index size () const { return rows () * cols (); } 00050 00051 /** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */ 00052 template<typename Dest> inline void evalTo(Dest& dst) const 00053 { derived ().evalTo(dst); } 00054 00055 /** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */ 00056 template<typename Dest> inline void addTo(Dest& dst) const 00057 { 00058 // This is the default implementation, 00059 // derived class can reimplement it in a more optimized way. 00060 typename Dest::PlainObject res(rows (),cols ()); 00061 evalTo(res); 00062 dst += res; 00063 } 00064 00065 /** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */ 00066 template<typename Dest> inline void subTo(Dest& dst) const 00067 { 00068 // This is the default implementation, 00069 // derived class can reimplement it in a more optimized way. 00070 typename Dest::PlainObject res(rows (),cols ()); 00071 evalTo(res); 00072 dst -= res; 00073 } 00074 00075 /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */ 00076 template<typename Dest> inline void applyThisOnTheRight(Dest& dst) const 00077 { 00078 // This is the default implementation, 00079 // derived class can reimplement it in a more optimized way. 00080 dst = dst * this->derived (); 00081 } 00082 00083 /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */ 00084 template<typename Dest> inline void applyThisOnTheLeft(Dest& dst) const 00085 { 00086 // This is the default implementation, 00087 // derived class can reimplement it in a more optimized way. 00088 dst = this->derived () * dst; 00089 } 00090 00091 }; 00092 00093 /*************************************************************************** 00094 * Implementation of matrix base methods 00095 ***************************************************************************/ 00096 00097 /** \brief Copies the generic expression \a other into *this. 00098 * 00099 * \details The expression must provide a (templated) evalTo(Derived& dst) const 00100 * function which does the actual job. In practice, this allows any user to write 00101 * its own special matrix without having to modify MatrixBase 00102 * 00103 * \returns a reference to *this. 00104 */ 00105 template<typename Derived> 00106 template<typename OtherDerived> 00107 Derived& DenseBase<Derived>::operator=(const EigenBase<OtherDerived> &other) 00108 { 00109 other.derived().evalTo(derived()); 00110 return derived(); 00111 } 00112 00113 template<typename Derived> 00114 template<typename OtherDerived> 00115 Derived& DenseBase<Derived>::operator+=(const EigenBase<OtherDerived> &other) 00116 { 00117 other.derived().addTo(derived()); 00118 return derived(); 00119 } 00120 00121 template<typename Derived> 00122 template<typename OtherDerived> 00123 Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived> &other) 00124 { 00125 other.derived().subTo(derived()); 00126 return derived(); 00127 } 00128 00129 } // end namespace Eigen 00130 00131 #endif // EIGEN_EIGENBASE_H
Generated on Thu Nov 17 2022 22:01:28 by
1.7.2