Array.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_ARRAY_H
00026 #define EIGEN_ARRAY_H
00027 
00045 namespace internal {
00046 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00047 struct traits<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > : traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
00048 {
00049   typedef ArrayXpr XprKind;
00050   typedef ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > XprBase;
00051 };
00052 }
00053 
00054 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00055 class Array
00056   : public PlainObjectBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
00057 {
00058   public:
00059 
00060     typedef PlainObjectBase<Array> Base;
00061     EIGEN_DENSE_PUBLIC_INTERFACE(Array)
00062 
00063     enum { Options = _Options };
00064     typedef typename Base::PlainObject PlainObject;
00065 
00066   protected:
00067     template <typename Derived, typename OtherDerived, bool IsVector>
00068     friend struct internal::conservative_resize_like_impl;
00069 
00070     using Base::m_storage;
00071   public:
00072     enum { NeedsToAlign = (!(Options&DontAlign))
00073                           && SizeAtCompileTime!=Dynamic && ((static_cast<int>(sizeof(Scalar))*SizeAtCompileTime)%16)==0 };
00074     EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
00075 
00076     using Base::base;
00077     using Base::coeff;
00078     using Base::coeffRef;
00079 
00086     template<typename OtherDerived>
00087     EIGEN_STRONG_INLINE Array& operator=(const EigenBase<OtherDerived> &other)
00088     {
00089       return Base::operator=(other);
00090     }
00091 
00101     template<typename OtherDerived>
00102     EIGEN_STRONG_INLINE Array& operator=(const ArrayBase<OtherDerived>& other)
00103     {
00104       return Base::_set(other);
00105     }
00106 
00110     EIGEN_STRONG_INLINE Array& operator=(const Array& other)
00111     {
00112       return Base::_set(other);
00113     }
00114 
00125     EIGEN_STRONG_INLINE explicit Array() : Base()
00126     {
00127       Base::_check_template_params();
00128       EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
00129     }
00130 
00131 #ifndef EIGEN_PARSED_BY_DOXYGEN
00132     // FIXME is it still needed ??
00134     Array(internal::constructor_without_unaligned_array_assert)
00135       : Base(internal::constructor_without_unaligned_array_assert())
00136     {
00137       Base::_check_template_params();
00138       EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
00139     }
00140 #endif
00141 
00148     EIGEN_STRONG_INLINE explicit Array(Index dim)
00149       : Base(dim, RowsAtCompileTime == 1 ? 1 : dim, ColsAtCompileTime == 1 ? 1 : dim)
00150     {
00151       Base::_check_template_params();
00152       EIGEN_STATIC_ASSERT_VECTOR_ONLY(Array)
00153       eigen_assert(dim >= 0);
00154       eigen_assert(SizeAtCompileTime == Dynamic || SizeAtCompileTime == dim);
00155       EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
00156     }
00157 
00158     #ifndef EIGEN_PARSED_BY_DOXYGEN
00159     template<typename T0, typename T1>
00160     EIGEN_STRONG_INLINE Array(const T0& x, const T1& y)
00161     {
00162       Base::_check_template_params();
00163       this->template _init2<T0,T1>(x, y);
00164     }
00165     #else
00166 
00171     Array(Index rows, Index cols);
00173     Array(const Scalar& x, const Scalar& y);
00174     #endif
00175 
00177     EIGEN_STRONG_INLINE Array(const Scalar& x, const Scalar& y, const Scalar& z)
00178     {
00179       Base::_check_template_params();
00180       EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 3)
00181       m_storage.data()[0] = x;
00182       m_storage.data()[1] = y;
00183       m_storage.data()[2] = z;
00184     }
00186     EIGEN_STRONG_INLINE Array(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
00187     {
00188       Base::_check_template_params();
00189       EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 4)
00190       m_storage.data()[0] = x;
00191       m_storage.data()[1] = y;
00192       m_storage.data()[2] = z;
00193       m_storage.data()[3] = w;
00194     }
00195 
00196     explicit Array(const Scalar *data);
00197 
00199     template<typename OtherDerived>
00200     EIGEN_STRONG_INLINE Array(const ArrayBase<OtherDerived>& other)
00201              : Base(other.rows() * other.cols(), other.rows(), other.cols())
00202     {
00203       Base::_check_template_params();
00204       Base::_set_noalias(other);
00205     }
00207     EIGEN_STRONG_INLINE Array(const Array& other)
00208             : Base(other.rows() * other.cols(), other.rows(), other.cols())
00209     {
00210       Base::_check_template_params();
00211       Base::_set_noalias(other);
00212     }
00214     template<typename OtherDerived>
00215     EIGEN_STRONG_INLINE Array(const ReturnByValue<OtherDerived>& other)
00216     {
00217       Base::_check_template_params();
00218       Base::resize(other.rows(), other.cols());
00219       other.evalTo(*this);
00220     }
00221 
00223     template<typename OtherDerived>
00224     EIGEN_STRONG_INLINE Array(const EigenBase<OtherDerived> &other)
00225       : Base(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols())
00226     {
00227       Base::_check_template_params();
00228       Base::resize(other.rows(), other.cols());
00229       *this = other;
00230     }
00231 
00235     template<typename OtherDerived>
00236     void swap(ArrayBase<OtherDerived> const & other)
00237     { this->_swap(other.derived()); }
00238 
00239     inline Index innerStride() const { return 1; }
00240     inline Index outerStride() const { return this->innerSize(); }
00241 
00242     #ifdef EIGEN_ARRAY_PLUGIN
00243     #include EIGEN_ARRAY_PLUGIN
00244     #endif
00245 
00246   private:
00247 
00248     template<typename MatrixType, typename OtherDerived, bool SwapPointers>
00249     friend struct internal::matrix_swap_impl;
00250 };
00251 
00271 #define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix)   \
00272                                     \
00273 typedef Array<Type, Size, Size> Array##SizeSuffix##SizeSuffix##TypeSuffix;  \
00274                                     \
00275 typedef Array<Type, Size, 1>    Array##SizeSuffix##TypeSuffix;
00276 
00277 #define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size)         \
00278                                     \
00279 typedef Array<Type, Size, Dynamic> Array##Size##X##TypeSuffix;  \
00280                                     \
00281 typedef Array<Type, Dynamic, Size> Array##X##Size##TypeSuffix;
00282 
00283 #define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
00284 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \
00285 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \
00286 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \
00287 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
00288 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
00289 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
00290 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
00291 
00292 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(int,                  i)
00293 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(float,                f)
00294 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(double,               d)
00295 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<float>,  cf)
00296 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
00297 
00298 #undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES
00299 #undef EIGEN_MAKE_ARRAY_TYPEDEFS
00300 
00301 #undef EIGEN_MAKE_ARRAY_TYPEDEFS_LARGE
00302 
00303 #define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \
00304 using Eigen::Matrix##SizeSuffix##TypeSuffix; \
00305 using Eigen::Vector##SizeSuffix##TypeSuffix; \
00306 using Eigen::RowVector##SizeSuffix##TypeSuffix;
00307 
00308 #define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \
00309 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \
00310 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \
00311 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \
00312 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) \
00313 
00314 #define EIGEN_USING_ARRAY_TYPEDEFS \
00315 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \
00316 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \
00317 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \
00318 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \
00319 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd)
00320 
00321 
00322 #endif // EIGEN_ARRAY_H


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