Main MRPT website > C++ reference
MRPT logo

EigenBase.h

Go to the documentation of this file.
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 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_EIGENBASE_H
00027 #define EIGEN_EIGENBASE_H
00028 
00029 
00030 /** Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T).
00031   *
00032   * In other words, an EigenBase object is an object that can be copied into a MatrixBase.
00033   *
00034   * Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc.
00035   *
00036   * Notice that this class is trivial, it is only used to disambiguate overloaded functions.
00037   *
00038   * \sa \ref TopicClassHierarchy
00039   */
00040 template<typename Derived> struct EigenBase
00041 {
00042 //   typedef typename internal::plain_matrix_type<Derived>::type PlainObject;
00043 
00044   typedef typename internal::traits<Derived>::StorageKind StorageKind;
00045   typedef typename internal::traits<Derived>::Index Index;
00046 
00047   /** \returns a reference to the derived object */
00048   Derived& derived() { return *static_cast<Derived*>(this); }
00049   /** \returns a const reference to the derived object */
00050   const Derived& derived() const { return *static_cast<const Derived*>(this); }
00051 
00052   inline Derived& const_cast_derived() const
00053   { return *static_cast<Derived*>(const_cast<EigenBase*>(this)); }
00054   inline const Derived& const_derived() const
00055   { return *static_cast<const Derived*>(this); }
00056 
00057   /** \returns the number of rows. \sa cols(), RowsAtCompileTime */
00058   inline Index rows() const { return derived().rows(); }
00059   /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/
00060   inline Index cols() const { return derived().cols(); }
00061   /** \returns the number of coefficients, which is rows()*cols().
00062     * \sa rows(), cols(), SizeAtCompileTime. */
00063   inline Index size() const { return rows() * cols(); }
00064 
00065   /** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */
00066   template<typename Dest> inline void evalTo(Dest& dst) const
00067   { derived().evalTo(dst); }
00068 
00069   /** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */
00070   template<typename Dest> inline void addTo(Dest& dst) const
00071   {
00072     // This is the default implementation,
00073     // derived class can reimplement it in a more optimized way.
00074     typename Dest::PlainObject res(rows(),cols());
00075     evalTo(res);
00076     dst += res;
00077   }
00078 
00079   /** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */
00080   template<typename Dest> inline void subTo(Dest& dst) const
00081   {
00082     // This is the default implementation,
00083     // derived class can reimplement it in a more optimized way.
00084     typename Dest::PlainObject res(rows(),cols());
00085     evalTo(res);
00086     dst -= res;
00087   }
00088 
00089   /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */
00090   template<typename Dest> inline void applyThisOnTheRight(Dest& dst) const
00091   {
00092     // This is the default implementation,
00093     // derived class can reimplement it in a more optimized way.
00094     dst = dst * this->derived();
00095   }
00096 
00097   /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */
00098   template<typename Dest> inline void applyThisOnTheLeft(Dest& dst) const
00099   {
00100     // This is the default implementation,
00101     // derived class can reimplement it in a more optimized way.
00102     dst = this->derived() * dst;
00103   }
00104 
00105 };
00106 
00107 /***************************************************************************
00108 * Implementation of matrix base methods
00109 ***************************************************************************/
00110 
00111 /** \brief Copies the generic expression \a other into *this.
00112   *
00113   * \details The expression must provide a (templated) evalTo(Derived& dst) const
00114   * function which does the actual job. In practice, this allows any user to write
00115   * its own special matrix without having to modify MatrixBase
00116   *
00117   * \returns a reference to *this.
00118   */
00119 template<typename Derived>
00120 template<typename OtherDerived>
00121 Derived& DenseBase<Derived>::operator=(const EigenBase<OtherDerived> &other)
00122 {
00123   other.derived().evalTo(derived());
00124   return derived();
00125 }
00126 
00127 template<typename Derived>
00128 template<typename OtherDerived>
00129 Derived& DenseBase<Derived>::operator+=(const EigenBase<OtherDerived> &other)
00130 {
00131   other.derived().addTo(derived());
00132   return derived();
00133 }
00134 
00135 template<typename Derived>
00136 template<typename OtherDerived>
00137 Derived& DenseBase<Derived>::operator-=(const EigenBase<OtherDerived> &other)
00138 {
00139   other.derived().subTo(derived());
00140   return derived();
00141 }
00142 
00143 /** replaces \c *this by \c *this * \a other.
00144   *
00145   * \returns a reference to \c *this
00146   */
00147 template<typename Derived>
00148 template<typename OtherDerived>
00149 inline Derived&
00150 MatrixBase<Derived>::operator*=(const EigenBase<OtherDerived> &other)
00151 {
00152   other.derived().applyThisOnTheRight(derived());
00153   return derived();
00154 }
00155 
00156 /** replaces \c *this by \c *this * \a other. It is equivalent to MatrixBase::operator*=() */
00157 template<typename Derived>
00158 template<typename OtherDerived>
00159 inline void MatrixBase<Derived>::applyOnTheRight(const EigenBase<OtherDerived> &other)
00160 {
00161   other.derived().applyThisOnTheRight(derived());
00162 }
00163 
00164 /** replaces \c *this by \c *this * \a other. */
00165 template<typename Derived>
00166 template<typename OtherDerived>
00167 inline void MatrixBase<Derived>::applyOnTheLeft(const EigenBase<OtherDerived> &other)
00168 {
00169   other.derived().applyThisOnTheLeft(derived());
00170 }
00171 
00172 #endif // EIGEN_EIGENBASE_H



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011