![]() |
Eigen
3.3.3
|
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 // This Source Code Form is subject to the terms of the Mozilla 00007 // Public License v. 2.0. If a copy of the MPL was not distributed 00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00009 00010 #ifndef EIGEN_ARRAYBASE_H 00011 #define EIGEN_ARRAYBASE_H 00012 00013 namespace Eigen { 00014 00015 template<typename ExpressionType> class MatrixWrapper; 00016 00039 template<typename Derived> class ArrayBase 00040 : public DenseBase<Derived> 00041 { 00042 public: 00043 #ifndef EIGEN_PARSED_BY_DOXYGEN 00044 00045 typedef ArrayBase StorageBaseType; 00046 00047 typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl; 00048 00049 typedef typename internal::traits<Derived>::StorageKind StorageKind; 00050 typedef typename internal::traits<Derived>::Scalar Scalar; 00051 typedef typename internal::packet_traits<Scalar>::type PacketScalar; 00052 typedef typename NumTraits<Scalar>::Real RealScalar; 00053 00054 typedef DenseBase<Derived> Base; 00055 using Base::RowsAtCompileTime; 00056 using Base::ColsAtCompileTime; 00057 using Base::SizeAtCompileTime; 00058 using Base::MaxRowsAtCompileTime; 00059 using Base::MaxColsAtCompileTime; 00060 using Base::MaxSizeAtCompileTime; 00061 using Base::IsVectorAtCompileTime; 00062 using Base::Flags; 00063 00064 using Base::derived; 00065 using Base::const_cast_derived; 00066 using Base::rows; 00067 using Base::cols; 00068 using Base::size; 00069 using Base::coeff; 00070 using Base::coeffRef; 00071 using Base::lazyAssign; 00072 using Base::operator=; 00073 using Base::operator+=; 00074 using Base::operator-=; 00075 using Base::operator*=; 00076 using Base::operator/=; 00077 00078 typedef typename Base::CoeffReturnType CoeffReturnType; 00079 00080 #endif // not EIGEN_PARSED_BY_DOXYGEN 00081 00082 #ifndef EIGEN_PARSED_BY_DOXYGEN 00083 typedef typename Base::PlainObject PlainObject; 00084 00086 typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType; 00087 #endif // not EIGEN_PARSED_BY_DOXYGEN 00088 00089 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase 00090 #define EIGEN_DOC_UNARY_ADDONS(X,Y) 00091 # include "../plugins/CommonCwiseUnaryOps.h" 00092 # include "../plugins/MatrixCwiseUnaryOps.h" 00093 # include "../plugins/ArrayCwiseUnaryOps.h" 00094 # include "../plugins/CommonCwiseBinaryOps.h" 00095 # include "../plugins/MatrixCwiseBinaryOps.h" 00096 # include "../plugins/ArrayCwiseBinaryOps.h" 00097 # ifdef EIGEN_ARRAYBASE_PLUGIN 00098 # include EIGEN_ARRAYBASE_PLUGIN 00099 # endif 00100 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS 00101 #undef EIGEN_DOC_UNARY_ADDONS 00102 00106 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00107 Derived& operator=(const ArrayBase& other) 00108 { 00109 internal::call_assignment(derived(), other.derived()); 00110 return derived(); 00111 } 00112 00115 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00116 Derived& operator=(const Scalar &value) 00117 { Base::setConstant(value); return derived(); } 00118 00119 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00120 Derived& operator+=(const Scalar& scalar); 00121 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00122 Derived& operator-=(const Scalar& scalar); 00123 00124 template<typename OtherDerived> 00125 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00126 Derived& operator+=(const ArrayBase<OtherDerived>& other); 00127 template<typename OtherDerived> 00128 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00129 Derived& operator-=(const ArrayBase<OtherDerived>& other); 00130 00131 template<typename OtherDerived> 00132 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00133 Derived& operator*=(const ArrayBase<OtherDerived>& other); 00134 00135 template<typename OtherDerived> 00136 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 00137 Derived& operator/=(const ArrayBase<OtherDerived>& other); 00138 00139 public: 00140 EIGEN_DEVICE_FUNC 00141 ArrayBase<Derived>& array() { return *this; } 00142 EIGEN_DEVICE_FUNC 00143 const ArrayBase<Derived>& array() const { return *this; } 00144 00147 EIGEN_DEVICE_FUNC 00148 MatrixWrapper<Derived> matrix() { return MatrixWrapper<Derived>(derived()); } 00149 EIGEN_DEVICE_FUNC 00150 const MatrixWrapper<const Derived> matrix() const { return MatrixWrapper<const Derived>(derived()); } 00151 00152 // template<typename Dest> 00153 // inline void evalTo(Dest& dst) const { dst = matrix(); } 00154 00155 protected: 00156 EIGEN_DEVICE_FUNC 00157 ArrayBase() : Base() {} 00158 00159 private: 00160 explicit ArrayBase(Index); 00161 ArrayBase(Index,Index); 00162 template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&); 00163 protected: 00164 // mixing arrays and matrices is not legal 00165 template<typename OtherDerived> Derived& operator+=(const MatrixBase<OtherDerived>& ) 00166 {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;} 00167 // mixing arrays and matrices is not legal 00168 template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& ) 00169 {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;} 00170 }; 00171 00176 template<typename Derived> 00177 template<typename OtherDerived> 00178 EIGEN_STRONG_INLINE Derived & 00179 ArrayBase<Derived>::operator-=(const ArrayBase<OtherDerived> &other) 00180 { 00181 call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>()); 00182 return derived(); 00183 } 00184 00189 template<typename Derived> 00190 template<typename OtherDerived> 00191 EIGEN_STRONG_INLINE Derived & 00192 ArrayBase<Derived>::operator+=(const ArrayBase<OtherDerived>& other) 00193 { 00194 call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>()); 00195 return derived(); 00196 } 00197 00202 template<typename Derived> 00203 template<typename OtherDerived> 00204 EIGEN_STRONG_INLINE Derived & 00205 ArrayBase<Derived>::operator*=(const ArrayBase<OtherDerived>& other) 00206 { 00207 call_assignment(derived(), other.derived(), internal::mul_assign_op<Scalar,typename OtherDerived::Scalar>()); 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 call_assignment(derived(), other.derived(), internal::div_assign_op<Scalar,typename OtherDerived::Scalar>()); 00221 return derived(); 00222 } 00223 00224 } // end namespace Eigen 00225 00226 #endif // EIGEN_ARRAYBASE_H