Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:56:10

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_ARRAYBASE_H
0011 #define EIGEN_ARRAYBASE_H
0012 
0013 namespace Eigen { 
0014 
0015 template<typename ExpressionType> class MatrixWrapper;
0016 
0017 /** \class ArrayBase
0018   * \ingroup Core_Module
0019   *
0020   * \brief Base class for all 1D and 2D array, and related expressions
0021   *
0022   * An array is similar to a dense vector or matrix. While matrices are mathematical
0023   * objects with well defined linear algebra operators, an array is just a collection
0024   * of scalar values arranged in a one or two dimensionnal fashion. As the main consequence,
0025   * all operations applied to an array are performed coefficient wise. Furthermore,
0026   * arrays support scalar math functions of the c++ standard library (e.g., std::sin(x)), and convenient
0027   * constructors allowing to easily write generic code working for both scalar values
0028   * and arrays.
0029   *
0030   * This class is the base that is inherited by all array expression types.
0031   *
0032   * \tparam Derived is the derived type, e.g., an array or an expression type.
0033   *
0034   * This class can be extended with the help of the plugin mechanism described on the page
0035   * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAYBASE_PLUGIN.
0036   *
0037   * \sa class MatrixBase, \ref TopicClassHierarchy
0038   */
0039 template<typename Derived> class ArrayBase
0040   : public DenseBase<Derived>
0041 {
0042   public:
0043 #ifndef EIGEN_PARSED_BY_DOXYGEN
0044     /** The base class for a given storage type. */
0045     typedef ArrayBase StorageBaseType;
0046 
0047     typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl;
0048 
0049     typedef typename internal::traits<Derived>::StorageKind StorageKind;
0050     typedef typename internal::traits<Derived>::Scalar Scalar;
0051     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
0052     typedef typename NumTraits<Scalar>::Real RealScalar;
0053 
0054     typedef DenseBase<Derived> Base;
0055     using Base::RowsAtCompileTime;
0056     using Base::ColsAtCompileTime;
0057     using Base::SizeAtCompileTime;
0058     using Base::MaxRowsAtCompileTime;
0059     using Base::MaxColsAtCompileTime;
0060     using Base::MaxSizeAtCompileTime;
0061     using Base::IsVectorAtCompileTime;
0062     using Base::Flags;
0063     
0064     using Base::derived;
0065     using Base::const_cast_derived;
0066     using Base::rows;
0067     using Base::cols;
0068     using Base::size;
0069     using Base::coeff;
0070     using Base::coeffRef;
0071     using Base::lazyAssign;
0072     using Base::operator-;
0073     using Base::operator=;
0074     using Base::operator+=;
0075     using Base::operator-=;
0076     using Base::operator*=;
0077     using Base::operator/=;
0078 
0079     typedef typename Base::CoeffReturnType CoeffReturnType;
0080 
0081 #endif // not EIGEN_PARSED_BY_DOXYGEN
0082 
0083 #ifndef EIGEN_PARSED_BY_DOXYGEN
0084     typedef typename Base::PlainObject PlainObject;
0085 
0086     /** \internal Represents a matrix with all coefficients equal to one another*/
0087     typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
0088 #endif // not EIGEN_PARSED_BY_DOXYGEN
0089 
0090 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
0091 #define EIGEN_DOC_UNARY_ADDONS(X,Y)
0092 #   include "../plugins/MatrixCwiseUnaryOps.h"
0093 #   include "../plugins/ArrayCwiseUnaryOps.h"
0094 #   include "../plugins/CommonCwiseBinaryOps.h"
0095 #   include "../plugins/MatrixCwiseBinaryOps.h"
0096 #   include "../plugins/ArrayCwiseBinaryOps.h"
0097 #   ifdef EIGEN_ARRAYBASE_PLUGIN
0098 #     include EIGEN_ARRAYBASE_PLUGIN
0099 #   endif
0100 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
0101 #undef EIGEN_DOC_UNARY_ADDONS
0102 
0103     /** Special case of the template operator=, in order to prevent the compiler
0104       * from generating a default operator= (issue hit with g++ 4.1)
0105       */
0106     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0107     Derived& operator=(const ArrayBase& other)
0108     {
0109       internal::call_assignment(derived(), other.derived());
0110       return derived();
0111     }
0112     
0113     /** Set all the entries to \a value.
0114       * \sa DenseBase::setConstant(), DenseBase::fill() */
0115     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0116     Derived& operator=(const Scalar &value)
0117     { Base::setConstant(value); return derived(); }
0118 
0119     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0120     Derived& operator+=(const Scalar& scalar);
0121     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0122     Derived& operator-=(const Scalar& scalar);
0123 
0124     template<typename OtherDerived>
0125     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0126     Derived& operator+=(const ArrayBase<OtherDerived>& other);
0127     template<typename OtherDerived>
0128     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0129     Derived& operator-=(const ArrayBase<OtherDerived>& other);
0130 
0131     template<typename OtherDerived>
0132     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0133     Derived& operator*=(const ArrayBase<OtherDerived>& other);
0134 
0135     template<typename OtherDerived>
0136     EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0137     Derived& operator/=(const ArrayBase<OtherDerived>& other);
0138 
0139   public:
0140     EIGEN_DEVICE_FUNC
0141     ArrayBase<Derived>& array() { return *this; }
0142     EIGEN_DEVICE_FUNC
0143     const ArrayBase<Derived>& array() const { return *this; }
0144 
0145     /** \returns an \link Eigen::MatrixBase Matrix \endlink expression of this array
0146       * \sa MatrixBase::array() */
0147     EIGEN_DEVICE_FUNC
0148     MatrixWrapper<Derived> matrix() { return MatrixWrapper<Derived>(derived()); }
0149     EIGEN_DEVICE_FUNC
0150     const MatrixWrapper<const Derived> matrix() const { return MatrixWrapper<const Derived>(derived()); }
0151 
0152 //     template<typename Dest>
0153 //     inline void evalTo(Dest& dst) const { dst = matrix(); }
0154 
0155   protected:
0156     EIGEN_DEFAULT_COPY_CONSTRUCTOR(ArrayBase)
0157     EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(ArrayBase)
0158 
0159   private:
0160     explicit ArrayBase(Index);
0161     ArrayBase(Index,Index);
0162     template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&);
0163   protected:
0164     // mixing arrays and matrices is not legal
0165     template<typename OtherDerived> Derived& operator+=(const MatrixBase<OtherDerived>& )
0166     {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
0167     // mixing arrays and matrices is not legal
0168     template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& )
0169     {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
0170 };
0171 
0172 /** replaces \c *this by \c *this - \a other.
0173   *
0174   * \returns a reference to \c *this
0175   */
0176 template<typename Derived>
0177 template<typename OtherDerived>
0178 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
0179 ArrayBase<Derived>::operator-=(const ArrayBase<OtherDerived> &other)
0180 {
0181   call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
0182   return derived();
0183 }
0184 
0185 /** replaces \c *this by \c *this + \a other.
0186   *
0187   * \returns a reference to \c *this
0188   */
0189 template<typename Derived>
0190 template<typename OtherDerived>
0191 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
0192 ArrayBase<Derived>::operator+=(const ArrayBase<OtherDerived>& other)
0193 {
0194   call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
0195   return derived();
0196 }
0197 
0198 /** replaces \c *this by \c *this * \a other coefficient wise.
0199   *
0200   * \returns a reference to \c *this
0201   */
0202 template<typename Derived>
0203 template<typename OtherDerived>
0204 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
0205 ArrayBase<Derived>::operator*=(const ArrayBase<OtherDerived>& other)
0206 {
0207   call_assignment(derived(), other.derived(), internal::mul_assign_op<Scalar,typename OtherDerived::Scalar>());
0208   return derived();
0209 }
0210 
0211 /** replaces \c *this by \c *this / \a other coefficient wise.
0212   *
0213   * \returns a reference to \c *this
0214   */
0215 template<typename Derived>
0216 template<typename OtherDerived>
0217 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived &
0218 ArrayBase<Derived>::operator/=(const ArrayBase<OtherDerived>& other)
0219 {
0220   call_assignment(derived(), other.derived(), internal::div_assign_op<Scalar,typename OtherDerived::Scalar>());
0221   return derived();
0222 }
0223 
0224 } // end namespace Eigen
0225 
0226 #endif // EIGEN_ARRAYBASE_H