Eigen  3.3.3
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 
00016 namespace internal {
00017 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00018 struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
00019 {
00020 private:
00021   enum { size = internal::size_at_compile_time<_Rows,_Cols>::ret };
00022   typedef typename find_best_packet<_Scalar,size>::type PacketScalar;
00023   enum {
00024       row_major_bit = _Options&RowMajor ? RowMajorBit : 0,
00025       is_dynamic_size_storage = _MaxRows==Dynamic || _MaxCols==Dynamic,
00026       max_size = is_dynamic_size_storage ? Dynamic : _MaxRows*_MaxCols,
00027       default_alignment = compute_default_alignment<_Scalar,max_size>::value,
00028       actual_alignment = ((_Options&DontAlign)==0) ? default_alignment : 0,
00029       required_alignment = unpacket_traits<PacketScalar>::alignment,
00030       packet_access_bit = (packet_traits<_Scalar>::Vectorizable && (EIGEN_UNALIGNED_VECTORIZE || (actual_alignment>=required_alignment))) ? PacketAccessBit : 0
00031     };
00032     
00033 public:
00034   typedef _Scalar Scalar;
00035   typedef Dense StorageKind;
00036   typedef Eigen::Index StorageIndex;
00037   typedef MatrixXpr XprKind;
00038   enum {
00039     RowsAtCompileTime = _Rows,
00040     ColsAtCompileTime = _Cols,
00041     MaxRowsAtCompileTime = _MaxRows,
00042     MaxColsAtCompileTime = _MaxCols,
00043     Flags = compute_matrix_flags<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::ret,
00044     Options = _Options,
00045     InnerStrideAtCompileTime = 1,
00046     OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime,
00047     
00048     // FIXME, the following flag in only used to define NeedsToAlign in PlainObjectBase
00049     EvaluatorFlags = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit,
00050     Alignment = actual_alignment
00051   };
00052 };
00053 }
00054 
00177 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00178 class Matrix
00179   : public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
00180 {
00181   public:
00182 
00186     typedef PlainObjectBase<Matrix> Base;
00187 
00188     enum { Options = _Options };
00189 
00190     EIGEN_DENSE_PUBLIC_INTERFACE(Matrix)
00191 
00192     typedef typename Base::PlainObject PlainObject;
00193 
00194     using Base::base;
00195     using Base::coeffRef;
00196 
00205     EIGEN_DEVICE_FUNC
00206     EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other)
00207     {
00208       return Base::_set(other);
00209     }
00210 
00221     template<typename OtherDerived>
00222     EIGEN_DEVICE_FUNC
00223     EIGEN_STRONG_INLINE Matrix& operator=(const DenseBase<OtherDerived>& other)
00224     {
00225       return Base::_set(other);
00226     }
00227 
00228     /* Here, doxygen failed to copy the brief information when using \copydoc */
00229 
00234     template<typename OtherDerived>
00235     EIGEN_DEVICE_FUNC
00236     EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived> &other)
00237     {
00238       return Base::operator=(other);
00239     }
00240 
00241     template<typename OtherDerived>
00242     EIGEN_DEVICE_FUNC
00243     EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func)
00244     {
00245       return Base::operator=(func);
00246     }
00247 
00258     EIGEN_DEVICE_FUNC
00259     EIGEN_STRONG_INLINE Matrix() : Base()
00260     {
00261       Base::_check_template_params();
00262       EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
00263     }
00264 
00265     // FIXME is it still needed
00266     EIGEN_DEVICE_FUNC
00267     explicit Matrix(internal::constructor_without_unaligned_array_assert)
00268       : Base(internal::constructor_without_unaligned_array_assert())
00269     { Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED }
00270 
00271 #if EIGEN_HAS_RVALUE_REFERENCES
00272     EIGEN_DEVICE_FUNC
00273     Matrix(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
00274       : Base(std::move(other))
00275     {
00276       Base::_check_template_params();
00277       if (RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic)
00278         Base::_set_noalias(other);
00279     }
00280     EIGEN_DEVICE_FUNC
00281     Matrix& operator=(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
00282     {
00283       other.swap(*this);
00284       return *this;
00285     }
00286 #endif
00287 
00288     #ifndef EIGEN_PARSED_BY_DOXYGEN
00289 
00290     // This constructor is for both 1x1 matrices and dynamic vectors
00291     template<typename T>
00292     EIGEN_DEVICE_FUNC
00293     EIGEN_STRONG_INLINE explicit Matrix(const T& x)
00294     {
00295       Base::_check_template_params();
00296       Base::template _init1<T>(x);
00297     }
00298 
00299     template<typename T0, typename T1>
00300     EIGEN_DEVICE_FUNC
00301     EIGEN_STRONG_INLINE Matrix(const T0& x, const T1& y)
00302     {
00303       Base::_check_template_params();
00304       Base::template _init2<T0,T1>(x, y);
00305     }
00306     #else
00307 
00308     EIGEN_DEVICE_FUNC
00309     explicit Matrix(const Scalar *data);
00310 
00323     EIGEN_STRONG_INLINE explicit Matrix(Index dim);
00325     Matrix(const Scalar& x);
00338     EIGEN_DEVICE_FUNC
00339     Matrix(Index rows, Index cols);
00340     
00342     Matrix(const Scalar& x, const Scalar& y);
00343     #endif
00344 
00346     EIGEN_DEVICE_FUNC
00347     EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
00348     {
00349       Base::_check_template_params();
00350       EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3)
00351       m_storage.data()[0] = x;
00352       m_storage.data()[1] = y;
00353       m_storage.data()[2] = z;
00354     }
00356     EIGEN_DEVICE_FUNC
00357     EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
00358     {
00359       Base::_check_template_params();
00360       EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4)
00361       m_storage.data()[0] = x;
00362       m_storage.data()[1] = y;
00363       m_storage.data()[2] = z;
00364       m_storage.data()[3] = w;
00365     }
00366 
00367 
00369     EIGEN_DEVICE_FUNC
00370     EIGEN_STRONG_INLINE Matrix(const Matrix& other) : Base(other)
00371     { }
00372 
00376     template<typename OtherDerived>
00377     EIGEN_DEVICE_FUNC
00378     EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived> &other)
00379       : Base(other.derived())
00380     { }
00381 
00382     EIGEN_DEVICE_FUNC inline Index innerStride() const { return 1; }
00383     EIGEN_DEVICE_FUNC inline Index outerStride() const { return this->innerSize(); }
00384 
00386 
00387     template<typename OtherDerived>
00388     EIGEN_DEVICE_FUNC
00389     explicit Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
00390     template<typename OtherDerived>
00391     EIGEN_DEVICE_FUNC
00392     Matrix& operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
00393 
00394     // allow to extend Matrix outside Eigen
00395     #ifdef EIGEN_MATRIX_PLUGIN
00396     #include EIGEN_MATRIX_PLUGIN
00397     #endif
00398 
00399   protected:
00400     template <typename Derived, typename OtherDerived, bool IsVector>
00401     friend struct internal::conservative_resize_like_impl;
00402 
00403     using Base::m_storage;
00404 };
00405 
00426 #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix)   \
00427                                     \
00428 typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix;  \
00429                                     \
00430 typedef Matrix<Type, Size, 1>    Vector##SizeSuffix##TypeSuffix;  \
00431                                     \
00432 typedef Matrix<Type, 1, Size>    RowVector##SizeSuffix##TypeSuffix;
00433 
00434 #define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size)         \
00435                                     \
00436 typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix;  \
00437                                     \
00438 typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
00439 
00440 #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
00441 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
00442 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
00443 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
00444 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
00445 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
00446 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
00447 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
00448 
00449 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int,                  i)
00450 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float,                f)
00451 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double,               d)
00452 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>,  cf)
00453 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
00454 
00455 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
00456 #undef EIGEN_MAKE_TYPEDEFS
00457 #undef EIGEN_MAKE_FIXED_TYPEDEFS
00458 
00459 } // end namespace Eigen
00460 
00461 #endif // EIGEN_MATRIX_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends