diff options
author | 2008-06-13 07:53:45 +0000 | |
---|---|---|
committer | 2008-06-13 07:53:45 +0000 | |
commit | c90c77051f0dc26a18e4e4fe2d7b828fe559db67 (patch) | |
tree | 16e2442d14f3faa95cda419817ec5f30a4404bf8 /Eigen/src | |
parent | e3fac69f196a0a1c6ede9d510f2a4409399ad2c1 (diff) |
* make the _Flags template parameter of Matrix default to the corrected
flags. This ensures that unless explicitly messed up otherwise,
a Matrix type is equal to its own Eval type. This seriously reduces
the number of types instantiated. Measured +13% compile speed, -7%
binary size.
* Improve doc of Matrix template parameters.
Diffstat (limited to 'Eigen/src')
-rw-r--r-- | Eigen/src/Core/Map.h | 48 | ||||
-rw-r--r-- | Eigen/src/Core/Matrix.h | 20 | ||||
-rw-r--r-- | Eigen/src/Core/Product.h | 9 | ||||
-rw-r--r-- | Eigen/src/Core/util/ForwardDeclarations.h | 12 | ||||
-rw-r--r-- | Eigen/src/Core/util/Meta.h | 9 |
5 files changed, 62 insertions, 36 deletions
diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h index 1eb879193..f4c660af9 100644 --- a/Eigen/src/Core/Map.h +++ b/Eigen/src/Core/Map.h @@ -97,17 +97,17 @@ template<typename MatrixType> class Map }; /** This is the const version of map(Scalar*,int,int). */ -template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> -inline const Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(const Scalar* data, int rows, int cols) +template<typename _Scalar, int _Rows, int _Cols, int _MaxRows, int _MaxCols, unsigned int _Flags> +inline const Map<Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> > +Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags>::map(const Scalar* data, int rows, int cols) { return Map<Matrix>(data, rows, cols); } /** This is the const version of map(Scalar*,int). */ -template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> -inline const Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(const Scalar* data, int size) +template<typename _Scalar, int _Rows, int _Cols, int _MaxRows, int _MaxCols, unsigned int _Flags> +inline const Map<Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> > +Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags>::map(const Scalar* data, int size) { ei_assert(_Cols == 1 || _Rows ==1); if(_Cols == 1) @@ -117,9 +117,9 @@ Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(const Scalar* dat } /** This is the const version of map(Scalar*). */ -template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> -inline const Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(const Scalar* data) +template<typename _Scalar, int _Rows, int _Cols, int _MaxRows, int _MaxCols, unsigned int _Flags> +inline const Map<Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> > +Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags>::map(const Scalar* data) { return Map<Matrix>(data, _Rows, _Cols); } @@ -135,9 +135,9 @@ Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(const Scalar* dat * * \sa map(const Scalar*, int, int), map(Scalar*, int), map(Scalar*), class Map */ -template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> -inline Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(Scalar* data, int rows, int cols) +template<typename _Scalar, int _Rows, int _Cols, int _MaxRows, int _MaxCols, unsigned int _Flags> +inline Map<Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> > +Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags>::map(Scalar* data, int rows, int cols) { return Map<Matrix>(data, rows, cols); } @@ -154,9 +154,9 @@ Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(Scalar* data, int * * \sa map(const Scalar*, int), map(Scalar*, int, int), map(Scalar*), class Map */ -template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> -inline Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(Scalar* data, int size) +template<typename _Scalar, int _Rows, int _Cols, int _MaxRows, int _MaxCols, unsigned int _Flags> +inline Map<Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> > +Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags>::map(Scalar* data, int size) { ei_assert(_Cols == 1 || _Rows ==1); if(_Cols == 1) @@ -174,9 +174,9 @@ Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(Scalar* data, int * * \sa map(const Scalar*), map(Scalar*, int), map(Scalar*, int, int), class Map */ -template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> -inline Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(Scalar* data) +template<typename _Scalar, int _Rows, int _Cols, int _MaxRows, int _MaxCols, unsigned int _Flags> +inline Map<Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> > +Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags>::map(Scalar* data) { return Map<Matrix>(data, _Rows, _Cols); } @@ -189,8 +189,8 @@ Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(Scalar* data) * * \sa Matrix(const Scalar *), Matrix::map(const Scalar *, int, int) */ -template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> -inline Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> +template<typename _Scalar, int _Rows, int _Cols, int _MaxRows, int _MaxCols, unsigned int _Flags> +inline Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> ::Matrix(const Scalar *data, int rows, int cols) : m_storage(rows*cols, rows, cols) { @@ -207,8 +207,8 @@ inline Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> * * \sa Matrix(const Scalar *), Matrix::map(const Scalar *, int) */ -template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> -inline Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> +template<typename _Scalar, int _Rows, int _Cols, int _MaxRows, int _MaxCols, unsigned int _Flags> +inline Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> ::Matrix(const Scalar *data, int size) : m_storage(size, RowsAtCompileTime == 1 ? 1 : size, ColsAtCompileTime == 1 ? 1 : size) { @@ -225,8 +225,8 @@ inline Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> * \sa Matrix(const Scalar *, int), Matrix(const Scalar *, int, int), * Matrix::map(const Scalar *) */ -template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> -inline Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> +template<typename _Scalar, int _Rows, int _Cols, int _MaxRows, int _MaxCols, unsigned int _Flags> +inline Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> ::Matrix(const Scalar *data) { *this = map(data); diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 6c7a42f94..75e2c67b0 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -35,7 +35,15 @@ * specify that the number of rows is dynamic, i.e. is not fixed at compile-time. * \param _Cols the number of columns at compile-time. Use the special value \a Dynamic to * specify that the number of columns is dynamic, i.e. is not fixed at compile-time. - * \param _SuggestedFlags allows to control certain features such as storage order. See MatrixBase::Flags. + * \param _MaxRows the maximum number of rows at compile-time. By default this is equal to \a _Rows. + * The most common exception is when you don't know the exact number of rows, but know that + * it is smaller than some given value. Then you can set \a _MaxRows to that value, and set + * _Rows to \a Dynamic. + * \param _MaxCols the maximum number of cols at compile-time. By default this is equal to \a _Cols. + * The most common exception is when you don't know the exact number of cols, but know that + * it is smaller than some given value. Then you can set \a _MaxCols to that value, and set + * _Cols to \a Dynamic. + * \param _Flags allows to control certain features such as storage order. See the \ref flags "list of flags". * * This single class template covers all kinds of matrix and vectors that Eigen can handle. * All matrix and vector types are just typedefs to specializations of this class template. @@ -70,8 +78,8 @@ * * Note that most of the API is in the base class MatrixBase. */ -template<typename _Scalar, int _Rows, int _Cols, unsigned int _SuggestedFlags, int _MaxRows, int _MaxCols> -struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _SuggestedFlags, _MaxRows, _MaxCols> > +template<typename _Scalar, int _Rows, int _Cols, int _MaxRows, int _MaxCols, unsigned int _Flags> +struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> > { typedef _Scalar Scalar; enum { @@ -79,13 +87,13 @@ struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _SuggestedFlags, _MaxRows, _MaxCo ColsAtCompileTime = _Cols, MaxRowsAtCompileTime = _MaxRows, MaxColsAtCompileTime = _MaxCols, - Flags = ei_corrected_matrix_flags<_Scalar, ei_size_at_compile_time<_MaxRows,_MaxCols>::ret, _SuggestedFlags>::ret, + Flags = _Flags, CoeffReadCost = NumTraits<Scalar>::ReadCost }; }; -template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> -class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > +template<typename _Scalar, int _Rows, int _Cols, int _MaxRows, int _MaxCols, unsigned int _Flags> +class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _MaxRows, _MaxCols, _Flags> > { public: diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 7af1bb3ed..39bda7e6e 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -163,9 +163,14 @@ template<typename T> class ei_product_eval_to_column_major typedef Matrix<_Scalar, ei_traits<T>::RowsAtCompileTime, ei_traits<T>::ColsAtCompileTime, - ei_corrected_matrix_flags<_Scalar, ei_size_at_compile_time<_MaxRows,_MaxCols>::ret, _Flags>::ret & ~RowMajorBit, ei_traits<T>::MaxRowsAtCompileTime, - ei_traits<T>::MaxColsAtCompileTime> type; + ei_traits<T>::MaxColsAtCompileTime, + ei_corrected_matrix_flags< + _Scalar, + ei_size_at_compile_time<_MaxRows,_MaxCols>::ret, + _Flags + >::ret & ~RowMajorBit + > type; }; // as ei_nested, but evaluate to a column-major matrix if an evaluation is required diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index f9370ada9..9d09a2aa6 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -28,10 +28,18 @@ template<typename T> struct ei_traits; template<typename Lhs, typename Rhs> struct ei_product_eval_mode; template<typename T> struct NumTraits; +template<typename Scalar, int Size, unsigned int SuggestedFlags> class ei_corrected_matrix_flags; + +template<int _Rows, int _Cols> struct ei_size_at_compile_time; template<typename _Scalar, int _Rows, int _Cols, - unsigned int _SuggestedFlags = EIGEN_DEFAULT_MATRIX_FLAGS, - int _MaxRows = _Rows, int _MaxCols = _Cols> + int _MaxRows = _Rows, int _MaxCols = _Cols, + unsigned int _Flags = ei_corrected_matrix_flags< + _Scalar, + ei_size_at_compile_time<_MaxRows,_MaxCols>::ret, + EIGEN_DEFAULT_MATRIX_FLAGS + >::ret +> class Matrix; template<typename ExpressionType, unsigned int Added, unsigned int Removed> class Flagged; diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index 5611ad3b0..5df6d89d0 100644 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -180,9 +180,14 @@ template<typename T> class ei_eval typedef Matrix<_Scalar, ei_traits<T>::RowsAtCompileTime, ei_traits<T>::ColsAtCompileTime, - ei_corrected_matrix_flags<_Scalar, ei_size_at_compile_time<_MaxRows,_MaxCols>::ret, _Flags>::ret, ei_traits<T>::MaxRowsAtCompileTime, - ei_traits<T>::MaxColsAtCompileTime> type; + ei_traits<T>::MaxColsAtCompileTime, + ei_corrected_matrix_flags< + _Scalar, + ei_size_at_compile_time<_MaxRows,_MaxCols>::ret, + _Flags + >::ret + > type; }; template<typename T> struct ei_unref { typedef T type; }; |