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 
00052 template<typename Derived> class ArrayBase
00053   : public DenseBase<Derived>
00054 {
00055   public:
00056 #ifndef EIGEN_PARSED_BY_DOXYGEN
00057 
00058     typedef ArrayBase StorageBaseType;
00059 
00060     typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl;
00061 
00062     using internal::special_scalar_op_base<Derived,typename internal::traits<Derived>::Scalar,
00063                 typename NumTraits<typename internal::traits<Derived>::Scalar>::Real>::operator*;
00064 
00065     typedef typename internal::traits<Derived>::StorageKind StorageKind;
00066     typedef typename internal::traits<Derived>::Index Index;
00067     typedef typename internal::traits<Derived>::Scalar Scalar;
00068     typedef typename internal::packet_traits<Scalar>::type PacketScalar;
00069     typedef typename NumTraits<Scalar>::Real RealScalar;
00070 
00071     typedef DenseBase<Derived> Base;
00072     using Base::RowsAtCompileTime;
00073     using Base::ColsAtCompileTime;
00074     using Base::SizeAtCompileTime;
00075     using Base::MaxRowsAtCompileTime;
00076     using Base::MaxColsAtCompileTime;
00077     using Base::MaxSizeAtCompileTime;
00078     using Base::IsVectorAtCompileTime;
00079     using Base::Flags;
00080     using Base::CoeffReadCost;
00081 
00082     using Base::derived;
00083     using Base::const_cast_derived;
00084     using Base::rows;
00085     using Base::cols;
00086     using Base::size;
00087     using Base::coeff;
00088     using Base::coeffRef;
00089     using Base::lazyAssign;
00090     using Base::operator=;
00091     using Base::operator+=;
00092     using Base::operator-=;
00093     using Base::operator*=;
00094     using Base::operator/=;
00095 
00096     typedef typename Base::CoeffReturnType CoeffReturnType;
00097 
00098 #endif // not EIGEN_PARSED_BY_DOXYGEN
00099 
00100 #ifndef EIGEN_PARSED_BY_DOXYGEN
00101 
00106     typedef Array<typename internal::traits<Derived>::Scalar,
00107                 internal::traits<Derived>::RowsAtCompileTime,
00108                 internal::traits<Derived>::ColsAtCompileTime,
00109                 AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
00110                 internal::traits<Derived>::MaxRowsAtCompileTime,
00111                 internal::traits<Derived>::MaxColsAtCompileTime
00112           > PlainObject;
00113 
00114 
00116     typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType;
00117 #endif // not EIGEN_PARSED_BY_DOXYGEN
00118 
00119 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
00120 #   include "../plugins/CommonCwiseUnaryOps.h"
00121 #   include "../plugins/MatrixCwiseUnaryOps.h"
00122 #   include "../plugins/ArrayCwiseUnaryOps.h"
00123 #   include "../plugins/CommonCwiseBinaryOps.h"
00124 #   include "../plugins/MatrixCwiseBinaryOps.h"
00125 #   include "../plugins/ArrayCwiseBinaryOps.h"
00126 #   ifdef EIGEN_ARRAYBASE_PLUGIN
00127 #     include EIGEN_ARRAYBASE_PLUGIN
00128 #   endif
00129 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
00130 
00134     Derived& operator=(const ArrayBase& other)
00135     {
00136       return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
00137     }
00138 
00139     Derived& operator+=(const Scalar& scalar)
00140     { return *this = derived() + scalar; }
00141     Derived& operator-=(const Scalar& scalar)
00142     { return *this = derived() - scalar; }
00143 
00144     template<typename OtherDerived>
00145     Derived& operator+=(const ArrayBase<OtherDerived>& other);
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     template<typename OtherDerived>
00153     Derived& operator/=(const ArrayBase<OtherDerived>& other);
00154 
00155   public:
00156     ArrayBase<Derived>& array() { return *this; }
00157     const ArrayBase<Derived>& array() const { return *this; }
00158 
00161     MatrixWrapper<Derived> matrix() { return derived(); }
00162     const MatrixWrapper<Derived> matrix() const { return derived(); }
00163 
00164 //     template<typename Dest>
00165 //     inline void evalTo(Dest& dst) const { dst = matrix(); }
00166 
00167   protected:
00168     ArrayBase() : Base() {}
00169 
00170   private:
00171     explicit ArrayBase(Index);
00172     ArrayBase(Index,Index);
00173     template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&);
00174   protected:
00175     // mixing arrays and matrices is not legal
00176     template<typename OtherDerived> Derived& operator+=(const MatrixBase<OtherDerived>& )
00177     {EIGEN_STATIC_ASSERT(sizeof(typename OtherDerived::Scalar)==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);}
00178     // mixing arrays and matrices is not legal
00179     template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& )
00180     {EIGEN_STATIC_ASSERT(sizeof(typename OtherDerived::Scalar)==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);}
00181 };
00182 
00187 template<typename Derived>
00188 template<typename OtherDerived>
00189 EIGEN_STRONG_INLINE Derived &
00190 ArrayBase<Derived>::operator-=(const ArrayBase<OtherDerived> &other)
00191 {
00192   SelfCwiseBinaryOp<internal::scalar_difference_op<Scalar>, Derived, OtherDerived> tmp(derived());
00193   tmp = other.derived();
00194   return derived();
00195 }
00196 
00201 template<typename Derived>
00202 template<typename OtherDerived>
00203 EIGEN_STRONG_INLINE Derived &
00204 ArrayBase<Derived>::operator+=(const ArrayBase<OtherDerived>& other)
00205 {
00206   SelfCwiseBinaryOp<internal::scalar_sum_op<Scalar>, Derived, OtherDerived> tmp(derived());
00207   tmp = other.derived();
00208   return derived();
00209 }
00210 
00215 template<typename Derived>
00216 template<typename OtherDerived>
00217 EIGEN_STRONG_INLINE Derived &
00218 ArrayBase<Derived>::operator*=(const ArrayBase<OtherDerived>& other)
00219 {
00220   SelfCwiseBinaryOp<internal::scalar_product_op<Scalar>, Derived, OtherDerived> tmp(derived());
00221   tmp = other.derived();
00222   return derived();
00223 }
00224 
00229 template<typename Derived>
00230 template<typename OtherDerived>
00231 EIGEN_STRONG_INLINE Derived &
00232 ArrayBase<Derived>::operator/=(const ArrayBase<OtherDerived>& other)
00233 {
00234   SelfCwiseBinaryOp<internal::scalar_quotient_op<Scalar>, Derived, OtherDerived> tmp(derived());
00235   tmp = other.derived();
00236   return derived();
00237 }
00238 
00239 #endif // EIGEN_ARRAYBASE_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:30:44