Eigen  3.2.8
Matrix.h
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 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_MATRIX_H
00012 #define EIGEN_MATRIX_H
00013 
00014 namespace Eigen {
00015 
00104 namespace internal {
00105 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00106 struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
00107 {
00108   typedef _Scalar Scalar;
00109   typedef Dense StorageKind;
00110   typedef DenseIndex Index;
00111   typedef MatrixXpr XprKind;
00112   enum {
00113     RowsAtCompileTime = _Rows,
00114     ColsAtCompileTime = _Cols,
00115     MaxRowsAtCompileTime = _MaxRows,
00116     MaxColsAtCompileTime = _MaxCols,
00117     Flags = compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret,
00118     CoeffReadCost = NumTraits<Scalar>::ReadCost,
00119     Options = _Options,
00120     InnerStrideAtCompileTime = 1,
00121     OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime
00122   };
00123 };
00124 }
00125 
00126 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00127 class Matrix
00128   : public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
00129 {
00130   public:
00131 
00135     typedef PlainObjectBase<Matrix> Base;
00136 
00137     enum { Options = _Options };
00138 
00139     EIGEN_DENSE_PUBLIC_INTERFACE(Matrix)
00140 
00141     typedef typename Base::PlainObject PlainObject;
00142 
00143     using Base::base;
00144     using Base::coeffRef;
00145 
00154     EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other)
00155     {
00156       return Base::_set(other);
00157     }
00158 
00169     template<typename OtherDerived>
00170     EIGEN_STRONG_INLINE Matrix& operator=(const MatrixBase<OtherDerived>& other)
00171     {
00172       return Base::_set(other);
00173     }
00174 
00175     /* Here, doxygen failed to copy the brief information when using \copydoc */
00176 
00181     template<typename OtherDerived>
00182     EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived> &other)
00183     {
00184       return Base::operator=(other);
00185     }
00186 
00187     template<typename OtherDerived>
00188     EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func)
00189     {
00190       return Base::operator=(func);
00191     }
00192 
00203     EIGEN_STRONG_INLINE Matrix() : Base()
00204     {
00205       Base::_check_template_params();
00206       EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
00207     }
00208 
00209     // FIXME is it still needed
00210     Matrix(internal::constructor_without_unaligned_array_assert)
00211       : Base(internal::constructor_without_unaligned_array_assert())
00212     { Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED }
00213 
00214 #ifdef EIGEN_HAVE_RVALUE_REFERENCES
00215     Matrix(Matrix&& other)
00216       : Base(std::move(other))
00217     {
00218       Base::_check_template_params();
00219       if (RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic)
00220         Base::_set_noalias(other);
00221     }
00222     Matrix& operator=(Matrix&& other)
00223     {
00224       other.swap(*this);
00225       return *this;
00226     }
00227 #endif
00228 
00235     EIGEN_STRONG_INLINE explicit Matrix(Index dim)
00236       : Base(dim, RowsAtCompileTime == 1 ? 1 : dim, ColsAtCompileTime == 1 ? 1 : dim)
00237     {
00238       Base::_check_template_params();
00239       EIGEN_STATIC_ASSERT_VECTOR_ONLY(Matrix)
00240       eigen_assert(dim >= 0);
00241       eigen_assert(SizeAtCompileTime == Dynamic || SizeAtCompileTime == dim);
00242       EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
00243     }
00244 
00245     #ifndef EIGEN_PARSED_BY_DOXYGEN
00246     template<typename T0, typename T1>
00247     EIGEN_STRONG_INLINE Matrix(const T0& x, const T1& y)
00248     {
00249       Base::_check_template_params();
00250       Base::template _init2<T0,T1>(x, y);
00251     }
00252     #else
00253 
00258     Matrix(Index rows, Index cols);
00260     Matrix(const Scalar& x, const Scalar& y);
00261     #endif
00262 
00264     EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
00265     {
00266       Base::_check_template_params();
00267       EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3)
00268       m_storage.data()[0] = x;
00269       m_storage.data()[1] = y;
00270       m_storage.data()[2] = z;
00271     }
00273     EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
00274     {
00275       Base::_check_template_params();
00276       EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4)
00277       m_storage.data()[0] = x;
00278       m_storage.data()[1] = y;
00279       m_storage.data()[2] = z;
00280       m_storage.data()[3] = w;
00281     }
00282 
00283     explicit Matrix(const Scalar *data);
00284 
00286     template<typename OtherDerived>
00287     EIGEN_STRONG_INLINE Matrix(const MatrixBase<OtherDerived>& other)
00288              : Base(other.rows() * other.cols(), other.rows(), other.cols())
00289     {
00290       // This test resides here, to bring the error messages closer to the user. Normally, these checks
00291       // are performed deeply within the library, thus causing long and scary error traces.
00292       EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
00293         YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
00294 
00295       Base::_check_template_params();
00296       Base::_set_noalias(other);
00297     }
00299     EIGEN_STRONG_INLINE Matrix(const Matrix& other)
00300             : Base(other.rows() * other.cols(), other.rows(), other.cols())
00301     {
00302       Base::_check_template_params();
00303       Base::_set_noalias(other);
00304     }
00306     template<typename OtherDerived>
00307     EIGEN_STRONG_INLINE Matrix(const ReturnByValue<OtherDerived>& other)
00308     {
00309       Base::_check_template_params();
00310       Base::resize(other.rows(), other.cols());
00311       other.evalTo(*this);
00312     }
00313 
00317     template<typename OtherDerived>
00318     EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived> &other)
00319       : Base(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols())
00320     {
00321       Base::_check_template_params();
00322       Base::_resize_to_match(other);
00323       // FIXME/CHECK: isn't *this = other.derived() more efficient. it allows to
00324       //              go for pure _set() implementations, right?
00325       *this = other;
00326     }
00327 
00332     template<typename OtherDerived>
00333     void swap(MatrixBase<OtherDerived> const & other)
00334     { this->_swap(other.derived()); }
00335 
00336     inline Index innerStride() const { return 1; }
00337     inline Index outerStride() const { return this->innerSize(); }
00338 
00340 
00341     template<typename OtherDerived>
00342     explicit Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
00343     template<typename OtherDerived>
00344     Matrix& operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
00345 
00346     #ifdef EIGEN2_SUPPORT
00347     template<typename OtherDerived>
00348     explicit Matrix(const eigen2_RotationBase<OtherDerived,ColsAtCompileTime>& r);
00349     template<typename OtherDerived>
00350     Matrix& operator=(const eigen2_RotationBase<OtherDerived,ColsAtCompileTime>& r);
00351     #endif
00352 
00353     // allow to extend Matrix outside Eigen
00354     #ifdef EIGEN_MATRIX_PLUGIN
00355     #include EIGEN_MATRIX_PLUGIN
00356     #endif
00357 
00358   protected:
00359     template <typename Derived, typename OtherDerived, bool IsVector>
00360     friend struct internal::conservative_resize_like_impl;
00361 
00362     using Base::m_storage;
00363 };
00364 
00385 #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix)   \
00386                                     \
00387 typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix;  \
00388                                     \
00389 typedef Matrix<Type, Size, 1>    Vector##SizeSuffix##TypeSuffix;  \
00390                                     \
00391 typedef Matrix<Type, 1, Size>    RowVector##SizeSuffix##TypeSuffix;
00392 
00393 #define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size)         \
00394                                     \
00395 typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix;  \
00396                                     \
00397 typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
00398 
00399 #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
00400 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
00401 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
00402 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
00403 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
00404 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
00405 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
00406 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
00407 
00408 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int,                  i)
00409 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float,                f)
00410 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double,               d)
00411 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>,  cf)
00412 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
00413 
00414 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
00415 #undef EIGEN_MAKE_TYPEDEFS
00416 #undef EIGEN_MAKE_FIXED_TYPEDEFS
00417 
00418 } // end namespace Eigen
00419 
00420 #endif // EIGEN_MATRIX_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends