diff --git a/Eigen/src/Core/GeneralProduct.h b/Eigen/src/Core/GeneralProduct.h index 675f6ee8d..f823ff251 100644 --- a/Eigen/src/Core/GeneralProduct.h +++ b/Eigen/src/Core/GeneralProduct.h @@ -82,7 +82,8 @@ private: public: enum { - value = selector::ret + value = selector::ret, + ret = selector::ret }; #ifdef EIGEN_DEBUG_PRODUCT static void debug() @@ -98,31 +99,31 @@ public: #endif }; -template struct product_tag -{ -private: - - typedef typename remove_all::type _Lhs; - typedef typename remove_all::type _Rhs; - enum { - Rows = _Lhs::RowsAtCompileTime, - Cols = _Rhs::ColsAtCompileTime, - Depth = EIGEN_SIZE_MIN_PREFER_FIXED(_Lhs::ColsAtCompileTime, _Rhs::RowsAtCompileTime) - }; - - enum { - rows_select = Rows==1 ? int(Rows) : int(Large), - cols_select = Cols==1 ? int(Cols) : int(Large), - depth_select = Depth==1 ? int(Depth) : int(Large) - }; - typedef product_type_selector selector; - -public: - enum { - ret = selector::ret - }; - -}; +// template struct product_tag +// { +// private: +// +// typedef typename remove_all::type _Lhs; +// typedef typename remove_all::type _Rhs; +// enum { +// Rows = _Lhs::RowsAtCompileTime, +// Cols = _Rhs::ColsAtCompileTime, +// Depth = EIGEN_SIZE_MIN_PREFER_FIXED(_Lhs::ColsAtCompileTime, _Rhs::RowsAtCompileTime) +// }; +// +// enum { +// rows_select = Rows==1 ? int(Rows) : int(Large), +// cols_select = Cols==1 ? int(Cols) : int(Large), +// depth_select = Depth==1 ? int(Depth) : int(Large) +// }; +// typedef product_type_selector selector; +// +// public: +// enum { +// ret = selector::ret +// }; +// +// }; /* The following allows to select the kind of product at compile time * based on the three dimensions of the product. diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 79d09fbb6..d64fbae35 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -88,7 +88,7 @@ class Product : public ProductImpl<_Lhs,_Rhs,Option, namespace internal { -template::ret> +template::ret> class dense_product_base : public internal::dense_xpr_base >::type {}; diff --git a/Eigen/src/Core/ProductEvaluators.h b/Eigen/src/Core/ProductEvaluators.h index f0eb57d67..46048882b 100644 --- a/Eigen/src/Core/ProductEvaluators.h +++ b/Eigen/src/Core/ProductEvaluators.h @@ -19,7 +19,7 @@ namespace internal { // Like more general binary expressions, products need their own evaluator: template< typename T, - int ProductTag = internal::product_tag::ret, + int ProductTag = internal::product_type::ret, typename LhsShape = typename evaluator_traits::Shape, typename RhsShape = typename evaluator_traits::Shape, typename LhsScalar = typename T::Lhs::Scalar, @@ -38,7 +38,43 @@ struct evaluator > evaluator(const XprType& xpr) : Base(xpr) {} }; + +// Catch scalar * ( A * B ) and transform it to (A*scalar) * B +// TODO we should apply that rule if that's really helpful +template +struct evaluator, const Product > > + : public evaluator,const Lhs>, Rhs, DefaultProduct> > +{ + typedef CwiseUnaryOp, const Product > XprType; + typedef evaluator,const Lhs>, Rhs, DefaultProduct> > Base; + typedef evaluator type; + typedef evaluator nestedType; + + evaluator(const XprType& xpr) + : Base(xpr.functor().m_other * xpr.nestedExpression().lhs() * xpr.nestedExpression().rhs()) + {} +}; + + +template +struct evaluator, DiagIndex> > + : public evaluator, DiagIndex> > +{ + typedef Diagonal, DiagIndex> XprType; + typedef evaluator, DiagIndex> > Base; + + typedef evaluator type; + typedef evaluator nestedType; +// + evaluator(const XprType& xpr) + : Base(Diagonal, DiagIndex>( + Product(xpr.nestedExpression().lhs(), xpr.nestedExpression().rhs()), + xpr.index() )) + {} +}; + + // Helper class to perform a matrix product with the destination at hand. // Depending on the sizes of the factors, there are different evaluation strategies // as controlled by internal::product_type. @@ -108,6 +144,23 @@ struct Assignment, internal::sub_ass } }; + +// Dense ?= scalar * Product +// TODO we should apply that rule if that's really helpful +// for instance, this is not good for inner products +template< typename DstXprType, typename Lhs, typename Rhs, typename AssignFunc, typename Scalar, typename ScalarBis> +struct Assignment, + const Product >, AssignFunc, Dense2Dense, Scalar> +{ + typedef CwiseUnaryOp, + const Product > SrcXprType; + static void run(DstXprType &dst, const SrcXprType &src, const AssignFunc& func) + { + call_assignment(dst.noalias(), (src.functor().m_other * src.nestedExpression().lhs()) * src.nestedExpression().rhs(), func); + } +}; + + template struct generic_product_impl { @@ -255,9 +308,9 @@ struct generic_product_impl }; // This specialization enforces the use of a coefficient-based evaluation strategy -template -struct generic_product_impl - : generic_product_impl {}; +// template +// struct generic_product_impl +// : generic_product_impl {}; // Case 2: Evaluate coeff by coeff // @@ -347,6 +400,17 @@ protected: Index m_innerDim; }; +template +struct product_evaluator, LazyCoeffBasedProductMode, DenseShape, DenseShape, typename Lhs::Scalar, typename Rhs::Scalar > + : product_evaluator, CoeffBasedProductMode, DenseShape, DenseShape, typename Lhs::Scalar, typename Rhs::Scalar > +{ + typedef Product XprType; + typedef Product BaseProduct; + typedef product_evaluator Base; + product_evaluator(const XprType& xpr) + : Base(BaseProduct(xpr.lhs(),xpr.rhs())) + {} +}; /*************************************************************************** * Normal product .coeff() implementation (with meta-unrolling) diff --git a/Eigen/src/Core/SelfAdjointView.h b/Eigen/src/Core/SelfAdjointView.h index 079b987f8..a5c6d5ceb 100644 --- a/Eigen/src/Core/SelfAdjointView.h +++ b/Eigen/src/Core/SelfAdjointView.h @@ -336,6 +336,7 @@ struct triangular_assignment_selector // in the future selfadjoint-ness should be defined by the expression traits // such that Transpose > is valid. (currently TriangularBase::transpose() is overloaded to make it work) @@ -347,6 +348,7 @@ struct evaluator_traits > static const int AssumeAliasing = 0; }; +#endif // EIGEN_ENABLE_EVALUATORS } // end namespace internal