From c1c780a94f148c618a74cfcccf40037442ae2d7c Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Tue, 22 Sep 2009 12:20:45 -0400 Subject: * ReturnByValue: -- simpplify by removing the 2nd template parameter -- rename Functor to Derived, as now it's a usual CRTP * Homogeneous: -- in products, honor the Max sizes etc. --- Eigen/src/Core/Matrix.h | 8 +++---- Eigen/src/Core/MatrixBase.h | 4 ++-- Eigen/src/Core/ReturnByValue.h | 38 ++++++++++++------------------- Eigen/src/Core/util/ForwardDeclarations.h | 2 +- Eigen/src/Geometry/Homogeneous.h | 30 +++++++++++++++++++----- Eigen/src/Geometry/Transform.h | 8 +++---- 6 files changed, 50 insertions(+), 40 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index c08f12491..aea0f15c8 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -399,8 +399,8 @@ class Matrix return Base::lazyAssign(other.derived()); } - template - EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue& func) + template + EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue& func) { resize(func.rows(), func.cols()); return Base::operator=(func); @@ -504,8 +504,8 @@ class Matrix _set_noalias(other); } /** Copy constructor with in-place evaluation */ - template - EIGEN_STRONG_INLINE Matrix(const ReturnByValue& other) + template + EIGEN_STRONG_INLINE Matrix(const ReturnByValue& other) { _check_template_params(); resize(other.rows(), other.cols()); diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 4835f167c..a1659e2a7 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -271,8 +271,8 @@ template class MatrixBase template Derived& operator-=(const AnyMatrixBase &other); - template - Derived& operator=(const ReturnByValue& func); + template + Derived& operator=(const ReturnByValue& func); #ifndef EIGEN_PARSED_BY_DOXYGEN /** Copies \a other into *this without evaluating other. \returns a reference to *this. */ diff --git a/Eigen/src/Core/ReturnByValue.h b/Eigen/src/Core/ReturnByValue.h index 3f2b478ff..4a5d5c105 100644 --- a/Eigen/src/Core/ReturnByValue.h +++ b/Eigen/src/Core/ReturnByValue.h @@ -28,45 +28,37 @@ /** \class ReturnByValue * */ -template -struct ei_traits > > - : public ei_traits > +template +struct ei_traits > + : public ei_traits::ReturnMatrixType> { enum { - Flags = ei_traits >::Flags | EvalBeforeNestingBit + Flags = ei_traits::ReturnMatrixType>::Flags | EvalBeforeNestingBit }; }; -template -struct ei_nested >, n, EvalTypeDerived> -{ - typedef EvalTypeDerived type; -}; - -template class ReturnByValue +template +struct ei_nested, n, PlainMatrixType> { - public: - template inline void evalTo(Dest& dst) const - { static_cast(this)->evalTo(dst); } + typedef typename ei_traits::ReturnMatrixType type; }; -template - class ReturnByValue > - : public MatrixBase > > +template + class ReturnByValue : public MatrixBase > { - typedef Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> EvalType; + typedef typename ei_traits::ReturnMatrixType ReturnMatrixType; public: EIGEN_GENERIC_PUBLIC_INTERFACE(ReturnByValue) template inline void evalTo(Dest& dst) const - { static_cast(this)->evalTo(dst); } - inline int rows() const { return static_cast(this)->rows(); } - inline int cols() const { return static_cast(this)->cols(); } + { static_cast(this)->evalTo(dst); } + inline int rows() const { return static_cast(this)->rows(); } + inline int cols() const { return static_cast(this)->cols(); } }; template -template -Derived& MatrixBase::operator=(const ReturnByValue& other) +template +Derived& MatrixBase::operator=(const ReturnByValue& other) { other.evalTo(derived()); return derived(); diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 3f66738f0..65e5ce687 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -64,7 +64,7 @@ template class SelfAdjointView; template class Cwise; template class WithFormat; template struct CommaInitializer; -template class ReturnByValue; +template class ReturnByValue; template class BandMatrix; diff --git a/Eigen/src/Geometry/Homogeneous.h b/Eigen/src/Geometry/Homogeneous.h index 2de99b5de..035d213b7 100644 --- a/Eigen/src/Geometry/Homogeneous.h +++ b/Eigen/src/Geometry/Homogeneous.h @@ -206,11 +206,20 @@ VectorwiseOp::hnormalized() const Direction==Horizontal ? _expression().cols()-1 : 1).nestByValue(); } +template +struct ei_traits,Lhs> > +{ + typedef Matrix::Scalar, + Lhs::RowsAtCompileTime, + MatrixType::ColsAtCompileTime, + MatrixType::PlainMatrixType::Options, + Lhs::MaxRowsAtCompileTime, + MatrixType::MaxColsAtCompileTime> ReturnMatrixType; +}; + template struct ei_homogeneous_left_product_impl,Lhs> - : public ReturnByValue,Lhs>, - Matrix::Scalar, - Lhs::RowsAtCompileTime,MatrixType::ColsAtCompileTime> > + : public ReturnByValue,Lhs> > { typedef typename ei_cleantype::type LhsNested; ei_homogeneous_left_product_impl(const Lhs& lhs, const MatrixType& rhs) @@ -235,11 +244,20 @@ struct ei_homogeneous_left_product_impl,Lhs> const typename MatrixType::Nested m_rhs; }; +template +struct ei_traits,Rhs> > +{ + typedef Matrix::Scalar, + MatrixType::RowsAtCompileTime, + Rhs::ColsAtCompileTime, + MatrixType::PlainMatrixType::Options, + MatrixType::MaxRowsAtCompileTime, + Rhs::MaxColsAtCompileTime> ReturnMatrixType; +}; + template struct ei_homogeneous_right_product_impl,Rhs> - : public ReturnByValue,Rhs>, - Matrix::Scalar, - MatrixType::RowsAtCompileTime, Rhs::ColsAtCompileTime> > + : public ReturnByValue,Rhs> > { typedef typename ei_cleantype::type RhsNested; ei_homogeneous_right_product_impl(const MatrixType& lhs, const Rhs& rhs) diff --git a/Eigen/src/Geometry/Transform.h b/Eigen/src/Geometry/Transform.h index e89581e21..d03fd52fd 100644 --- a/Eigen/src/Geometry/Transform.h +++ b/Eigen/src/Geometry/Transform.h @@ -247,14 +247,14 @@ public: ei_transform_construct_from_matrix::run(this, other.matrix()); } - template - Transform(const ReturnByValue& other) + template + Transform(const ReturnByValue& other) { other.evalTo(*this); } - template - Transform& operator=(const ReturnByValue& other) + template + Transform& operator=(const ReturnByValue& other) { other.evalTo(*this); return *this; -- cgit v1.2.3