diff options
author | 2008-03-30 18:43:22 +0000 | |
---|---|---|
committer | 2008-03-30 18:43:22 +0000 | |
commit | f279162ec4f01ecec8fa37eae02757720e16e65b (patch) | |
tree | 34938443dd2eb8a59b98f94ce1544d4c46587fcd | |
parent | 758b26551a01894f76c8376f11ac9fd3c13d0844 (diff) |
* introducte recursive Flags system for the expressions
-- currently 3 flags: RowMajor, Lazy and Large
-- only RowMajor actually used for now
* many minor improvements
-rw-r--r-- | Eigen/src/Core/AssociativeFunctors.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/Block.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/Coeffs.h | 16 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseBinaryOp.h | 5 | ||||
-rw-r--r-- | Eigen/src/Core/CwiseUnaryOp.h | 5 | ||||
-rw-r--r-- | Eigen/src/Core/DiagonalCoeffs.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/DiagonalMatrix.h | 5 | ||||
-rw-r--r-- | Eigen/src/Core/Eval.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/EvalOMP.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/ForwardDeclarations.h | 8 | ||||
-rw-r--r-- | Eigen/src/Core/IO.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/Identity.h | 5 | ||||
-rw-r--r-- | Eigen/src/Core/Map.h | 63 | ||||
-rw-r--r-- | Eigen/src/Core/MathFunctions.h | 1 | ||||
-rw-r--r-- | Eigen/src/Core/Matrix.h | 34 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixBase.h | 29 | ||||
-rw-r--r-- | Eigen/src/Core/Minor.h | 5 | ||||
-rw-r--r-- | Eigen/src/Core/Ones.h | 5 | ||||
-rw-r--r-- | Eigen/src/Core/OperatorEquals.h | 10 | ||||
-rw-r--r-- | Eigen/src/Core/Product.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/Random.h | 5 | ||||
-rw-r--r-- | Eigen/src/Core/Redux.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/Transpose.h | 5 | ||||
-rw-r--r-- | Eigen/src/Core/Util.h | 12 | ||||
-rw-r--r-- | Eigen/src/Core/Zero.h | 3 | ||||
-rw-r--r-- | test/basicstuff.cpp | 4 |
26 files changed, 153 insertions, 115 deletions
diff --git a/Eigen/src/Core/AssociativeFunctors.h b/Eigen/src/Core/AssociativeFunctors.h index 106549f75..fd42de9ec 100644 --- a/Eigen/src/Core/AssociativeFunctors.h +++ b/Eigen/src/Core/AssociativeFunctors.h @@ -49,7 +49,7 @@ struct ei_scalar_product_op EIGEN_EMPTY_STRUCT { * \sa class CwiseBinaryOp, MatrixBase::cwiseMin, class PartialRedux, MatrixBase::minCoeff() */ struct ei_scalar_min_op EIGEN_EMPTY_STRUCT { - template<typename Scalar> Scalar operator() (const Scalar& a, const Scalar& b) const { return ei_min(a, b); } + template<typename Scalar> Scalar operator() (const Scalar& a, const Scalar& b) const { return std::min(a, b); } }; /** \internal @@ -58,7 +58,7 @@ struct ei_scalar_min_op EIGEN_EMPTY_STRUCT { * \sa class CwiseBinaryOp, MatrixBase::cwiseMax, class PartialRedux, MatrixBase::maxCoeff() */ struct ei_scalar_max_op EIGEN_EMPTY_STRUCT { - template<typename Scalar> Scalar operator() (const Scalar& a, const Scalar& b) const { return ei_max(a, b); } + template<typename Scalar> Scalar operator() (const Scalar& a, const Scalar& b) const { return std::max(a, b); } }; #endif // EIGEN_ASSOCIATIVE_FUNCTORS_H diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 6d39efe7e..751af9647 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -66,7 +66,10 @@ struct ei_traits<Block<MatrixType, BlockRows, BlockCols> > MaxRowsAtCompileTime = RowsAtCompileTime == 1 ? 1 : (BlockRows==Dynamic ? MatrixType::MaxRowsAtCompileTime : BlockRows), MaxColsAtCompileTime = ColsAtCompileTime == 1 ? 1 - : (BlockCols==Dynamic ? MatrixType::MaxColsAtCompileTime : BlockCols) + : (BlockCols==Dynamic ? MatrixType::MaxColsAtCompileTime : BlockCols), + Flags = RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic + ? (unsigned int)MatrixType::Flags + : (unsigned int)MatrixType::Flags &~ Large }; }; @@ -132,7 +135,7 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block .coeffRef(row + m_startRow.value(), col + m_startCol.value()); } - Scalar _coeff(int row, int col) const + const Scalar _coeff(int row, int col) const { return m_matrix.coeff(row + m_startRow.value(), col + m_startCol.value()); } diff --git a/Eigen/src/Core/Coeffs.h b/Eigen/src/Core/Coeffs.h index d0b211314..b170ffda7 100644 --- a/Eigen/src/Core/Coeffs.h +++ b/Eigen/src/Core/Coeffs.h @@ -40,7 +40,7 @@ * \sa operator()(int,int) const, coeffRef(int,int), coeff(int) const */ template<typename Derived> -typename ei_traits<Derived>::Scalar MatrixBase<Derived> +const typename ei_traits<Derived>::Scalar MatrixBase<Derived> ::coeff(int row, int col) const { ei_internal_assert(row >= 0 && row < rows() @@ -53,7 +53,7 @@ typename ei_traits<Derived>::Scalar MatrixBase<Derived> * \sa operator()(int,int), operator[](int) const */ template<typename Derived> -typename ei_traits<Derived>::Scalar MatrixBase<Derived> +const typename ei_traits<Derived>::Scalar MatrixBase<Derived> ::operator()(int row, int col) const { ei_assert(row >= 0 && row < rows() @@ -112,7 +112,7 @@ typename ei_traits<Derived>::Scalar& MatrixBase<Derived> * \sa operator[](int) const, coeffRef(int), coeff(int,int) const */ template<typename Derived> -typename ei_traits<Derived>::Scalar MatrixBase<Derived> +const typename ei_traits<Derived>::Scalar MatrixBase<Derived> ::coeff(int index) const { ei_internal_assert(IsVectorAtCompileTime); @@ -136,7 +136,7 @@ typename ei_traits<Derived>::Scalar MatrixBase<Derived> * z() const, w() const */ template<typename Derived> -typename ei_traits<Derived>::Scalar MatrixBase<Derived> +const typename ei_traits<Derived>::Scalar MatrixBase<Derived> ::operator[](int index) const { ei_assert(IsVectorAtCompileTime); @@ -208,22 +208,22 @@ typename ei_traits<Derived>::Scalar& MatrixBase<Derived> /** equivalent to operator[](0). \only_for_vectors */ template<typename Derived> -typename ei_traits<Derived>::Scalar MatrixBase<Derived> +const typename ei_traits<Derived>::Scalar MatrixBase<Derived> ::x() const { return (*this)[0]; } /** equivalent to operator[](1). \only_for_vectors */ template<typename Derived> -typename ei_traits<Derived>::Scalar MatrixBase<Derived> +const typename ei_traits<Derived>::Scalar MatrixBase<Derived> ::y() const { return (*this)[1]; } /** equivalent to operator[](2). \only_for_vectors */ template<typename Derived> -typename ei_traits<Derived>::Scalar MatrixBase<Derived> +const typename ei_traits<Derived>::Scalar MatrixBase<Derived> ::z() const { return (*this)[2]; } /** equivalent to operator[](3). \only_for_vectors */ template<typename Derived> -typename ei_traits<Derived>::Scalar MatrixBase<Derived> +const typename ei_traits<Derived>::Scalar MatrixBase<Derived> ::w() const { return (*this)[3]; } /** equivalent to operator[](0). \only_for_vectors */ diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index ff7e8661c..9a83f4257 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -59,7 +59,8 @@ struct ei_traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > RowsAtCompileTime = Lhs::RowsAtCompileTime, ColsAtCompileTime = Lhs::ColsAtCompileTime, MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime, - MaxColsAtCompileTime = Lhs::MaxColsAtCompileTime + MaxColsAtCompileTime = Lhs::MaxColsAtCompileTime, + Flags = Lhs::Flags | Rhs::Flags }; }; @@ -82,7 +83,7 @@ class CwiseBinaryOp : ei_no_assignment_operator, int _rows() const { return m_lhs.rows(); } int _cols() const { return m_lhs.cols(); } - Scalar _coeff(int row, int col) const + const Scalar _coeff(int row, int col) const { return m_functor(m_lhs.coeff(row, col), m_rhs.coeff(row, col)); } diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h index 08e0cbdce..d3cc6ad30 100644 --- a/Eigen/src/Core/CwiseUnaryOp.h +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -49,7 +49,8 @@ struct ei_traits<CwiseUnaryOp<UnaryOp, MatrixType> > RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, + Flags = MatrixType::Flags }; }; @@ -69,7 +70,7 @@ class CwiseUnaryOp : ei_no_assignment_operator, int _rows() const { return m_matrix.rows(); } int _cols() const { return m_matrix.cols(); } - Scalar _coeff(int row, int col) const + const Scalar _coeff(int row, int col) const { return m_functor(m_matrix.coeff(row, col)); } diff --git a/Eigen/src/Core/DiagonalCoeffs.h b/Eigen/src/Core/DiagonalCoeffs.h index 69fab3066..10cb7b8e4 100644 --- a/Eigen/src/Core/DiagonalCoeffs.h +++ b/Eigen/src/Core/DiagonalCoeffs.h @@ -51,7 +51,10 @@ struct ei_traits<DiagonalCoeffs<MatrixType> > MaxRowsAtCompileTime = MatrixType::MaxSizeAtCompileTime == Dynamic ? Dynamic : EIGEN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime), - MaxColsAtCompileTime = 1 + MaxColsAtCompileTime = 1, + Flags = RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic + ? (unsigned int)MatrixType::Flags + : (unsigned int)MatrixType::Flags &~ Large }; }; @@ -76,7 +79,7 @@ template<typename MatrixType> class DiagonalCoeffs return m_matrix.const_cast_derived().coeffRef(row, row); } - Scalar _coeff(int row, int) const + const Scalar _coeff(int row, int) const { return m_matrix.coeff(row, row); } diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h index 36d2c656b..f46e8ad0d 100644 --- a/Eigen/src/Core/DiagonalMatrix.h +++ b/Eigen/src/Core/DiagonalMatrix.h @@ -46,7 +46,8 @@ struct ei_traits<DiagonalMatrix<CoeffsVectorType> > RowsAtCompileTime = CoeffsVectorType::SizeAtCompileTime, ColsAtCompileTime = CoeffsVectorType::SizeAtCompileTime, MaxRowsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime, - MaxColsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime + MaxColsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime, + Flags = CoeffsVectorType::Flags }; }; @@ -69,7 +70,7 @@ class DiagonalMatrix : ei_no_assignment_operator, int _rows() const { return m_coeffs.size(); } int _cols() const { return m_coeffs.size(); } - Scalar _coeff(int row, int col) const + const Scalar _coeff(int row, int col) const { return row == col ? m_coeffs.coeff(row) : static_cast<Scalar>(0); } diff --git a/Eigen/src/Core/Eval.h b/Eigen/src/Core/Eval.h index c841a2887..81de3026c 100644 --- a/Eigen/src/Core/Eval.h +++ b/Eigen/src/Core/Eval.h @@ -52,7 +52,8 @@ struct ei_traits<Eval<ExpressionType> > RowsAtCompileTime = ExpressionType::RowsAtCompileTime, ColsAtCompileTime = ExpressionType::ColsAtCompileTime, MaxRowsAtCompileTime = ExpressionType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = ExpressionType::MaxColsAtCompileTime + MaxColsAtCompileTime = ExpressionType::MaxColsAtCompileTime, + Flags = ExpressionType::Flags & ~Lazy }; }; @@ -60,7 +61,7 @@ template<typename ExpressionType> class Eval : ei_no_assignment_operator, public Matrix< typename ExpressionType::Scalar, ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime, - EIGEN_DEFAULT_MATRIX_STORAGE_ORDER, + ExpressionType::Flags, ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime> { @@ -77,7 +78,7 @@ template<typename ExpressionType> class Eval : ei_no_assignment_operator, typedef Matrix<typename ExpressionType::Scalar, ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime, - EIGEN_DEFAULT_MATRIX_STORAGE_ORDER, + ExpressionType::Flags, ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime> MatrixType; diff --git a/Eigen/src/Core/EvalOMP.h b/Eigen/src/Core/EvalOMP.h index 6c1f9a89f..d23f64007 100644 --- a/Eigen/src/Core/EvalOMP.h +++ b/Eigen/src/Core/EvalOMP.h @@ -47,7 +47,8 @@ struct ei_traits<EvalOMP<ExpressionType> > RowsAtCompileTime = ExpressionType::RowsAtCompileTime, ColsAtCompileTime = ExpressionType::ColsAtCompileTime, MaxRowsAtCompileTime = ExpressionType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = ExpressionType::MaxColsAtCompileTime + MaxColsAtCompileTime = ExpressionType::MaxColsAtCompileTime, + Flags = ExpressionType::Flags & ~Lazy }; }; @@ -55,7 +56,7 @@ template<typename ExpressionType> class EvalOMP : ei_no_assignment_operator, public Matrix< typename ExpressionType::Scalar, ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime, - EIGEN_DEFAULT_MATRIX_STORAGE_ORDER, + ExpressionType::Flags, ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime> { @@ -68,7 +69,7 @@ template<typename ExpressionType> class EvalOMP : ei_no_assignment_operator, typedef Matrix<typename ExpressionType::Scalar, ExpressionType::RowsAtCompileTime, ExpressionType::ColsAtCompileTime, - EIGEN_DEFAULT_MATRIX_STORAGE_ORDER, + ExpressionType::Flags, ExpressionType::MaxRowsAtCompileTime, ExpressionType::MaxColsAtCompileTime> MatrixType; diff --git a/Eigen/src/Core/ForwardDeclarations.h b/Eigen/src/Core/ForwardDeclarations.h index 332198b6e..9d5ec90ea 100644 --- a/Eigen/src/Core/ForwardDeclarations.h +++ b/Eigen/src/Core/ForwardDeclarations.h @@ -28,7 +28,7 @@ template<typename T> struct ei_traits; template<typename Lhs, typename Rhs> struct ei_product_eval_mode; -template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> class Matrix; +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> class Matrix; template<typename MatrixType> class MatrixRef; template<typename MatrixType> class Minor; template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic> class Block; @@ -73,10 +73,10 @@ template<typename T> struct ei_xpr_copy typedef T Type; }; -template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> -struct ei_xpr_copy<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +struct ei_xpr_copy<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > { - typedef const Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> & Type; + typedef const Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> & Type; }; #endif // EIGEN_FORWARDDECLARATIONS_H diff --git a/Eigen/src/Core/IO.h b/Eigen/src/Core/IO.h index db384b024..f7094a4a1 100644 --- a/Eigen/src/Core/IO.h +++ b/Eigen/src/Core/IO.h @@ -40,7 +40,7 @@ std::ostream & operator << for (int j = 1; j < m.cols(); j++ ) s << " " << m( i, j ); if( i < m.rows() - 1) - s << std::endl; + s << "\n"; } return s; } diff --git a/Eigen/src/Core/Identity.h b/Eigen/src/Core/Identity.h index 0b39a4274..532167b9c 100644 --- a/Eigen/src/Core/Identity.h +++ b/Eigen/src/Core/Identity.h @@ -39,7 +39,8 @@ struct ei_traits<Identity<MatrixType> > RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, + Flags = MatrixType::Flags }; }; @@ -63,7 +64,7 @@ template<typename MatrixType> class Identity : ei_no_assignment_operator, int _rows() const { return m_rows.value(); } int _cols() const { return m_cols.value(); } - Scalar _coeff(int row, int col) const + const Scalar _coeff(int row, int col) const { return row == col ? static_cast<Scalar>(1) : static_cast<Scalar>(0); } diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h index 5d08ef542..e1abfad3f 100644 --- a/Eigen/src/Core/Map.h +++ b/Eigen/src/Core/Map.h @@ -46,7 +46,8 @@ struct ei_traits<Map<MatrixType> > RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, + Flags = MatrixType::Flags }; }; @@ -64,18 +65,18 @@ template<typename MatrixType> class Map const Scalar& _coeff(int row, int col) const { - if(MatrixType::StorageOrder == ColumnMajor) - return m_data[row + col * m_rows]; - else // RowMajor + if(Flags & RowMajor) return m_data[col + row * m_cols]; + else // column-major + return m_data[row + col * m_rows]; } Scalar& _coeffRef(int row, int col) { - if(MatrixType::StorageOrder == ColumnMajor) - return const_cast<Scalar*>(m_data)[row + col * m_rows]; - else // RowMajor + if(Flags & RowMajor) return const_cast<Scalar*>(m_data)[col + row * m_cols]; + else // column-major + return const_cast<Scalar*>(m_data)[row + col * m_rows]; } public: @@ -95,17 +96,17 @@ template<typename MatrixType> class Map }; /** This is the const version of map(Scalar*,int,int). */ -template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> -const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(const Scalar* data, int rows, int cols) +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +const Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > +Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::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, int _StorageOrder, int _MaxRows, int _MaxCols> -const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(const Scalar* data, int size) +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +const Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > +Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(const Scalar* data, int size) { ei_assert(_Cols == 1 || _Rows ==1); if(_Cols == 1) @@ -115,9 +116,9 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(const Scal } /** This is the const version of map(Scalar*). */ -template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> -const Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(const Scalar* data) +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +const Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > +Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(const Scalar* data) { return Map<Matrix>(data, _Rows, _Cols); } @@ -133,9 +134,9 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(const Scal * * \sa map(const Scalar*, int, int), map(Scalar*, int), map(Scalar*), class Map */ -template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> -Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(Scalar* data, int rows, int cols) +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > +Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(Scalar* data, int rows, int cols) { return Map<Matrix>(data, rows, cols); } @@ -152,9 +153,9 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(Scalar* da * * \sa map(const Scalar*, int), map(Scalar*, int, int), map(Scalar*), class Map */ -template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> -Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(Scalar* data, int size) +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > +Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(Scalar* data, int size) { ei_assert(_Cols == 1 || _Rows ==1); if(_Cols == 1) @@ -172,9 +173,9 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(Scalar* da * * \sa map(const Scalar*), map(Scalar*, int), map(Scalar*, int, int), class Map */ -template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> -Map<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > -Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(Scalar* data) +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +Map<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > +Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols>::map(Scalar* data) { return Map<Matrix>(data, _Rows, _Cols); } @@ -187,8 +188,8 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>::map(Scalar* da * * \sa Matrix(const Scalar *), Matrix::map(const Scalar *, int, int) */ -template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> -Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> ::Matrix(const Scalar *data, int rows, int cols) : m_storage(rows*cols, rows, cols) { @@ -205,8 +206,8 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> * * \sa Matrix(const Scalar *), Matrix::map(const Scalar *, int) */ -template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> -Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> ::Matrix(const Scalar *data, int size) : m_storage(size, RowsAtCompileTime == 1 ? 1 : size, ColsAtCompileTime == 1 ? 1 : size) { @@ -223,8 +224,8 @@ Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> * \sa Matrix(const Scalar *, int), Matrix(const Scalar *, int, int), * Matrix::map(const Scalar *) */ -template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> -Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> ::Matrix(const Scalar *data) { *this = map(data); diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index df30c5ad4..f2d665872 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -40,6 +40,7 @@ inline int ei_exp(int) { ei_assert(false); return 0; } inline int ei_log(int) { ei_assert(false); return 0; } inline int ei_sin(int) { ei_assert(false); return 0; } inline int ei_cos(int) { ei_assert(false); return 0; } +// FIXME naive GCC version test, e.g. 5.0 would not pass #if (defined __ICC) || (defined __GNUC__ && (__GNUC__<4 || __GNUC_MINOR__<3)) inline int ei_pow(int x, int y) { return int(std::pow(double(x), y)); } #else diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 60365f625..f0192e6be 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -31,12 +31,11 @@ * \brief The matrix class, also used for vectors and row-vectors * * \param _Scalar the scalar type, i.e. the type of the coefficients - * \param _Rows the number of rows at compile-time. Use the special value \a Dynamic to 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 _StorageOrder can be either \a RowMajor or \a ColumnMajor. - * This template parameter has a default value (EIGEN_DEFAULT_MATRIX_STORAGE_ORDER) - * which, if not predefined, is defined to \a ColumnMajor. You can override this behavior by - * predefining it before including Eigen headers. + * \param _Rows the number of rows at compile-time. Use the special value \a Dynamic to + * 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 _Flags allows to control certain features such as storage order. See MatrixBase::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. @@ -71,8 +70,8 @@ * * Note that most of the API is in the base class MatrixBase. */ -template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> -struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > +template<typename _Scalar, int _Rows, int _Cols, unsigned int _Flags, int _MaxRows, int _MaxCols> +struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _Flags, _MaxRows, _MaxCols> > { typedef _Scalar Scalar; enum { @@ -80,21 +79,20 @@ struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols ColsAtCompileTime = _Cols, MaxRowsAtCompileTime = _MaxRows, MaxColsAtCompileTime = _MaxCols, + Flags = _Flags }; }; template<typename _Scalar, int _Rows, int _Cols, - int _StorageOrder = EIGEN_DEFAULT_MATRIX_STORAGE_ORDER, + unsigned int _Flags = EIGEN_DEFAULT_MATRIX_STORAGE_ORDER, int _MaxRows = _Rows, int _MaxCols = _Cols> class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, - _StorageOrder, _MaxRows, _MaxCols> > + _Flags, _MaxRows, _MaxCols> > { public: EIGEN_GENERIC_PUBLIC_INTERFACE(Matrix) - enum { StorageOrder = _StorageOrder }; - friend class Map<Matrix>; private: @@ -106,18 +104,18 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, const Scalar& _coeff(int row, int col) const { - if(StorageOrder == ColumnMajor) - return m_storage.data()[row + col * m_storage.rows()]; - else // RowMajor + if(Flags & RowMajor) return m_storage.data()[col + row * m_storage.cols()]; + else // column-major + return m_storage.data()[row + col * m_storage.rows()]; } Scalar& _coeffRef(int row, int col) { - if(StorageOrder == ColumnMajor) - return m_storage.data()[row + col * m_storage.rows()]; - else // RowMajor + if(Flags & RowMajor) return m_storage.data()[col + row * m_storage.cols()]; + else // column-major + return m_storage.data()[row + col * m_storage.rows()]; } public: diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index fa3a09dd6..f97f72419 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -120,11 +120,22 @@ template<typename Derived> class MatrixBase */ IsVectorAtCompileTime - = ei_traits<Derived>::RowsAtCompileTime == 1 || ei_traits<Derived>::ColsAtCompileTime == 1 + = ei_traits<Derived>::RowsAtCompileTime == 1 || ei_traits<Derived>::ColsAtCompileTime == 1, /**< This is set to true if either the number of rows or the number of * columns is known at compile-time to be equal to 1. Indeed, in that case, * we are dealing with a column-vector (if there is only one column) or with * a row-vector (if there is only one row). */ + + Flags = ei_traits<Derived>::Flags + /**< This stores expression metadata which typically is inherited by new expressions + * constructed from this one. The available flags are: + * \li \c RowMajor: if this bit is set, the preferred storage order for an evaluation + * of this expression is row-major. Otherwise, it is column-major. + * \li \c Lazy: if this bit is set, the next evaluation of this expression will be canceled. + * This can be used, with care, to achieve lazy evaluation. + * \li \c Large: if this bit is set, optimization will be tuned for large matrices (typically, + * at least 32x32). + */ }; /** This is the "real scalar" type; if the \a Scalar type is already real numbers @@ -182,22 +193,22 @@ template<typename Derived> class MatrixBase /// \name Coefficient accessors //@{ - Scalar coeff(int row, int col) const; - Scalar operator()(int row, int col) const; + const Scalar coeff(int row, int col) const; + const Scalar operator()(int row, int col) const; Scalar& coeffRef(int row, int col); Scalar& operator()(int row, int col); - Scalar coeff(int index) const; - Scalar operator[](int index) const; + const Scalar coeff(int index) const; + const Scalar operator[](int index) const; Scalar& coeffRef(int index); Scalar& operator[](int index); - Scalar x() const; - Scalar y() const; - Scalar z() const; - Scalar w() const; + const Scalar x() const; + const Scalar y() const; + const Scalar z() const; + const Scalar w() const; Scalar& x(); Scalar& y(); Scalar& z(); diff --git a/Eigen/src/Core/Minor.h b/Eigen/src/Core/Minor.h index 3897c8bac..62941d764 100644 --- a/Eigen/src/Core/Minor.h +++ b/Eigen/src/Core/Minor.h @@ -49,7 +49,8 @@ struct ei_traits<Minor<MatrixType> > MaxRowsAtCompileTime = (MatrixType::MaxRowsAtCompileTime != Dynamic) ? MatrixType::MaxRowsAtCompileTime - 1 : Dynamic, MaxColsAtCompileTime = (MatrixType::MaxColsAtCompileTime != Dynamic) ? - MatrixType::MaxColsAtCompileTime - 1 : Dynamic + MatrixType::MaxColsAtCompileTime - 1 : Dynamic, + Flags = MatrixType::Flags }; }; @@ -80,7 +81,7 @@ template<typename MatrixType> class Minor return m_matrix.const_cast_derived().coeffRef(row + (row >= m_row), col + (col >= m_col)); } - Scalar _coeff(int row, int col) const + const Scalar _coeff(int row, int col) const { return m_matrix.coeff(row + (row >= m_row), col + (col >= m_col)); } diff --git a/Eigen/src/Core/Ones.h b/Eigen/src/Core/Ones.h index 0d0f002bd..05d9b4270 100644 --- a/Eigen/src/Core/Ones.h +++ b/Eigen/src/Core/Ones.h @@ -40,7 +40,8 @@ struct ei_traits<Ones<MatrixType> > RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, + Flags = MatrixType::Flags }; }; @@ -56,7 +57,7 @@ template<typename MatrixType> class Ones : ei_no_assignment_operator, int _rows() const { return m_rows.value(); } int _cols() const { return m_cols.value(); } - Scalar _coeff(int, int) const + const Scalar _coeff(int, int) const { return static_cast<Scalar>(1); } diff --git a/Eigen/src/Core/OperatorEquals.h b/Eigen/src/Core/OperatorEquals.h index babd51776..a6165c912 100644 --- a/Eigen/src/Core/OperatorEquals.h +++ b/Eigen/src/Core/OperatorEquals.h @@ -111,12 +111,12 @@ Derived& MatrixBase<Derived> && SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT) ei_vector_operator_equals_unroller <Derived, OtherDerived, - SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT ? SizeAtCompileTime : Dynamic>::run - (*static_cast<Derived*>(this), *static_cast<const OtherDerived*>(&other)); + SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT ? SizeAtCompileTime : Dynamic + >::run(derived(), other.derived()); else for(int i = 0; i < size(); i++) coeffRef(i) = other.coeff(i); - return *static_cast<Derived*>(this); + return derived(); } else // copying a matrix expression into a matrix { @@ -127,8 +127,8 @@ Derived& MatrixBase<Derived> { ei_matrix_operator_equals_unroller <Derived, OtherDerived, - SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT ? SizeAtCompileTime : Dynamic>::run - (*static_cast<Derived*>(this), *static_cast<const OtherDerived*>(&other)); + SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT ? SizeAtCompileTime : Dynamic + >::run(derived(), other.derived()); } else { diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index a1ec6b8d2..f8b173bcf 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -82,7 +82,10 @@ struct ei_traits<Product<Lhs, Rhs, EvalMode> > RowsAtCompileTime = Lhs::RowsAtCompileTime, ColsAtCompileTime = Rhs::ColsAtCompileTime, MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime, - MaxColsAtCompileTime = Rhs::MaxColsAtCompileTime + MaxColsAtCompileTime = Rhs::MaxColsAtCompileTime, + Flags = (RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic) + ? (unsigned int)(Lhs::Flags | Rhs::Flags) + : (unsigned int)(Lhs::Flags | Rhs::Flags) & ~Large }; }; @@ -120,7 +123,7 @@ template<typename Lhs, typename Rhs, int EvalMode> class Product : ei_no_assignm int _rows() const { return m_lhs.rows(); } int _cols() const { return m_rhs.cols(); } - Scalar _coeff(int row, int col) const + const Scalar _coeff(int row, int col) const { Scalar res; if(EIGEN_UNROLLED_LOOPS diff --git a/Eigen/src/Core/Random.h b/Eigen/src/Core/Random.h index f756c9649..36b8c9ee5 100644 --- a/Eigen/src/Core/Random.h +++ b/Eigen/src/Core/Random.h @@ -40,7 +40,8 @@ struct ei_traits<Random<MatrixType> > RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, + Flags = MatrixType::Flags }; }; @@ -56,7 +57,7 @@ template<typename MatrixType> class Random : ei_no_assignment_operator, int _rows() const { return m_rows.value(); } int _cols() const { return m_cols.value(); } - Scalar _coeff(int, int) const + const Scalar _coeff(int, int) const { return ei_random<Scalar>(); } diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index fa1f0e652..9afb4e664 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -92,7 +92,10 @@ struct ei_traits<PartialRedux<Direction, BinaryOp, MatrixType> > RowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::RowsAtCompileTime, ColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, + Flags = (RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic) + ? (unsigned int)MatrixType::Flags + : (unsigned int)MatrixType::Flags & ~Large }; }; @@ -112,7 +115,7 @@ class PartialRedux : ei_no_assignment_operator, int _rows() const { return (Direction==Vertical ? 1 : m_matrix.rows()); } int _cols() const { return (Direction==Horizontal ? 1 : m_matrix.cols()); } - Scalar _coeff(int i, int j) const + const Scalar _coeff(int i, int j) const { if (Direction==Vertical) return this->col(j).redux(m_functor); diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 2f1b54d99..de481a31b 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -45,7 +45,8 @@ struct ei_traits<Transpose<MatrixType> > RowsAtCompileTime = MatrixType::ColsAtCompileTime, ColsAtCompileTime = MatrixType::RowsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime + MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime, + Flags = MatrixType::Flags ^ RowMajor }; }; @@ -70,7 +71,7 @@ template<typename MatrixType> class Transpose return m_matrix.const_cast_derived().coeffRef(col, row); } - Scalar _coeff(int row, int col) const + const Scalar _coeff(int row, int col) const { return m_matrix.coeff(col, row); } diff --git a/Eigen/src/Core/Util.h b/Eigen/src/Core/Util.h index 76b0ea99d..87808351c 100644 --- a/Eigen/src/Core/Util.h +++ b/Eigen/src/Core/Util.h @@ -39,7 +39,7 @@ #ifdef EIGEN_DEFAULT_TO_ROW_MAJOR #define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER RowMajor #else -#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER ColumnMajor +#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER 0 #endif #undef minor @@ -116,7 +116,8 @@ enum { RowsAtCompileTime = Base::RowsAtCompileTime, \ MaxColsAtCompileTime = Base::MaxColsAtCompileTime, \ SizeAtCompileTime = Base::SizeAtCompileTime, \ MaxSizeAtCompileTime = Base::MaxSizeAtCompileTime, \ - IsVectorAtCompileTime = Base::IsVectorAtCompileTime }; + IsVectorAtCompileTime = Base::IsVectorAtCompileTime, \ + Flags = Base::Flags }; #define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived) \ _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::MatrixBase<Derived>) \ @@ -125,8 +126,11 @@ friend class Eigen::MatrixBase<Derived>; #define EIGEN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b) const int Dynamic = -10; -const int ColumnMajor = 0; -const int RowMajor = 1; + +// matrix/expression flags +const unsigned int RowMajor = 0x1; +const unsigned int Lazy = 0x2; +const unsigned int Large = 0x4; enum CornerType { TopLeft, TopRight, BottomLeft, BottomRight }; diff --git a/Eigen/src/Core/Zero.h b/Eigen/src/Core/Zero.h index 33792f0b1..106742d32 100644 --- a/Eigen/src/Core/Zero.h +++ b/Eigen/src/Core/Zero.h @@ -40,7 +40,8 @@ struct ei_traits<Zero<MatrixType> > RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, + Flags = MatrixType::Flags }; }; diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp index 5e79ec21c..ac87738cc 100644 --- a/test/basicstuff.cpp +++ b/test/basicstuff.cpp @@ -76,8 +76,8 @@ template<typename MatrixType> void basicStuff(const MatrixType& m) square.col(r) = square.row(r).eval(); Matrix<Scalar, 1, MatrixType::RowsAtCompileTime> rv(rows); Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> cv(rows); - rv = square.col(r); - cv = square.row(r); + rv = square.row(r); + cv = square.col(r); VERIFY_IS_APPROX(rv, cv.transpose()); if(cols!=1 && rows!=1 && MatrixType::SizeAtCompileTime!=Dynamic) |