Matrix.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) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_MATRIX_H
00027 #define EIGEN_MATRIX_H
00028 
00117 namespace internal {
00118 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00119 struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
00120 {
00121   typedef _Scalar Scalar;
00122   typedef Dense StorageKind;
00123   typedef DenseIndex Index;
00124   typedef MatrixXpr XprKind;
00125   enum {
00126     RowsAtCompileTime = _Rows,
00127     ColsAtCompileTime = _Cols,
00128     MaxRowsAtCompileTime = _MaxRows,
00129     MaxColsAtCompileTime = _MaxCols,
00130     Flags = compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret,
00131     CoeffReadCost = NumTraits<Scalar>::ReadCost,
00132     Options = _Options,
00133     InnerStrideAtCompileTime = 1,
00134     OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime
00135   };
00136 };
00137 }
00138 
00139 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00140 class Matrix
00141   : public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
00142 {
00143   public:
00144 
00148     typedef PlainObjectBase<Matrix> Base;
00149 
00150     enum { Options = _Options };
00151 
00152     EIGEN_DENSE_PUBLIC_INTERFACE(Matrix)
00153 
00154     typedef typename Base::PlainObject PlainObject;
00155 
00156     enum { NeedsToAlign = (!(Options&DontAlign))
00157                           && SizeAtCompileTime!=Dynamic && ((static_cast<int>(sizeof(Scalar))*SizeAtCompileTime)%16)==0 };
00158     EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
00159 
00160     using Base::base;
00161     using Base::coeffRef;
00162 
00171     EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other)
00172     {
00173       return Base::_set(other);
00174     }
00175 
00186     template<typename OtherDerived>
00187     EIGEN_STRONG_INLINE Matrix& operator=(const MatrixBase<OtherDerived>& other)
00188     {
00189       return Base::_set(other);
00190     }
00191 
00192     /* Here, doxygen failed to copy the brief information when using \copydoc */
00193 
00198     template<typename OtherDerived>
00199     EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived> &other)
00200     {
00201       return Base::operator=(other);
00202     }
00203 
00204     template<typename OtherDerived>
00205     EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func)
00206     {
00207       return Base::operator=(func);
00208     }
00209 
00220     EIGEN_STRONG_INLINE explicit Matrix() : Base()
00221     {
00222       Base::_check_template_params();
00223       EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
00224     }
00225 
00226     // FIXME is it still needed
00227     Matrix(internal::constructor_without_unaligned_array_assert)
00228       : Base(internal::constructor_without_unaligned_array_assert())
00229     { Base::_check_template_params(); EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED }
00230 
00237     EIGEN_STRONG_INLINE explicit Matrix(Index dim)
00238       : Base(dim, RowsAtCompileTime == 1 ? 1 : dim, ColsAtCompileTime == 1 ? 1 : dim)
00239     {
00240       Base::_check_template_params();
00241       EIGEN_STATIC_ASSERT_VECTOR_ONLY(Matrix)
00242       eigen_assert(dim >= 0);
00243       eigen_assert(SizeAtCompileTime == Dynamic || SizeAtCompileTime == dim);
00244       EIGEN_INITIALIZE_BY_ZERO_IF_THAT_OPTION_IS_ENABLED
00245     }
00246 
00247     #ifndef EIGEN_PARSED_BY_DOXYGEN
00248     template<typename T0, typename T1>
00249     EIGEN_STRONG_INLINE Matrix(const T0& x, const T1& y)
00250     {
00251       Base::_check_template_params();
00252       Base::template _init2<T0,T1>(x, y);
00253     }
00254     #else
00255 
00260     Matrix(Index rows, Index cols);
00262     Matrix(const Scalar& x, const Scalar& y);
00263     #endif
00264 
00266     EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
00267     {
00268       Base::_check_template_params();
00269       EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3)
00270       m_storage.data()[0] = x;
00271       m_storage.data()[1] = y;
00272       m_storage.data()[2] = z;
00273     }
00275     EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
00276     {
00277       Base::_check_template_params();
00278       EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4)
00279       m_storage.data()[0] = x;
00280       m_storage.data()[1] = y;
00281       m_storage.data()[2] = z;
00282       m_storage.data()[3] = w;
00283     }
00284 
00285     explicit Matrix(const Scalar *data);
00286 
00288     template<typename OtherDerived>
00289     EIGEN_STRONG_INLINE Matrix(const MatrixBase<OtherDerived>& other)
00290              : Base(other.rows() * other.cols(), other.rows(), other.cols())
00291     {
00292       // This test resides here, to bring the error messages closer to the user. Normally, these checks
00293       // are performed deeply within the library, thus causing long and scary error traces.
00294       EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
00295         YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
00296 
00297       Base::_check_template_params();
00298       Base::_set_noalias(other);
00299     }
00301     EIGEN_STRONG_INLINE Matrix(const Matrix& other)
00302             : Base(other.rows() * other.cols(), other.rows(), other.cols())
00303     {
00304       Base::_check_template_params();
00305       Base::_set_noalias(other);
00306     }
00308     template<typename OtherDerived>
00309     EIGEN_STRONG_INLINE Matrix(const ReturnByValue<OtherDerived>& other)
00310     {
00311       Base::_check_template_params();
00312       Base::resize(other.rows(), other.cols());
00313       other.evalTo(*this);
00314     }
00315 
00319     template<typename OtherDerived>
00320     EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived> &other)
00321       : Base(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols())
00322     {
00323       Base::_check_template_params();
00324       Base::resize(other.rows(), other.cols());
00325       // FIXME/CHECK: isn't *this = other.derived() more efficient. it allows to
00326       //              go for pure _set() implementations, right?
00327       *this = other;
00328     }
00329 
00334     template<typename OtherDerived>
00335     void swap(MatrixBase<OtherDerived> const & other)
00336     { this->_swap(other.derived()); }
00337 
00338     inline Index innerStride() const { return 1; }
00339     inline Index outerStride() const { return this->innerSize(); }
00340 
00342 
00343     template<typename OtherDerived>
00344     explicit Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
00345     template<typename OtherDerived>
00346     Matrix& operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
00347 
00348     #ifdef EIGEN2_SUPPORT
00349     template<typename OtherDerived>
00350     explicit Matrix(const eigen2_RotationBase<OtherDerived,ColsAtCompileTime>& r);
00351     template<typename OtherDerived>
00352     Matrix& operator=(const eigen2_RotationBase<OtherDerived,ColsAtCompileTime>& r);
00353     #endif
00354 
00355     // allow to extend Matrix outside Eigen
00356     #ifdef EIGEN_MATRIX_PLUGIN
00357     #include EIGEN_MATRIX_PLUGIN
00358     #endif
00359 
00360   protected:
00361     template <typename Derived, typename OtherDerived, bool IsVector>
00362     friend struct internal::conservative_resize_like_impl;
00363 
00364     using Base::m_storage;
00365 };
00366 
00387 #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix)   \
00388                                     \
00389 typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix;  \
00390                                     \
00391 typedef Matrix<Type, Size, 1>    Vector##SizeSuffix##TypeSuffix;  \
00392                                     \
00393 typedef Matrix<Type, 1, Size>    RowVector##SizeSuffix##TypeSuffix;
00394 
00395 #define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size)         \
00396                                     \
00397 typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix;  \
00398                                     \
00399 typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
00400 
00401 #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
00402 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
00403 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
00404 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
00405 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
00406 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
00407 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
00408 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
00409 
00410 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int,                  i)
00411 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float,                f)
00412 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double,               d)
00413 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>,  cf)
00414 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
00415 
00416 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
00417 #undef EIGEN_MAKE_TYPEDEFS
00418 
00419 #undef EIGEN_MAKE_TYPEDEFS_LARGE
00420 
00421 #define EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \
00422 using Eigen::Matrix##SizeSuffix##TypeSuffix; \
00423 using Eigen::Vector##SizeSuffix##TypeSuffix; \
00424 using Eigen::RowVector##SizeSuffix##TypeSuffix;
00425 
00426 #define EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(TypeSuffix) \
00427 EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \
00428 EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \
00429 EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \
00430 EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) \
00431 
00432 #define EIGEN_USING_MATRIX_TYPEDEFS \
00433 EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(i) \
00434 EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(f) \
00435 EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(d) \
00436 EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(cf) \
00437 EIGEN_USING_MATRIX_TYPEDEFS_FOR_TYPE(cd)
00438 
00439 #endif // EIGEN_MATRIX_H


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