![]() |
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_ARRAY_H 00011 #define EIGEN_ARRAY_H 00012 00013 namespace Eigen { 00014 00015 namespace internal { 00016 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> 00017 struct traits<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > : traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > 00018 { 00019 typedef ArrayXpr XprKind; 00020 typedef ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > XprBase; 00021 }; 00022 } 00023 00044 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> 00045 class Array 00046 : public PlainObjectBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > 00047 { 00048 public: 00049 00050 typedef PlainObjectBase<Array> Base; 00051 EIGEN_DENSE_PUBLIC_INTERFACE(Array) 00052 00053 enum { Options = _Options }; 00054 typedef typename Base::PlainObject PlainObject; 00055 00056 protected: 00057 template <typename Derived, typename OtherDerived, bool IsVector> 00058 friend struct internal::conservative_resize_like_impl; 00059 00060 using Base::m_storage; 00061 00062 public: 00063 00064 using Base::base; 00065 using Base::coeff; 00066 using Base::coeffRef; 00067 00074 template<typename OtherDerived> 00075 EIGEN_DEVICE_FUNC 00076 EIGEN_STRONG_INLINE Array& operator=(const EigenBase<OtherDerived> &other) 00077 { 00078 return Base::operator=(other); 00079 } 00080 00084 /* This overload is needed because the usage of 00085 * using Base::operator=; 00086 * fails on MSVC. Since the code below is working with GCC and MSVC, we skipped 00087 * the usage of 'using'. This should be done only for operator=. 00088 */ 00089 EIGEN_DEVICE_FUNC 00090 EIGEN_STRONG_INLINE Array& operator=(const Scalar &value) 00091 { 00092 Base::setConstant(value); 00093 return *this; 00094 } 00095 00105 template<typename OtherDerived> 00106 EIGEN_DEVICE_FUNC 00107 EIGEN_STRONG_INLINE Array& operator=(const DenseBase<OtherDerived>& other) 00108 { 00109 return Base::_set(other); 00110 } 00111 00115 EIGEN_DEVICE_FUNC 00116 EIGEN_STRONG_INLINE Array& operator=(const Array& other) 00117 { 00118 return Base::_set(other); 00119 } 00120 00131 EIGEN_DEVICE_FUNC 00132 EIGEN_STRONG_INLINE Array() : Base() 00133 { 00134 Base::_check_template_params(); 00135 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED 00136 } 00137 00138 #ifndef EIGEN_PARSED_BY_DOXYGEN 00139 // FIXME is it still needed ?? 00141 EIGEN_DEVICE_FUNC 00142 Array(internal::constructor_without_unaligned_array_assert) 00143 : Base(internal::constructor_without_unaligned_array_assert()) 00144 { 00145 Base::_check_template_params(); 00146 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED 00147 } 00148 #endif 00149 00150 #if EIGEN_HAS_RVALUE_REFERENCES 00151 EIGEN_DEVICE_FUNC 00152 Array(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value) 00153 : Base(std::move(other)) 00154 { 00155 Base::_check_template_params(); 00156 if (RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic) 00157 Base::_set_noalias(other); 00158 } 00159 EIGEN_DEVICE_FUNC 00160 Array& operator=(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value) 00161 { 00162 other.swap(*this); 00163 return *this; 00164 } 00165 #endif 00166 00167 #ifndef EIGEN_PARSED_BY_DOXYGEN 00168 template<typename T> 00169 EIGEN_DEVICE_FUNC 00170 EIGEN_STRONG_INLINE explicit Array(const T& x) 00171 { 00172 Base::_check_template_params(); 00173 Base::template _init1<T>(x); 00174 } 00175 00176 template<typename T0, typename T1> 00177 EIGEN_DEVICE_FUNC 00178 EIGEN_STRONG_INLINE Array(const T0& val0, const T1& val1) 00179 { 00180 Base::_check_template_params(); 00181 this->template _init2<T0,T1>(val0, val1); 00182 } 00183 #else 00184 00185 EIGEN_DEVICE_FUNC explicit Array(const Scalar *data); 00192 EIGEN_DEVICE_FUNC 00193 EIGEN_STRONG_INLINE explicit Array(Index dim); 00195 Array(const Scalar& value); 00201 Array(Index rows, Index cols); 00203 Array(const Scalar& val0, const Scalar& val1); 00204 #endif 00205 00207 EIGEN_DEVICE_FUNC 00208 EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2) 00209 { 00210 Base::_check_template_params(); 00211 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 3) 00212 m_storage.data()[0] = val0; 00213 m_storage.data()[1] = val1; 00214 m_storage.data()[2] = val2; 00215 } 00217 EIGEN_DEVICE_FUNC 00218 EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2, const Scalar& val3) 00219 { 00220 Base::_check_template_params(); 00221 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 4) 00222 m_storage.data()[0] = val0; 00223 m_storage.data()[1] = val1; 00224 m_storage.data()[2] = val2; 00225 m_storage.data()[3] = val3; 00226 } 00227 00229 EIGEN_DEVICE_FUNC 00230 EIGEN_STRONG_INLINE Array(const Array& other) 00231 : Base(other) 00232 { } 00233 00235 template<typename OtherDerived> 00236 EIGEN_DEVICE_FUNC 00237 EIGEN_STRONG_INLINE Array(const EigenBase<OtherDerived> &other) 00238 : Base(other.derived()) 00239 { } 00240 00241 EIGEN_DEVICE_FUNC inline Index innerStride() const { return 1; } 00242 EIGEN_DEVICE_FUNC inline Index outerStride() const { return this->innerSize(); } 00243 00244 #ifdef EIGEN_ARRAY_PLUGIN 00245 #include EIGEN_ARRAY_PLUGIN 00246 #endif 00247 00248 private: 00249 00250 template<typename MatrixType, typename OtherDerived, bool SwapPointers> 00251 friend struct internal::matrix_swap_impl; 00252 }; 00253 00273 #define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ 00274 \ 00275 typedef Array<Type, Size, Size> Array##SizeSuffix##SizeSuffix##TypeSuffix; \ 00276 \ 00277 typedef Array<Type, Size, 1> Array##SizeSuffix##TypeSuffix; 00278 00279 #define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \ 00280 \ 00281 typedef Array<Type, Size, Dynamic> Array##Size##X##TypeSuffix; \ 00282 \ 00283 typedef Array<Type, Dynamic, Size> Array##X##Size##TypeSuffix; 00284 00285 #define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \ 00286 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \ 00287 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \ 00288 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \ 00289 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \ 00290 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \ 00291 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \ 00292 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4) 00293 00294 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(int, i) 00295 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(float, f) 00296 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(double, d) 00297 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<float>, cf) 00298 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<double>, cd) 00299 00300 #undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES 00301 #undef EIGEN_MAKE_ARRAY_TYPEDEFS 00302 00303 #undef EIGEN_MAKE_ARRAY_TYPEDEFS_LARGE 00304 00305 #define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \ 00306 using Eigen::Matrix##SizeSuffix##TypeSuffix; \ 00307 using Eigen::Vector##SizeSuffix##TypeSuffix; \ 00308 using Eigen::RowVector##SizeSuffix##TypeSuffix; 00309 00310 #define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \ 00311 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \ 00312 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \ 00313 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \ 00314 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) \ 00315 00316 #define EIGEN_USING_ARRAY_TYPEDEFS \ 00317 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \ 00318 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \ 00319 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \ 00320 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \ 00321 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd) 00322 00323 } // end namespace Eigen 00324 00325 #endif // EIGEN_ARRAY_H