From 2ee68a074efc1163358fb3b51fb4b23e83a05f97 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 12 Mar 2008 17:17:36 +0000 Subject: generalized ei_traits<>. Finally the importing macro is named EIGEN_BASIC_PUBLIC_INTERFACE because it does not only import the ei_traits, it also makes the base class a friend, etc. --- Eigen/src/Core/Block.h | 85 ++++++++++----------- Eigen/src/Core/Coeffs.h | 48 ++++++------ Eigen/src/Core/Column.h | 25 +++--- Eigen/src/Core/CommaInitializer.h | 6 +- Eigen/src/Core/CwiseBinaryOp.h | 30 +++++--- Eigen/src/Core/CwiseUnaryOp.h | 36 ++++----- Eigen/src/Core/DiagonalCoeffs.h | 33 ++++---- Eigen/src/Core/DiagonalMatrix.h | 27 +++---- Eigen/src/Core/Dot.h | 20 ++--- Eigen/src/Core/Eval.h | 33 +++++--- Eigen/src/Core/EvalOMP.h | 33 +++++--- Eigen/src/Core/ForwardDeclarations.h | 2 +- Eigen/src/Core/Fuzzy.h | 6 +- Eigen/src/Core/Identity.h | 26 +++---- Eigen/src/Core/Map.h | 29 ++++--- Eigen/src/Core/Matrix.h | 33 ++++---- Eigen/src/Core/MatrixBase.h | 142 +++++++++++++++++------------------ Eigen/src/Core/MatrixRef.h | 24 +++--- Eigen/src/Core/Minor.h | 33 ++++---- Eigen/src/Core/Ones.h | 30 ++++---- Eigen/src/Core/OperatorEquals.h | 20 ++--- Eigen/src/Core/Product.h | 35 ++++----- Eigen/src/Core/Random.h | 30 ++++---- Eigen/src/Core/Row.h | 25 +++--- Eigen/src/Core/Swap.h | 6 +- Eigen/src/Core/Trace.h | 10 +-- Eigen/src/Core/Transpose.h | 25 +++--- Eigen/src/Core/Util.h | 21 +++++- Eigen/src/Core/Zero.h | 31 ++++---- 29 files changed, 477 insertions(+), 427 deletions(-) (limited to 'Eigen/src/Core') diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index f9f893fb4..8db636ece 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -57,18 +57,27 @@ * \sa MatrixBase::block(int,int,int,int), MatrixBase::block(int,int), class VectorBlock */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum{ + RowsAtCompileTime = MatrixType::RowsAtCompileTime == 1 ? 1 : BlockRows, + ColsAtCompileTime = MatrixType::ColsAtCompileTime == 1 ? 1 : BlockCols, + MaxRowsAtCompileTime = RowsAtCompileTime == 1 ? 1 + : (BlockRows==Dynamic ? MatrixType::MaxRowsAtCompileTime : BlockRows), + MaxColsAtCompileTime = ColsAtCompileTime == 1 ? 1 + : (BlockCols==Dynamic ? MatrixType::MaxColsAtCompileTime : BlockCols) + }; +}; template class Block : public MatrixBase > { public: - typedef typename Scalar::Type Scalar; + + EIGEN_BASIC_PUBLIC_INTERFACE(Block) + typedef typename MatrixType::AsArg MatRef; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; /** Fixed-size constructor */ @@ -97,14 +106,6 @@ template class Block EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block) private: - enum{ - RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime == 1 ? 1 : BlockRows, - ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime == 1 ? 1 : BlockCols, - MaxRowsAtCompileTime = RowsAtCompileTime == 1 ? 1 - : (BlockRows==Dynamic ? MatrixType::Traits::MaxRowsAtCompileTime : BlockRows), - MaxColsAtCompileTime = ColsAtCompileTime == 1 ? 1 - : (BlockCols==Dynamic ? MatrixType::Traits::MaxColsAtCompileTime : BlockCols) - }; const Block& _asArg() const { return *this; } int _rows() const { return m_blockRows.value(); } @@ -123,8 +124,8 @@ template class Block protected: MatRef m_matrix; - IntAtRunTimeIfDynamic m_startRow; - IntAtRunTimeIfDynamic m_startCol; + IntAtRunTimeIfDynamic m_startRow; + IntAtRunTimeIfDynamic m_startCol; IntAtRunTimeIfDynamic m_blockRows; IntAtRunTimeIfDynamic m_blockCols; }; @@ -180,11 +181,11 @@ template Block MatrixBase ::block(int start, int size) { - assert(Traits::IsVectorAtCompileTime); - return Block(asArg(), Traits::RowsAtCompileTime == 1 ? 0 : start, - Traits::ColsAtCompileTime == 1 ? 0 : start, - Traits::RowsAtCompileTime == 1 ? 1 : size, - Traits::ColsAtCompileTime == 1 ? 1 : size); + assert(IsVectorAtCompileTime); + return Block(asArg(), RowsAtCompileTime == 1 ? 0 : start, + ColsAtCompileTime == 1 ? 0 : start, + RowsAtCompileTime == 1 ? 1 : size, + ColsAtCompileTime == 1 ? 1 : size); } /** This is the const version of block(int,int).*/ @@ -192,11 +193,11 @@ template const Block MatrixBase ::block(int start, int size) const { - assert(Traits::IsVectorAtCompileTime); - return Block(asArg(), Traits::RowsAtCompileTime == 1 ? 0 : start, - Traits::ColsAtCompileTime == 1 ? 0 : start, - Traits::RowsAtCompileTime == 1 ? 1 : size, - Traits::ColsAtCompileTime == 1 ? 1 : size); + assert(IsVectorAtCompileTime); + return Block(asArg(), RowsAtCompileTime == 1 ? 0 : start, + ColsAtCompileTime == 1 ? 0 : start, + RowsAtCompileTime == 1 ? 1 : size, + ColsAtCompileTime == 1 ? 1 : size); } /** \returns a dynamic-size expression of the first coefficients of *this. @@ -218,10 +219,10 @@ template Block MatrixBase ::start(int size) { - assert(Traits::IsVectorAtCompileTime); + assert(IsVectorAtCompileTime); return Block(asArg(), 0, 0, - Traits::RowsAtCompileTime == 1 ? 1 : size, - Traits::ColsAtCompileTime == 1 ? 1 : size); + RowsAtCompileTime == 1 ? 1 : size, + ColsAtCompileTime == 1 ? 1 : size); } /** This is the const version of start(int).*/ @@ -229,10 +230,10 @@ template const Block MatrixBase ::start(int size) const { - assert(Traits::IsVectorAtCompileTime); + assert(IsVectorAtCompileTime); return Block(asArg(), 0, 0, - Traits::RowsAtCompileTime == 1 ? 1 : size, - Traits::ColsAtCompileTime == 1 ? 1 : size); + RowsAtCompileTime == 1 ? 1 : size, + ColsAtCompileTime == 1 ? 1 : size); } /** \returns a dynamic-size expression of the last coefficients of *this. @@ -254,12 +255,12 @@ template Block MatrixBase ::end(int size) { - assert(Traits::IsVectorAtCompileTime); + assert(IsVectorAtCompileTime); return Block(asArg(), - Traits::RowsAtCompileTime == 1 ? 0 : rows() - size, - Traits::ColsAtCompileTime == 1 ? 0 : cols() - size, - Traits::RowsAtCompileTime == 1 ? 1 : size, - Traits::ColsAtCompileTime == 1 ? 1 : size); + RowsAtCompileTime == 1 ? 0 : rows() - size, + ColsAtCompileTime == 1 ? 0 : cols() - size, + RowsAtCompileTime == 1 ? 1 : size, + ColsAtCompileTime == 1 ? 1 : size); } /** This is the const version of end(int).*/ @@ -267,12 +268,12 @@ template const Block MatrixBase ::end(int size) const { - assert(Traits::IsVectorAtCompileTime); + assert(IsVectorAtCompileTime); return Block(asArg(), - Traits::RowsAtCompileTime == 1 ? 0 : rows() - size, - Traits::ColsAtCompileTime == 1 ? 0 : cols() - size, - Traits::RowsAtCompileTime == 1 ? 1 : size, - Traits::ColsAtCompileTime == 1 ? 1 : size); + RowsAtCompileTime == 1 ? 0 : rows() - size, + ColsAtCompileTime == 1 ? 0 : cols() - size, + RowsAtCompileTime == 1 ? 1 : size, + ColsAtCompileTime == 1 ? 1 : size); } /** \returns a dynamic-size expression of a corner of *this. diff --git a/Eigen/src/Core/Coeffs.h b/Eigen/src/Core/Coeffs.h index 6ee45c260..bbaa3d33a 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 Scalar::Type MatrixBase +typename ei_traits::Scalar MatrixBase ::coeff(int row, int col) const { eigen_internal_assert(row >= 0 && row < rows() @@ -53,7 +53,7 @@ typename Scalar::Type MatrixBase * \sa operator()(int,int), operator[](int) const */ template -typename Scalar::Type MatrixBase +typename ei_traits::Scalar MatrixBase ::operator()(int row, int col) const { assert(row >= 0 && row < rows() @@ -76,7 +76,7 @@ typename Scalar::Type MatrixBase * \sa operator()(int,int), coeff(int, int) const, coeffRef(int) */ template -typename Scalar::Type& MatrixBase +typename ei_traits::Scalar& MatrixBase ::coeffRef(int row, int col) { eigen_internal_assert(row >= 0 && row < rows() @@ -89,7 +89,7 @@ typename Scalar::Type& MatrixBase * \sa operator()(int,int) const, operator[](int) */ template -typename Scalar::Type& MatrixBase +typename ei_traits::Scalar& MatrixBase ::operator()(int row, int col) { assert(row >= 0 && row < rows() @@ -112,11 +112,11 @@ typename Scalar::Type& MatrixBase * \sa operator[](int) const, coeffRef(int), coeff(int,int) const */ template -typename Scalar::Type MatrixBase +typename ei_traits::Scalar MatrixBase ::coeff(int index) const { - eigen_internal_assert(Traits::IsVectorAtCompileTime); - if(Traits::RowsAtCompileTime == 1) + eigen_internal_assert(IsVectorAtCompileTime); + if(RowsAtCompileTime == 1) { eigen_internal_assert(index >= 0 && index < cols()); return coeff(0, index); @@ -136,11 +136,11 @@ typename Scalar::Type MatrixBase * z() const, w() const */ template -typename Scalar::Type MatrixBase +typename ei_traits::Scalar MatrixBase ::operator[](int index) const { - assert(Traits::IsVectorAtCompileTime); - if(Traits::RowsAtCompileTime == 1) + assert(IsVectorAtCompileTime); + if(RowsAtCompileTime == 1) { assert(index >= 0 && index < cols()); return coeff(0, index); @@ -167,11 +167,11 @@ typename Scalar::Type MatrixBase * \sa operator[](int), coeff(int) const, coeffRef(int,int) */ template -typename Scalar::Type& MatrixBase +typename ei_traits::Scalar& MatrixBase ::coeffRef(int index) { - eigen_internal_assert(Traits::IsVectorAtCompileTime); - if(Traits::RowsAtCompileTime == 1) + eigen_internal_assert(IsVectorAtCompileTime); + if(RowsAtCompileTime == 1) { eigen_internal_assert(index >= 0 && index < cols()); return coeffRef(0, index); @@ -190,11 +190,11 @@ typename Scalar::Type& MatrixBase * \sa operator[](int) const, operator()(int,int), x(), y(), z(), w() */ template -typename Scalar::Type& MatrixBase +typename ei_traits::Scalar& MatrixBase ::operator[](int index) { - assert(Traits::IsVectorAtCompileTime); - if(Traits::RowsAtCompileTime == 1) + assert(IsVectorAtCompileTime); + if(RowsAtCompileTime == 1) { assert(index >= 0 && index < cols()); return coeffRef(0, index); @@ -208,42 +208,42 @@ typename Scalar::Type& MatrixBase /** equivalent to operator[](0). \only_for_vectors */ template -typename Scalar::Type MatrixBase +typename ei_traits::Scalar MatrixBase ::x() const { return (*this)[0]; } /** equivalent to operator[](1). \only_for_vectors */ template -typename Scalar::Type MatrixBase +typename ei_traits::Scalar MatrixBase ::y() const { return (*this)[1]; } /** equivalent to operator[](2). \only_for_vectors */ template -typename Scalar::Type MatrixBase +typename ei_traits::Scalar MatrixBase ::z() const { return (*this)[2]; } /** equivalent to operator[](3). \only_for_vectors */ template -typename Scalar::Type MatrixBase +typename ei_traits::Scalar MatrixBase ::w() const { return (*this)[3]; } /** equivalent to operator[](0). \only_for_vectors */ template -typename Scalar::Type& MatrixBase +typename ei_traits::Scalar& MatrixBase ::x() { return (*this)[0]; } /** equivalent to operator[](1). \only_for_vectors */ template -typename Scalar::Type& MatrixBase +typename ei_traits::Scalar& MatrixBase ::y() { return (*this)[1]; } /** equivalent to operator[](2). \only_for_vectors */ template -typename Scalar::Type& MatrixBase +typename ei_traits::Scalar& MatrixBase ::z() { return (*this)[2]; } /** equivalent to operator[](3). \only_for_vectors */ template -typename Scalar::Type& MatrixBase +typename ei_traits::Scalar& MatrixBase ::w() { return (*this)[3]; } #endif // EIGEN_COEFFS_H diff --git a/Eigen/src/Core/Column.h b/Eigen/src/Core/Column.h index 7eee89d91..943095671 100644 --- a/Eigen/src/Core/Column.h +++ b/Eigen/src/Core/Column.h @@ -46,18 +46,25 @@ * \sa MatrixBase::col() */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum { + RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = 1, + MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = 1 + }; +}; template class Column : public MatrixBase > { public: - typedef typename Scalar::Type Scalar; + + EIGEN_BASIC_PUBLIC_INTERFACE(Column) + typedef typename MatrixType::AsArg MatRef; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; Column(const MatRef& matrix, int col) : m_matrix(matrix), m_col(col) @@ -68,12 +75,6 @@ template class Column EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Column) private: - enum { - RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, - ColsAtCompileTime = 1, - MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = 1 - }; const Column& _asArg() const { return *this; } int _rows() const { return m_matrix.rows(); } diff --git a/Eigen/src/Core/CommaInitializer.h b/Eigen/src/Core/CommaInitializer.h index b7de3b3aa..5456eb7c6 100644 --- a/Eigen/src/Core/CommaInitializer.h +++ b/Eigen/src/Core/CommaInitializer.h @@ -55,7 +55,7 @@ struct MatrixBase::CommaInitializer } assert(m_col::CommaInitializer ~CommaInitializer(void) { - assert((m_row+m_currentBlockRows)==m_matrix.rows() && m_col==m_matrix.cols() && "Too few coefficients passed to Matrix::operator<<"); + assert((m_row+m_currentBlockRows) == m_matrix.rows() + && m_col == m_matrix.cols() + && "Too few coefficients passed to Matrix::operator<<"); } Derived& m_matrix; diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h index 5314eb793..63e0fbac0 100644 --- a/Eigen/src/Core/CwiseBinaryOp.h +++ b/Eigen/src/Core/CwiseBinaryOp.h @@ -47,20 +47,32 @@ * \sa class ScalarProductOp, class ScalarQuotientOp */ template -struct Scalar > -{ typedef typename ei_result_of::type Type; }; +struct ei_traits > +{ + typedef typename ei_result_of< + BinaryOp( + typename Lhs::Scalar, + typename Rhs::Scalar + ) + >::type Scalar; + enum { + RowsAtCompileTime = Lhs::RowsAtCompileTime, + ColsAtCompileTime = Lhs::ColsAtCompileTime, + MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime, + MaxColsAtCompileTime = Lhs::MaxColsAtCompileTime + }; +}; template class CwiseBinaryOp : NoOperatorEquals, public MatrixBase > { public: - typedef typename Scalar::Type Scalar; + + EIGEN_BASIC_PUBLIC_INTERFACE(CwiseBinaryOp) + typedef typename Lhs::AsArg LhsRef; typedef typename Rhs::AsArg RhsRef; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; CwiseBinaryOp(const LhsRef& lhs, const RhsRef& rhs, const BinaryOp& func = BinaryOp()) : m_lhs(lhs), m_rhs(rhs), m_functor(func) @@ -69,12 +81,6 @@ class CwiseBinaryOp : NoOperatorEquals, } private: - enum { - RowsAtCompileTime = Lhs::Traits::RowsAtCompileTime, - ColsAtCompileTime = Lhs::Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = Lhs::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = Lhs::Traits::MaxColsAtCompileTime - }; const CwiseBinaryOp& _asArg() const { return *this; } int _rows() const { return m_lhs.rows(); } diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h index 55ff7e170..a2ad55aef 100644 --- a/Eigen/src/Core/CwiseUnaryOp.h +++ b/Eigen/src/Core/CwiseUnaryOp.h @@ -40,29 +40,32 @@ * \sa class CwiseBinaryOp */ template -struct Scalar > -{ typedef typename ei_result_of::type Type; }; +struct ei_traits > +{ + typedef typename ei_result_of< + UnaryOp(typename MatrixType::Scalar) + >::type Scalar; + enum { + RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + }; +}; template class CwiseUnaryOp : NoOperatorEquals, public MatrixBase > { public: - typedef typename ei_result_of::type Scalar; + + EIGEN_BASIC_PUBLIC_INTERFACE(CwiseUnaryOp) + typedef typename MatrixType::AsArg MatRef; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; CwiseUnaryOp(const MatRef& mat, const UnaryOp& func = UnaryOp()) : m_matrix(mat), m_functor(func) {} private: - enum { - RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime - }; const CwiseUnaryOp& _asArg() const { return *this; } int _rows() const { return m_matrix.rows(); } @@ -155,7 +158,7 @@ MatrixBase::conjugate() const } /** \internal - * \brief Template functor to cast a scalar to another + * \brief Template functor to cast a scalar to another type * * \sa class CwiseUnaryOp, MatrixBase::cast() */ @@ -183,9 +186,8 @@ MatrixBase::cast() const return CwiseUnaryOp, Derived>(asArg()); } - /** \internal - * \brief Template functor to multiply a scalar by a fixed another one + * \brief Template functor to multiply a scalar by a fixed other one * * \sa class CwiseUnaryOp, MatrixBase::operator*, MatrixBase::operator/ */ @@ -198,7 +200,7 @@ struct ScalarMultipleOp { /** \relates MatrixBase \sa class ScalarMultipleOp */ template -const CwiseUnaryOp::Type>, Derived> +const CwiseUnaryOp::Scalar>, Derived> MatrixBase::operator*(const Scalar& scalar) const { return CwiseUnaryOp, Derived>(asArg(), ScalarMultipleOp(scalar)); @@ -206,7 +208,7 @@ MatrixBase::operator*(const Scalar& scalar) const /** \relates MatrixBase \sa class ScalarMultipleOp */ template -const CwiseUnaryOp::Type>, Derived> +const CwiseUnaryOp::Scalar>, Derived> MatrixBase::operator/(const Scalar& scalar) const { assert(NumTraits::HasFloatingPoint); diff --git a/Eigen/src/Core/DiagonalCoeffs.h b/Eigen/src/Core/DiagonalCoeffs.h index a03241e65..e8bc04108 100644 --- a/Eigen/src/Core/DiagonalCoeffs.h +++ b/Eigen/src/Core/DiagonalCoeffs.h @@ -38,34 +38,35 @@ * \sa MatrixBase::diagonal() */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum { + RowsAtCompileTime = MatrixType::SizeAtCompileTime == Dynamic ? Dynamic + : EIGEN_ENUM_MIN(MatrixType::RowsAtCompileTime, + MatrixType::ColsAtCompileTime), + ColsAtCompileTime = 1, + MaxRowsAtCompileTime = MatrixType::MaxSizeAtCompileTime == Dynamic ? Dynamic + : EIGEN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime, + MatrixType::MaxColsAtCompileTime), + MaxColsAtCompileTime = 1 + }; +}; template class DiagonalCoeffs : public MatrixBase > { public: - typedef typename Scalar::Type Scalar; + + EIGEN_BASIC_PUBLIC_INTERFACE(DiagonalCoeffs) + typedef typename MatrixType::AsArg MatRef; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; DiagonalCoeffs(const MatRef& matrix) : m_matrix(matrix) {} EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DiagonalCoeffs) private: - enum { - RowsAtCompileTime = MatrixType::Traits::SizeAtCompileTime == Dynamic ? Dynamic - : EIGEN_ENUM_MIN(MatrixType::Traits::RowsAtCompileTime, - MatrixType::Traits::ColsAtCompileTime), - ColsAtCompileTime = 1, - MaxRowsAtCompileTime = MatrixType::Traits::MaxSizeAtCompileTime == Dynamic ? Dynamic - : EIGEN_ENUM_MIN(MatrixType::Traits::MaxRowsAtCompileTime, - MatrixType::Traits::MaxColsAtCompileTime), - MaxColsAtCompileTime = 1 - }; const DiagonalCoeffs& _asArg() const { return *this; } int _rows() const { return std::min(m_matrix.rows(), m_matrix.cols()); } diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h index 6b4e0b17a..e27d2c366 100644 --- a/Eigen/src/Core/DiagonalMatrix.h +++ b/Eigen/src/Core/DiagonalMatrix.h @@ -39,33 +39,34 @@ * \sa MatrixBase::diagonal(const OtherDerived&) */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename CoeffsVectorType::Scalar Scalar; + enum { + RowsAtCompileTime = CoeffsVectorType::SizeAtCompileTime, + ColsAtCompileTime = CoeffsVectorType::SizeAtCompileTime, + MaxRowsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime, + MaxColsAtCompileTime = CoeffsVectorType::MaxSizeAtCompileTime + }; +}; template class DiagonalMatrix : NoOperatorEquals, public MatrixBase > { public: - typedef typename Scalar::Type Scalar; + + EIGEN_BASIC_PUBLIC_INTERFACE(DiagonalMatrix) + typedef typename CoeffsVectorType::AsArg CoeffsVecRef; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; DiagonalMatrix(const CoeffsVecRef& coeffs) : m_coeffs(coeffs) { - assert(CoeffsVectorType::Traits::IsVectorAtCompileTime + assert(CoeffsVectorType::IsVectorAtCompileTime && coeffs.size() > 0); } private: - enum { - RowsAtCompileTime = CoeffsVectorType::Traits::SizeAtCompileTime, - ColsAtCompileTime = CoeffsVectorType::Traits::SizeAtCompileTime, - MaxRowsAtCompileTime = CoeffsVectorType::Traits::MaxSizeAtCompileTime, - MaxColsAtCompileTime = CoeffsVectorType::Traits::MaxSizeAtCompileTime - }; const DiagonalMatrix& _asArg() const { return *this; } int _rows() const { return m_coeffs.size(); } diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index 03764ba34..f4d13e517 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -69,18 +69,18 @@ struct DotUnroller */ template template -typename Scalar::Type +typename ei_traits::Scalar MatrixBase::dot(const MatrixBase& other) const { - assert(Traits::IsVectorAtCompileTime - && OtherDerived::Traits::IsVectorAtCompileTime + assert(IsVectorAtCompileTime + && OtherDerived::IsVectorAtCompileTime && size() == other.size()); Scalar res; if(EIGEN_UNROLLED_LOOPS - && Traits::SizeAtCompileTime != Dynamic - && Traits::SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT_PRODUCT) - DotUnroller > ::run(*static_cast(this), other, res); else @@ -99,7 +99,7 @@ MatrixBase::dot(const MatrixBase& other) const * \sa dot(), norm() */ template -typename NumTraits::Type>::Real MatrixBase::norm2() const +typename NumTraits::Scalar>::Real MatrixBase::norm2() const { return ei_real(dot(*this)); } @@ -111,7 +111,7 @@ typename NumTraits::Type>::Real MatrixBase::no * \sa dot(), norm2() */ template -typename NumTraits::Type>::Real MatrixBase::norm() const +typename NumTraits::Scalar>::Real MatrixBase::norm() const { return ei_sqrt(norm2()); } @@ -123,7 +123,7 @@ typename NumTraits::Type>::Real MatrixBase::no * \sa norm() */ template -const CwiseUnaryOp::Type>, Derived> +const CwiseUnaryOp::Scalar>, Derived> MatrixBase::normalized() const { return (*this) / norm(); diff --git a/Eigen/src/Core/Eval.h b/Eigen/src/Core/Eval.h index 85a9d0aa0..ece372a04 100644 --- a/Eigen/src/Core/Eval.h +++ b/Eigen/src/Core/Eval.h @@ -45,19 +45,26 @@ * \sa MatrixBase::eval() */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename ExpressionType::Scalar Scalar; + enum { + RowsAtCompileTime = ExpressionType::RowsAtCompileTime, + ColsAtCompileTime = ExpressionType::ColsAtCompileTime, + MaxRowsAtCompileTime = ExpressionType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = ExpressionType::MaxColsAtCompileTime + }; +}; template class Eval : NoOperatorEquals, public Matrix< typename ExpressionType::Scalar, - ExpressionType::Traits::RowsAtCompileTime, - ExpressionType::Traits::ColsAtCompileTime, + ExpressionType::RowsAtCompileTime, + ExpressionType::ColsAtCompileTime, EIGEN_DEFAULT_MATRIX_STORAGE_ORDER, - ExpressionType::Traits::MaxRowsAtCompileTime, - ExpressionType::Traits::MaxColsAtCompileTime> + ExpressionType::MaxRowsAtCompileTime, + ExpressionType::MaxColsAtCompileTime> { public: - typedef typename Scalar::Type Scalar; /** The actual matrix type to evaluate to. This type can be used independently * of the rest of this class to get the actual matrix type to evaluate and store @@ -67,12 +74,14 @@ template class Eval : NoOperatorEquals, * \include Eval_MatrixType.cpp * Output: \verbinclude Eval_MatrixType.out */ - typedef Matrix MatrixType; + ExpressionType::MaxRowsAtCompileTime, + ExpressionType::MaxColsAtCompileTime> MatrixType; + + _EIGEN_BASIC_PUBLIC_INTERFACE(Eval, MatrixType) explicit Eval(const ExpressionType& expr) : MatrixType(expr) {} }; diff --git a/Eigen/src/Core/EvalOMP.h b/Eigen/src/Core/EvalOMP.h index 7bc006d17..929e4515a 100644 --- a/Eigen/src/Core/EvalOMP.h +++ b/Eigen/src/Core/EvalOMP.h @@ -39,27 +39,40 @@ * * \sa MatrixBase::evalOMP(), class Eval, MatrixBase::eval() */ +template +struct ei_traits > +{ + typedef typename ExpressionType::Scalar Scalar; + enum { + RowsAtCompileTime = ExpressionType::RowsAtCompileTime, + ColsAtCompileTime = ExpressionType::ColsAtCompileTime, + MaxRowsAtCompileTime = ExpressionType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = ExpressionType::MaxColsAtCompileTime + }; +}; + template class EvalOMP : NoOperatorEquals, public Matrix< typename ExpressionType::Scalar, - ExpressionType::Traits::RowsAtCompileTime, - ExpressionType::Traits::ColsAtCompileTime, + ExpressionType::RowsAtCompileTime, + ExpressionType::ColsAtCompileTime, EIGEN_DEFAULT_MATRIX_STORAGE_ORDER, - ExpressionType::Traits::MaxRowsAtCompileTime, - ExpressionType::Traits::MaxColsAtCompileTime> + ExpressionType::MaxRowsAtCompileTime, + ExpressionType::MaxColsAtCompileTime> { public: - typedef typename ExpressionType::Scalar Scalar; /** The actual matrix type to evaluate to. This type can be used independently * of the rest of this class to get the actual matrix type to evaluate and store * the value of an expression. */ - typedef Matrix MatrixType; + ExpressionType::MaxRowsAtCompileTime, + ExpressionType::MaxColsAtCompileTime> MatrixType; + + _EIGEN_BASIC_PUBLIC_INTERFACE(EvalOMP, MatrixType) #ifdef _OPENMP explicit EvalOMP(const ExpressionType& other) diff --git a/Eigen/src/Core/ForwardDeclarations.h b/Eigen/src/Core/ForwardDeclarations.h index 5bed1f154..a548cd475 100644 --- a/Eigen/src/Core/ForwardDeclarations.h +++ b/Eigen/src/Core/ForwardDeclarations.h @@ -25,7 +25,7 @@ #ifndef EIGEN_FORWARDDECLARATIONS_H #define EIGEN_FORWARDDECLARATIONS_H -template struct Scalar; +template struct ei_traits; template class Matrix; template class MatrixRef; diff --git a/Eigen/src/Core/Fuzzy.h b/Eigen/src/Core/Fuzzy.h index a7a276328..0f601a8f5 100644 --- a/Eigen/src/Core/Fuzzy.h +++ b/Eigen/src/Core/Fuzzy.h @@ -49,7 +49,7 @@ bool MatrixBase::isApprox( ) const { assert(rows() == other.rows() && cols() == other.cols()); - if(Traits::IsVectorAtCompileTime) + if(IsVectorAtCompileTime) { return((*this - other).norm2() <= std::min(norm2(), other.norm2()) * prec * prec); } @@ -79,7 +79,7 @@ bool MatrixBase::isMuchSmallerThan( typename NumTraits::Real prec ) const { - if(Traits::IsVectorAtCompileTime) + if(IsVectorAtCompileTime) { return(norm2() <= ei_abs2(other * prec)); } @@ -110,7 +110,7 @@ bool MatrixBase::isMuchSmallerThan( ) const { assert(rows() == other.rows() && cols() == other.cols()); - if(Traits::IsVectorAtCompileTime) + if(IsVectorAtCompileTime) { return(norm2() <= other.norm2() * prec * prec); } diff --git a/Eigen/src/Core/Identity.h b/Eigen/src/Core/Identity.h index 38c8d0d32..5dd3ec609 100644 --- a/Eigen/src/Core/Identity.h +++ b/Eigen/src/Core/Identity.h @@ -32,17 +32,23 @@ * \sa MatrixBase::identity(), MatrixBase::identity(int,int), MatrixBase::setIdentity() */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum { + RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + }; +}; template class Identity : NoOperatorEquals, public MatrixBase > { public: - typedef typename Scalar::Type Scalar; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; + + EIGEN_BASIC_PUBLIC_INTERFACE(Identity) Identity(int rows, int cols) : m_rows(rows), m_cols(cols) { @@ -53,12 +59,6 @@ template class Identity : NoOperatorEquals, } private: - enum { - RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime - }; const Identity& _asArg() const { return *this; } int _rows() const { return m_rows.value(); } @@ -107,7 +107,7 @@ const Identity MatrixBase::identity(int rows, int cols) template const Identity MatrixBase::identity() { - return Identity(Traits::RowsAtCompileTime, Traits::ColsAtCompileTime); + return Identity(RowsAtCompileTime, ColsAtCompileTime); } /** \returns true if *this is approximately equal to the identity matrix diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h index 634a17165..e1b71952a 100644 --- a/Eigen/src/Core/Map.h +++ b/Eigen/src/Core/Map.h @@ -39,26 +39,25 @@ * \sa Matrix::map() */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum { + RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + }; +}; template class Map : public MatrixBase > { public: - typedef typename Scalar::Type Scalar; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; + + EIGEN_BASIC_PUBLIC_INTERFACE(Map) private: - enum { - RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, - Order = MatrixType::StorageOrder, - MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime - }; const Map& _asArg() const { return *this; } int _rows() const { return m_rows; } @@ -66,7 +65,7 @@ template class Map const Scalar& _coeff(int row, int col) const { - if(Order == ColumnMajor) + if(MatrixType::StorageOrder == ColumnMajor) return m_data[row + col * m_rows]; else // RowMajor return m_data[col + row * m_cols]; @@ -74,7 +73,7 @@ template class Map Scalar& _coeffRef(int row, int col) { - if(Order == ColumnMajor) + if(MatrixType::StorageOrder == ColumnMajor) return const_cast(m_data)[row + col * m_rows]; else // RowMajor return const_cast(m_data)[col + row * m_cols]; diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 68ccef1b1..ffb960493 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -72,8 +72,16 @@ * Note that most of the API is in the base class MatrixBase. */ template -struct Scalar > -{ typedef _Scalar Type; }; +struct ei_traits > +{ + typedef _Scalar Scalar; + enum { + RowsAtCompileTime = _Rows, + ColsAtCompileTime = _Cols, + MaxRowsAtCompileTime = _MaxRows, + MaxColsAtCompileTime = _MaxCols, + }; +}; template > { public: - friend class MatrixBase; - friend class MatrixBase::Traits; + + EIGEN_BASIC_PUBLIC_INTERFACE(Matrix) + + enum { StorageOrder = _StorageOrder }; + friend class Map; - typedef MatrixBase Base; - typedef typename Scalar::Type Scalar; typedef MatrixRef AsArg; friend class MatrixRef; private: - enum { - RowsAtCompileTime = _Rows, - ColsAtCompileTime = _Cols, - StorageOrder = _StorageOrder, - MaxRowsAtCompileTime = _MaxRows, - MaxColsAtCompileTime = _MaxCols, - MaxSizeAtCompileTime = _MaxRows == Dynamic || _MaxCols == Dynamic - ? Dynamic - : _MaxRows * _MaxCols - }; MatrixStorage m_storage; @@ -167,7 +166,7 @@ class Matrix : public MatrixBase::operator=(other); } /** This is a special case of the templated operator=. Its purpose is to diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 57ef46560..62dfc6bee 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -55,76 +55,74 @@ template class MatrixBase public: - typedef typename Scalar::Type Scalar; + typedef typename ei_traits::Scalar Scalar; + + /** The number of rows at compile-time. This is just a copy of the value provided + * by the \a Derived type. If a value is not known at compile-time, + * it is set to the \a Dynamic constant. + * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */ + enum { RowsAtCompileTime = ei_traits::RowsAtCompileTime }; + + /** The number of columns at compile-time. This is just a copy of the value provided + * by the \a Derived type. If a value is not known at compile-time, + * it is set to the \a Dynamic constant. + * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */ + enum { ColsAtCompileTime = ei_traits::ColsAtCompileTime }; + + /** This is equal to the number of coefficients, i.e. the number of + * rows times the number of columns, or to \a Dynamic if this is not + * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ + enum { SizeAtCompileTime + = ei_traits::RowsAtCompileTime == Dynamic + || ei_traits::ColsAtCompileTime == Dynamic + ? Dynamic + : ei_traits::RowsAtCompileTime * ei_traits::ColsAtCompileTime + }; - /** \brief Some traits provided by the Derived type. + /** This value is equal to the maximum possible number of rows that this expression + * might have. If this expression might have an arbitrarily high number of rows, + * this value is set to \a Dynamic. * - * Grouping these in a nested subclass is what was needed for ICC compatibility. */ - struct Traits - { - /** The number of rows at compile-time. This is just a copy of the value provided - * by the \a Derived type. If a value is not known at compile-time, - * it is set to the \a Dynamic constant. - * \sa MatrixBase::rows(), MatrixBase::cols(), ColsAtCompileTime, SizeAtCompileTime */ - enum { RowsAtCompileTime = Derived::RowsAtCompileTime }; - - /** The number of columns at compile-time. This is just a copy of the value provided - * by the \a Derived type. If a value is not known at compile-time, - * it is set to the \a Dynamic constant. - * \sa MatrixBase::rows(), MatrixBase::cols(), RowsAtCompileTime, SizeAtCompileTime */ - enum { ColsAtCompileTime = Derived::ColsAtCompileTime }; - - /** This is equal to the number of coefficients, i.e. the number of - * rows times the number of columns, or to \a Dynamic if this is not - * known at compile-time. \sa RowsAtCompileTime, ColsAtCompileTime */ - enum { SizeAtCompileTime - = Derived::RowsAtCompileTime == Dynamic || Derived::ColsAtCompileTime == Dynamic - ? Dynamic : Derived::RowsAtCompileTime * Derived::ColsAtCompileTime - }; - - /** This value is equal to the maximum possible number of rows that this expression - * might have. If this expression might have an arbitrarily high number of rows, - * this value is set to \a Dynamic. - * - * This value is useful to know when evaluating an expression, in order to determine - * whether it is possible to avoid doing a dynamic memory allocation. - * - * \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime - */ - enum { MaxRowsAtCompileTime = Derived::MaxRowsAtCompileTime }; - - /** This value is equal to the maximum possible number of columns that this expression - * might have. If this expression might have an arbitrarily high number of columns, - * this value is set to \a Dynamic. - * - * This value is useful to know when evaluating an expression, in order to determine - * whether it is possible to avoid doing a dynamic memory allocation. - * - * \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime - */ - enum { MaxColsAtCompileTime = Derived::MaxColsAtCompileTime }; - - /** This value is equal to the maximum possible number of coefficients that this expression - * might have. If this expression might have an arbitrarily high number of coefficients, - * this value is set to \a Dynamic. - * - * This value is useful to know when evaluating an expression, in order to determine - * whether it is possible to avoid doing a dynamic memory allocation. - * - * \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime - */ - enum { MaxSizeAtCompileTime - = Derived::MaxRowsAtCompileTime == Dynamic || Derived::MaxColsAtCompileTime == Dynamic - ? Dynamic : Derived::MaxRowsAtCompileTime * Derived::MaxColsAtCompileTime - }; - - /** 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). */ - enum { IsVectorAtCompileTime - = Derived::RowsAtCompileTime == 1 || Derived::ColsAtCompileTime == 1 - }; + * This value is useful to know when evaluating an expression, in order to determine + * whether it is possible to avoid doing a dynamic memory allocation. + * + * \sa RowsAtCompileTime, MaxColsAtCompileTime, MaxSizeAtCompileTime + */ + enum { MaxRowsAtCompileTime = ei_traits::MaxRowsAtCompileTime }; + + /** This value is equal to the maximum possible number of columns that this expression + * might have. If this expression might have an arbitrarily high number of columns, + * this value is set to \a Dynamic. + * + * This value is useful to know when evaluating an expression, in order to determine + * whether it is possible to avoid doing a dynamic memory allocation. + * + * \sa ColsAtCompileTime, MaxRowsAtCompileTime, MaxSizeAtCompileTime + */ + enum { MaxColsAtCompileTime = ei_traits::MaxColsAtCompileTime }; + + /** This value is equal to the maximum possible number of coefficients that this expression + * might have. If this expression might have an arbitrarily high number of coefficients, + * this value is set to \a Dynamic. + * + * This value is useful to know when evaluating an expression, in order to determine + * whether it is possible to avoid doing a dynamic memory allocation. + * + * \sa SizeAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime + */ + enum { MaxSizeAtCompileTime + = ei_traits::MaxRowsAtCompileTime == Dynamic + || ei_traits::MaxColsAtCompileTime == Dynamic + ? Dynamic + : ei_traits::MaxRowsAtCompileTime * ei_traits::MaxColsAtCompileTime + }; + + /** 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). */ + enum { IsVectorAtCompileTime + = ei_traits::RowsAtCompileTime == 1 || ei_traits::ColsAtCompileTime == 1 }; /** This is the "reference type" used to pass objects of type MatrixBase as arguments @@ -149,17 +147,17 @@ template class MatrixBase /// \name matrix properties //@{ - /** \returns the number of rows. \sa cols(), Traits::RowsAtCompileTime */ + /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ int rows() const { return static_cast(this)->_rows(); } - /** \returns the number of columns. \sa row(), Traits::ColsAtCompileTime*/ + /** \returns the number of columns. \sa row(), ColsAtCompileTime*/ int cols() const { return static_cast(this)->_cols(); } /** \returns the number of coefficients, which is \a rows()*cols(). - * \sa rows(), cols(), Traits::SizeAtCompileTime. */ + * \sa rows(), cols(), SizeAtCompileTime. */ int size() const { return rows() * cols(); } /** \returns true if either the number of rows or the number of columns is equal to 1. * In other words, this function returns * \code rows()==1 || cols()==1 \endcode - * \sa rows(), cols(), Traits::IsVectorAtCompileTime. */ + * \sa rows(), cols(), IsVectorAtCompileTime. */ bool isVector() const { return rows()==1 || cols()==1; } //@} diff --git a/Eigen/src/Core/MatrixRef.h b/Eigen/src/Core/MatrixRef.h index 5d3100d22..0d0f13f1c 100644 --- a/Eigen/src/Core/MatrixRef.h +++ b/Eigen/src/Core/MatrixRef.h @@ -26,17 +26,23 @@ #define EIGEN_MATRIXREF_H template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum { + RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + }; +}; template class MatrixRef : public MatrixBase > { public: - typedef typename Scalar::Type Scalar; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; + + EIGEN_BASIC_PUBLIC_INTERFACE(MatrixRef) MatrixRef(const MatrixType& matrix) : m_matrix(matrix) {} ~MatrixRef() {} @@ -44,12 +50,6 @@ template class MatrixRef EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixRef) private: - enum { - RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime - }; MatrixRef _asArg() const { return *this; } int _rows() const { return m_matrix.rows(); } diff --git a/Eigen/src/Core/Minor.h b/Eigen/src/Core/Minor.h index faab9c8ae..bb957b16b 100644 --- a/Eigen/src/Core/Minor.h +++ b/Eigen/src/Core/Minor.h @@ -38,18 +38,29 @@ * \sa MatrixBase::minor() */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum { + RowsAtCompileTime = (MatrixType::RowsAtCompileTime != Dynamic) ? + MatrixType::RowsAtCompileTime - 1 : Dynamic, + ColsAtCompileTime = (MatrixType::ColsAtCompileTime != Dynamic) ? + MatrixType::ColsAtCompileTime - 1 : Dynamic, + MaxRowsAtCompileTime = (MatrixType::MaxRowsAtCompileTime != Dynamic) ? + MatrixType::MaxRowsAtCompileTime - 1 : Dynamic, + MaxColsAtCompileTime = (MatrixType::MaxColsAtCompileTime != Dynamic) ? + MatrixType::MaxColsAtCompileTime - 1 : Dynamic + }; +}; template class Minor : public MatrixBase > { public: - typedef typename Scalar::Type Scalar; + + EIGEN_BASIC_PUBLIC_INTERFACE(Minor) + typedef typename MatrixType::AsArg MatRef; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; Minor(const MatRef& matrix, int row, int col) @@ -62,16 +73,6 @@ template class Minor EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Minor) private: - enum { - RowsAtCompileTime = (MatrixType::Traits::RowsAtCompileTime != Dynamic) ? - MatrixType::Traits::RowsAtCompileTime - 1 : Dynamic, - ColsAtCompileTime = (MatrixType::Traits::ColsAtCompileTime != Dynamic) ? - MatrixType::Traits::ColsAtCompileTime - 1 : Dynamic, - MaxRowsAtCompileTime = (MatrixType::Traits::MaxRowsAtCompileTime != Dynamic) ? - MatrixType::Traits::MaxRowsAtCompileTime - 1 : Dynamic, - MaxColsAtCompileTime = (MatrixType::Traits::MaxColsAtCompileTime != Dynamic) ? - MatrixType::Traits::MaxColsAtCompileTime - 1 : Dynamic - }; const Minor& _asArg() const { return *this; } int _rows() const { return m_matrix.rows() - 1; } diff --git a/Eigen/src/Core/Ones.h b/Eigen/src/Core/Ones.h index b77542d98..34bc3e8a7 100644 --- a/Eigen/src/Core/Ones.h +++ b/Eigen/src/Core/Ones.h @@ -33,25 +33,25 @@ * MatrixBase::setOnes(), MatrixBase::isOnes() */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum { + RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + }; +}; template class Ones : NoOperatorEquals, public MatrixBase > { public: - typedef typename Scalar::Type Scalar; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; + + EIGEN_BASIC_PUBLIC_INTERFACE(Ones) private: - enum { - RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime - }; const Ones& _asArg() const { return *this; } int _rows() const { return m_rows.value(); } @@ -115,8 +115,8 @@ const Ones MatrixBase::ones(int rows, int cols) template const Ones MatrixBase::ones(int size) { - assert(Traits::IsVectorAtCompileTime); - if(Traits::RowsAtCompileTime == 1) return Ones(1, size); + assert(IsVectorAtCompileTime); + if(RowsAtCompileTime == 1) return Ones(1, size); else return Ones(size, 1); } @@ -133,7 +133,7 @@ const Ones MatrixBase::ones(int size) template const Ones MatrixBase::ones() { - return Ones(Traits::RowsAtCompileTime, Traits::ColsAtCompileTime); + return Ones(RowsAtCompileTime, ColsAtCompileTime); } /** \returns true if *this is approximately equal to the matrix where all coefficients diff --git a/Eigen/src/Core/OperatorEquals.h b/Eigen/src/Core/OperatorEquals.h index ebad3fdfa..42d8ed9ee 100644 --- a/Eigen/src/Core/OperatorEquals.h +++ b/Eigen/src/Core/OperatorEquals.h @@ -30,8 +30,8 @@ template struct MatrixOperatorEqualsUnroller { enum { - col = (UnrollCount-1) / Derived1::Traits::RowsAtCompileTime, - row = (UnrollCount-1) % Derived1::Traits::RowsAtCompileTime + col = (UnrollCount-1) / Derived1::RowsAtCompileTime, + row = (UnrollCount-1) % Derived1::RowsAtCompileTime }; static void run(Derived1 &dst, const Derived2 &src) @@ -102,16 +102,16 @@ template Derived& MatrixBase ::operator=(const MatrixBase& other) { - if(Traits::IsVectorAtCompileTime && OtherDerived::Traits::IsVectorAtCompileTime) + if(IsVectorAtCompileTime && OtherDerived::IsVectorAtCompileTime) // copying a vector expression into a vector { assert(size() == other.size()); if(EIGEN_UNROLLED_LOOPS - && Traits::SizeAtCompileTime != Dynamic - && Traits::SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT_OPEQUAL) + && SizeAtCompileTime != Dynamic + && SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT_OPEQUAL) VectorOperatorEqualsUnroller ::run + SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT_OPEQUAL ? SizeAtCompileTime : Dynamic>::run (*static_cast(this), *static_cast(&other)); else for(int i = 0; i < size(); i++) @@ -122,17 +122,17 @@ Derived& MatrixBase { assert(rows() == other.rows() && cols() == other.cols()); if(EIGEN_UNROLLED_LOOPS - && Traits::SizeAtCompileTime != Dynamic - && Traits::SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT_OPEQUAL) + && SizeAtCompileTime != Dynamic + && SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT_OPEQUAL) { MatrixOperatorEqualsUnroller ::run + SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT_OPEQUAL ? SizeAtCompileTime : Dynamic>::run (*static_cast(this), *static_cast(&other)); } else { - if(Traits::ColsAtCompileTime == Dynamic || Traits::RowsAtCompileTime != Dynamic) + if(ColsAtCompileTime == Dynamic || RowsAtCompileTime != Dynamic) { // traverse in column-major order for(int j = 0; j < cols(); j++) diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 56ea4b338..f0f412025 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -1,4 +1,4 @@ -// // This file is part of Eigen, a lightweight C++ template library +// This file is part of Eigen, a lightweight C++ template library // for linear algebra. Eigen itself is part of the KDE project. // // Copyright (C) 2006-2008 Benoit Jacob @@ -73,19 +73,26 @@ struct ProductUnroller * \sa class Sum, class Difference */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename Lhs::Scalar Scalar; + enum { + RowsAtCompileTime = Lhs::RowsAtCompileTime, + ColsAtCompileTime = Rhs::ColsAtCompileTime, + MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime, + MaxColsAtCompileTime = Rhs::MaxColsAtCompileTime + }; +}; template class Product : NoOperatorEquals, public MatrixBase > { public: - typedef typename Scalar::Type Scalar; + + EIGEN_BASIC_PUBLIC_INTERFACE(Product) + typedef typename Lhs::AsArg LhsRef; typedef typename Rhs::AsArg RhsRef; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; Product(const LhsRef& lhs, const RhsRef& rhs) : m_lhs(lhs), m_rhs(rhs) @@ -94,12 +101,6 @@ template class Product : NoOperatorEquals, } private: - enum { - RowsAtCompileTime = Lhs::Traits::RowsAtCompileTime, - ColsAtCompileTime = Rhs::Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = Lhs::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = Rhs::Traits::MaxColsAtCompileTime - }; const Product& _asArg() const { return *this; } int _rows() const { return m_lhs.rows(); } @@ -109,10 +110,10 @@ template class Product : NoOperatorEquals, { Scalar res; if(EIGEN_UNROLLED_LOOPS - && Lhs::Traits::ColsAtCompileTime != Dynamic - && Lhs::Traits::ColsAtCompileTime <= EIGEN_UNROLLING_LIMIT_PRODUCT) - ProductUnroller ::run(row, col, m_lhs, m_rhs, res); else diff --git a/Eigen/src/Core/Random.h b/Eigen/src/Core/Random.h index 364b8f4ed..1c2154b43 100644 --- a/Eigen/src/Core/Random.h +++ b/Eigen/src/Core/Random.h @@ -33,25 +33,23 @@ * MatrixBase::setRandom() */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum { + RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + }; +}; template class Random : NoOperatorEquals, public MatrixBase > { public: - typedef typename MatrixType::Scalar Scalar; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; - private: - enum { - RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime - }; + EIGEN_BASIC_PUBLIC_INTERFACE(Random) const Random& _asArg() const { return *this; } int _rows() const { return m_rows.value(); } @@ -117,8 +115,8 @@ template const Eval > MatrixBase::random(int size) { - assert(Traits::IsVectorAtCompileTime); - if(Traits::RowsAtCompileTime == 1) return Random(1, size).eval(); + assert(IsVectorAtCompileTime); + if(RowsAtCompileTime == 1) return Random(1, size).eval(); else return Random(size, 1).eval(); } @@ -137,7 +135,7 @@ template const Eval > MatrixBase::random() { - return Random(Traits::RowsAtCompileTime, Traits::ColsAtCompileTime).eval(); + return Random(RowsAtCompileTime, ColsAtCompileTime).eval(); } /** Sets all coefficients in this expression to random values. diff --git a/Eigen/src/Core/Row.h b/Eigen/src/Core/Row.h index 3a50297d3..57a56852c 100644 --- a/Eigen/src/Core/Row.h +++ b/Eigen/src/Core/Row.h @@ -46,18 +46,25 @@ * \sa MatrixBase::row() */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum { + RowsAtCompileTime = 1, + ColsAtCompileTime = MatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = 1, + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + }; +}; template class Row : public MatrixBase > { public: - typedef typename Scalar::Type Scalar; + + EIGEN_BASIC_PUBLIC_INTERFACE(Row) + typedef typename MatrixType::AsArg MatRef; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; Row(const MatRef& matrix, int row) : m_matrix(matrix), m_row(row) @@ -68,12 +75,6 @@ template class Row EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Row) private: - enum { - RowsAtCompileTime = 1, - ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = 1, - MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime - }; const Row& _asArg() const { return *this; } diff --git a/Eigen/src/Core/Swap.h b/Eigen/src/Core/Swap.h index c7a1199fa..5bd16530e 100644 --- a/Eigen/src/Core/Swap.h +++ b/Eigen/src/Core/Swap.h @@ -30,12 +30,12 @@ template void MatrixBase::swap(const MatrixBase& other) { MatrixBase *_other = const_cast*>(&other); - if(Traits::SizeAtCompileTime == Dynamic) + if(SizeAtCompileTime == Dynamic) { Scalar tmp; - if(Traits::IsVectorAtCompileTime) + if(IsVectorAtCompileTime) { - assert(OtherDerived::Traits::IsVectorAtCompileTime && size() == _other->size()); + assert(OtherDerived::IsVectorAtCompileTime && size() == _other->size()); for(int i = 0; i < size(); i++) { tmp = coeff(i); diff --git a/Eigen/src/Core/Trace.h b/Eigen/src/Core/Trace.h index 728b4faf3..c106f0a9d 100644 --- a/Eigen/src/Core/Trace.h +++ b/Eigen/src/Core/Trace.h @@ -57,16 +57,16 @@ template struct TraceUnroller * * \sa diagonal() */ template -typename Scalar::Type +typename ei_traits::Scalar MatrixBase::trace() const { assert(rows() == cols()); Scalar res; if(EIGEN_UNROLLED_LOOPS - && Traits::RowsAtCompileTime != Dynamic - && Traits::RowsAtCompileTime <= EIGEN_UNROLLING_LIMIT_PRODUCT) - TraceUnroller + && RowsAtCompileTime != Dynamic + && RowsAtCompileTime <= EIGEN_UNROLLING_LIMIT_PRODUCT) + TraceUnroller ::run(*static_cast(this), res); else { diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 648b8b677..8f802818f 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -38,30 +38,31 @@ * \sa MatrixBase::transpose(), MatrixBase::adjoint() */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum { + RowsAtCompileTime = MatrixType::ColsAtCompileTime, + ColsAtCompileTime = MatrixType::RowsAtCompileTime, + MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime, + MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime + }; +}; template class Transpose : public MatrixBase > { public: - typedef typename Scalar::Type Scalar; + + EIGEN_BASIC_PUBLIC_INTERFACE(Transpose) + typedef typename MatrixType::AsArg MatRef; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; Transpose(const MatRef& matrix) : m_matrix(matrix) {} EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Transpose) private: - enum { - RowsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, - ColsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime, - MaxColsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime - }; const Transpose& _asArg() const { return *this; } int _rows() const { return m_matrix.cols(); } diff --git a/Eigen/src/Core/Util.h b/Eigen/src/Core/Util.h index aceb98d8a..5b93c3f78 100644 --- a/Eigen/src/Core/Util.h +++ b/Eigen/src/Core/Util.h @@ -84,18 +84,18 @@ using Eigen::MatrixBase; template \ Derived& operator Op(const MatrixBase& other) \ { \ - return Base::operator Op(other); \ + return MatrixBase::operator Op(other); \ } \ Derived& operator Op(const Derived& other) \ { \ - return Base::operator Op(other); \ + return MatrixBase::operator Op(other); \ } #define EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, Op) \ template \ Derived& operator Op(const Other& scalar) \ { \ - return Base::operator Op(scalar); \ + return MatrixBase::operator Op(scalar); \ } #define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \ @@ -105,6 +105,21 @@ EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, -=) \ EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, *=) \ EIGEN_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(Derived, /=) +#define _EIGEN_BASIC_PUBLIC_INTERFACE(Derived, BaseClass) \ +friend class MatrixBase; \ +typedef BaseClass Base; \ +typedef typename ei_traits::Scalar Scalar; \ +enum { RowsAtCompileTime = ei_traits::RowsAtCompileTime, \ + ColsAtCompileTime = ei_traits::ColsAtCompileTime, \ + MaxRowsAtCompileTime = ei_traits::MaxRowsAtCompileTime, \ + MaxColsAtCompileTime = ei_traits::MaxColsAtCompileTime }; \ +using Base::SizeAtCompileTime; \ +using Base::MaxSizeAtCompileTime; \ +using Base::IsVectorAtCompileTime; + +#define EIGEN_BASIC_PUBLIC_INTERFACE(Derived) \ +_EIGEN_BASIC_PUBLIC_INTERFACE(Derived, MatrixBase) + #define EIGEN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b) const int Dynamic = -10; diff --git a/Eigen/src/Core/Zero.h b/Eigen/src/Core/Zero.h index 92fb36edd..7848bb048 100644 --- a/Eigen/src/Core/Zero.h +++ b/Eigen/src/Core/Zero.h @@ -33,25 +33,25 @@ * MatrixBase::setZero(), MatrixBase::isZero() */ template -struct Scalar > -{ typedef typename Scalar::Type Type; }; +struct ei_traits > +{ + typedef typename MatrixType::Scalar Scalar; + enum { + RowsAtCompileTime = MatrixType::RowsAtCompileTime, + ColsAtCompileTime = MatrixType::ColsAtCompileTime, + MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, + MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime + }; +}; template class Zero : NoOperatorEquals, public MatrixBase > { public: - typedef typename Scalar::Type Scalar; - friend class MatrixBase; - friend class MatrixBase::Traits; - typedef MatrixBase Base; + + EIGEN_BASIC_PUBLIC_INTERFACE(Zero) private: - enum { - RowsAtCompileTime = MatrixType::Traits::RowsAtCompileTime, - ColsAtCompileTime = MatrixType::Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = MatrixType::Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = MatrixType::Traits::MaxColsAtCompileTime - }; const Zero& _asArg() const { return *this; } int _rows() const { return m_rows.value(); } @@ -63,6 +63,7 @@ template class Zero : NoOperatorEquals, } public: + Zero(int rows, int cols) : m_rows(rows), m_cols(cols) { assert(rows > 0 @@ -115,8 +116,8 @@ const Zero MatrixBase::zero(int rows, int cols) template const Zero MatrixBase::zero(int size) { - assert(Traits::IsVectorAtCompileTime); - if(Traits::RowsAtCompileTime == 1) return Zero(1, size); + assert(IsVectorAtCompileTime); + if(RowsAtCompileTime == 1) return Zero(1, size); else return Zero(size, 1); } @@ -133,7 +134,7 @@ const Zero MatrixBase::zero(int size) template const Zero MatrixBase::zero() { - return Zero(Traits::RowsAtCompileTime, Traits::ColsAtCompileTime); + return Zero(RowsAtCompileTime, ColsAtCompileTime); } /** \returns true if *this is approximately equal to the zero matrix, -- cgit v1.2.3