Main MRPT website > C++ reference
MRPT logo

ArrayBase.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 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_ARRAYBASE_H
00026 #define EIGEN_ARRAYBASE_H
00027 
00028 template<typename ExpressionType> class MatrixWrapper;
00029 
00030 /** \class ArrayBase
00031   * \ingroup Core_Module
00032   *
00033   * \brief Base class for all 1D and 2D array, and related expressions
00034   *
00035   * An array is similar to a dense vector or matrix. While matrices are mathematical
00036   * objects with well defined linear algebra operators, an array is just a collection
00037   * of scalar values arranged in a one or two dimensionnal fashion. As the main consequence,
00038   * all operations applied to an array are performed coefficient wise. Furthermore,
00039   * arrays support scalar math functions of the c++ standard library (e.g., std::sin(x)), and convenient
00040   * constructors allowing to easily write generic code working for both scalar values
00041   * and arrays.
00042   *
00043   * This class is the base that is inherited by all array expression types.
00044   *
00045   * \param Derived is the derived type, e.g., an array or an expression type.
00046   *
00047   * \sa class MatrixBase, \ref TopicClassHierarchy
00048   */
00049 template<typename Derived> class ArrayBase
00050   : public DenseBase<Derived>
00051 {
00052   public:
00053 #ifndef EIGEN_PARSED_BY_DOXYGEN
00054     /** The base class for a given storage type. */
00055     typedef ArrayBase StorageBaseType;
00056 
00057     typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl;
00058 
00059     using internal::special_scalar_op_base<Derived,typename internal::traits<Derived>::Scalar,
00060                 typename NumTraits<typename internal::traits<Derived>::Scalar>::Real>::operator*;
00061 
00062     typedef typename internal::traits<Derived>::StorageKind StorageKind;
00063     typedef typename internal::traits<Derived>::Index Index;
00064     typedef typename internal::traits<Derived>::Scalar Scalar;
00065     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00066     typedef typename NumTraits<Scalar>::Real RealScalar;
00067 
00068     typedef DenseBase<Derived> Base;
00069     using Base::RowsAtCompileTime;
00070     using Base::ColsAtCompileTime;
00071     using Base::SizeAtCompileTime;
00072     using Base::MaxRowsAtCompileTime;
00073     using Base::MaxColsAtCompileTime;
00074     using Base::MaxSizeAtCompileTime;
00075     using Base::IsVectorAtCompileTime;
00076     using Base::Flags;
00077     using Base::CoeffReadCost;
00078 
00079     using Base::derived;
00080     using Base::const_cast_derived;
00081     using Base::rows;
00082     using Base::cols;
00083     using Base::size;
00084     using Base::coeff;
00085     using Base::coeffRef;
00086     using Base::lazyAssign;
00087     using Base::operator=;
00088     using Base::operator+=;
00089     using Base::operator-=;
00090     using Base::operator*=;
00091     using Base::operator/=;
00092 
00093     typedef typename Base::CoeffReturnType CoeffReturnType;
00094 
00095 #endif // not EIGEN_PARSED_BY_DOXYGEN
00096 
00097 #ifndef EIGEN_PARSED_BY_DOXYGEN
00098     /** \internal the plain matrix type corresponding to this expression. Note that is not necessarily
00099       * exactly the return type of eval(): in the case of plain matrices, the return type of eval() is a const
00100       * reference to a matrix, not a matrix! It is however guaranteed that the return type of eval() is either
00101       * PlainObject or const PlainObject&.
00102       */
00103     typedef Array<typename internal::traits<Derived>::Scalar,
00104                 internal::traits<Derived>::RowsAtCompileTime,
00105                 internal::traits<Derived>::ColsAtCompileTime,
00106                 AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
00107                 internal::traits<Derived>::MaxRowsAtCompileTime,
00108                 internal::traits<Derived>::MaxColsAtCompileTime
00109           > PlainObject;
00110 
00111 
00112     /** \internal Represents a matrix with all coefficients equal to one another*/
00113     typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType;
00114 #endif // not EIGEN_PARSED_BY_DOXYGEN
00115 
00116 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
00117 #   include "../plugins/CommonCwiseUnaryOps.h"
00118 #   include "../plugins/MatrixCwiseUnaryOps.h"
00119 #   include "../plugins/ArrayCwiseUnaryOps.h"
00120 #   include "../plugins/CommonCwiseBinaryOps.h"
00121 #   include "../plugins/MatrixCwiseBinaryOps.h"
00122 #   include "../plugins/ArrayCwiseBinaryOps.h"
00123 #   ifdef EIGEN_ARRAYBASE_PLUGIN
00124 #     include EIGEN_ARRAYBASE_PLUGIN
00125 #   endif
00126 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
00127 
00128     /** Special case of the template operator=, in order to prevent the compiler
00129       * from generating a default operator= (issue hit with g++ 4.1)
00130       */
00131     Derived& operator=(const ArrayBase& other)
00132     {
00133       return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
00134     }
00135 
00136     Derived& operator+=(const Scalar& scalar)
00137     { return *this = derived() + scalar; }
00138     Derived& operator-=(const Scalar& scalar)
00139     { return *this = derived() - scalar; }
00140 
00141     template<typename OtherDerived>
00142     Derived& operator+=(const ArrayBase<OtherDerived>& other);
00143     template<typename OtherDerived>
00144     Derived& operator-=(const ArrayBase<OtherDerived>& other);
00145 
00146     template<typename OtherDerived>
00147     Derived& operator*=(const ArrayBase<OtherDerived>& other);
00148 
00149     template<typename OtherDerived>
00150     Derived& operator/=(const ArrayBase<OtherDerived>& other);
00151 
00152   public:
00153     ArrayBase<Derived>& array() { return *this; }
00154     const ArrayBase<Derived>& array() const { return *this; }
00155 
00156     /** \returns an \link MatrixBase Matrix \endlink expression of this array
00157       * \sa MatrixBase::array() */
00158     MatrixWrapper<Derived> matrix() { return derived(); }
00159     const MatrixWrapper<Derived> matrix() const { return derived(); }
00160 
00161 //     template<typename Dest>
00162 //     inline void evalTo(Dest& dst) const { dst = matrix(); }
00163 
00164   protected:
00165     ArrayBase() : Base() {}
00166 
00167   private:
00168     explicit ArrayBase(Index);
00169     ArrayBase(Index,Index);
00170     template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&);
00171   protected:
00172     // mixing arrays and matrices is not legal
00173     template<typename OtherDerived> Derived& operator+=(const MatrixBase<OtherDerived>& mat)
00174     {EIGEN_STATIC_ASSERT(sizeof(typename OtherDerived::Scalar)==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);}
00175     // mixing arrays and matrices is not legal
00176     template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& mat)
00177     {EIGEN_STATIC_ASSERT(sizeof(typename OtherDerived::Scalar)==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);}
00178 };
00179 
00180 /** replaces \c *this by \c *this - \a other.
00181   *
00182   * \returns a reference to \c *this
00183   */
00184 template<typename Derived>
00185 template<typename OtherDerived>
00186 EIGEN_STRONG_INLINE Derived &
00187 ArrayBase<Derived>::operator-=(const ArrayBase<OtherDerived> &other)
00188 {
00189   SelfCwiseBinaryOp<internal::scalar_difference_op<Scalar>, Derived, OtherDerived> tmp(derived());
00190   tmp = other.derived();
00191   return derived();
00192 }
00193 
00194 /** replaces \c *this by \c *this + \a other.
00195   *
00196   * \returns a reference to \c *this
00197   */
00198 template<typename Derived>
00199 template<typename OtherDerived>
00200 EIGEN_STRONG_INLINE Derived &
00201 ArrayBase<Derived>::operator+=(const ArrayBase<OtherDerived>& other)
00202 {
00203   SelfCwiseBinaryOp<internal::scalar_sum_op<Scalar>, Derived, OtherDerived> tmp(derived());
00204   tmp = other.derived();
00205   return derived();
00206 }
00207 
00208 /** replaces \c *this by \c *this * \a other coefficient wise.
00209   *
00210   * \returns a reference to \c *this
00211   */
00212 template<typename Derived>
00213 template<typename OtherDerived>
00214 EIGEN_STRONG_INLINE Derived &
00215 ArrayBase<Derived>::operator*=(const ArrayBase<OtherDerived>& other)
00216 {
00217   SelfCwiseBinaryOp<internal::scalar_product_op<Scalar>, Derived, OtherDerived> tmp(derived());
00218   tmp = other.derived();
00219   return derived();
00220 }
00221 
00222 /** replaces \c *this by \c *this / \a other coefficient wise.
00223   *
00224   * \returns a reference to \c *this
00225   */
00226 template<typename Derived>
00227 template<typename OtherDerived>
00228 EIGEN_STRONG_INLINE Derived &
00229 ArrayBase<Derived>::operator/=(const ArrayBase<OtherDerived>& other)
00230 {
00231   SelfCwiseBinaryOp<internal::scalar_quotient_op<Scalar>, Derived, OtherDerived> tmp(derived());
00232   tmp = other.derived();
00233   return derived();
00234 }
00235 
00236 #endif // EIGEN_ARRAYBASE_H



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011