From 0c8b0e007b282139b4d3ab8e74f287c8e5109d69 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 19 Jun 2015 15:38:19 +0200 Subject: [PATCH] Introduce a AliasFreeProduct option for Permutations and Transpositions --- Eigen/src/Core/PermutationMatrix.h | 16 +++++----- Eigen/src/Core/Product.h | 2 +- Eigen/src/Core/ProductEvaluators.h | 37 +++++++++++++++--------- Eigen/src/Core/Transpositions.h | 16 +++++----- Eigen/src/Core/util/Constants.h | 2 +- Eigen/src/SparseCore/SparsePermutation.h | 8 ++--- 6 files changed, 46 insertions(+), 35 deletions(-) diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h index 8cf989f2c..bfe6f899a 100644 --- a/Eigen/src/Core/PermutationMatrix.h +++ b/Eigen/src/Core/PermutationMatrix.h @@ -541,11 +541,11 @@ class PermutationWrapper : public PermutationBase EIGEN_DEVICE_FUNC -const Product +const Product operator*(const MatrixBase &matrix, const PermutationBase& permutation) { - return Product + return Product (matrix.derived(), permutation.derived()); } @@ -553,11 +553,11 @@ operator*(const MatrixBase &matrix, */ template EIGEN_DEVICE_FUNC -const Product +const Product operator*(const PermutationBase &permutation, const MatrixBase& matrix) { - return Product + return Product (permutation.derived(), matrix.derived()); } @@ -620,19 +620,19 @@ class Transpose > /** \returns the matrix with the inverse permutation applied to the columns. */ template friend - const Product + const Product operator*(const MatrixBase& matrix, const Transpose& trPerm) { - return Product(matrix.derived(), trPerm.derived()); + return Product(matrix.derived(), trPerm.derived()); } /** \returns the matrix with the inverse permutation applied to the rows. */ template - const Product + const Product operator*(const MatrixBase& matrix) const { - return Product(*this, matrix.derived()); + return Product(*this, matrix.derived()); } const PermutationType& nestedExpression() const { return m_permutation; } diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h index 0739528f1..87340b88c 100644 --- a/Eigen/src/Core/Product.h +++ b/Eigen/src/Core/Product.h @@ -25,7 +25,7 @@ template class Pro * This class represents an expression of the product of two arbitrary matrices. * * The other template parameters are: - * \tparam Option can be DefaultProduct or LazyProduct + * \tparam Option can be DefaultProduct, AliasFreeProduct, or LazyProduct * */ diff --git a/Eigen/src/Core/ProductEvaluators.h b/Eigen/src/Core/ProductEvaluators.h index 5765857ce..c12ebb5a0 100644 --- a/Eigen/src/Core/ProductEvaluators.h +++ b/Eigen/src/Core/ProductEvaluators.h @@ -90,13 +90,21 @@ struct evaluator_traits > enum { AssumeAliasing = 1 }; }; +template +struct evaluator_traits > + : evaluator_traits_base > +{ + enum { AssumeAliasing = 0 }; +}; + // This is the default evaluator implementation for products: // It creates a temporary and call generic_product_impl -template -struct product_evaluator, ProductTag, LhsShape, RhsShape, typename traits::Scalar, typename traits::Scalar> - : public evaluator::PlainObject>::type +template +struct product_evaluator, ProductTag, LhsShape, RhsShape, typename traits::Scalar, + typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct),typename traits::Scalar>::type> + : public evaluator::PlainObject>::type { - typedef Product XprType; + typedef Product XprType; typedef typename XprType::PlainObject PlainObject; typedef typename evaluator::type Base; enum { @@ -128,10 +136,11 @@ protected: }; // Dense = Product -template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar> -struct Assignment, internal::assign_op, Dense2Dense, Scalar> +template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar> +struct Assignment, internal::assign_op, Dense2Dense, + typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct),Scalar>::type> { - typedef Product SrcXprType; + typedef Product SrcXprType; static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op &) { // FIXME shall we handle nested_eval here? @@ -140,10 +149,11 @@ struct Assignment, internal::assign_ }; // Dense += Product -template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar> -struct Assignment, internal::add_assign_op, Dense2Dense, Scalar> +template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar> +struct Assignment, internal::add_assign_op, Dense2Dense, + typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct),Scalar>::type> { - typedef Product SrcXprType; + typedef Product SrcXprType; static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op &) { // FIXME shall we handle nested_eval here? @@ -152,10 +162,11 @@ struct Assignment, internal::add_ass }; // Dense -= Product -template< typename DstXprType, typename Lhs, typename Rhs, typename Scalar> -struct Assignment, internal::sub_assign_op, Dense2Dense, Scalar> +template< typename DstXprType, typename Lhs, typename Rhs, int Options, typename Scalar> +struct Assignment, internal::sub_assign_op, Dense2Dense, + typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct),Scalar>::type> { - typedef Product SrcXprType; + typedef Product SrcXprType; static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op &) { // FIXME shall we handle nested_eval here? diff --git a/Eigen/src/Core/Transpositions.h b/Eigen/src/Core/Transpositions.h index 0296882f6..3b1c1815d 100644 --- a/Eigen/src/Core/Transpositions.h +++ b/Eigen/src/Core/Transpositions.h @@ -334,11 +334,11 @@ class TranspositionsWrapper */ template EIGEN_DEVICE_FUNC -const Product +const Product operator*(const MatrixBase &matrix, const TranspositionsBase& transpositions) { - return Product + return Product (matrix.derived(), transpositions.derived()); } @@ -346,11 +346,11 @@ operator*(const MatrixBase &matrix, */ template EIGEN_DEVICE_FUNC -const Product +const Product operator*(const TranspositionsBase &transpositions, const MatrixBase& matrix) { - return Product + return Product (transpositions.derived(), matrix.derived()); } @@ -381,19 +381,19 @@ class Transpose > /** \returns the \a matrix with the inverse transpositions applied to the columns. */ template friend - const Product + const Product operator*(const MatrixBase& matrix, const Transpose& trt) { - return Product(matrix.derived(), trt.derived()); + return Product(matrix.derived(), trt.derived()); } /** \returns the \a matrix with the inverse transpositions applied to the rows. */ template - const Product + const Product operator*(const MatrixBase& matrix) const { - return Product(*this, matrix.derived()); + return Product(*this, matrix.derived()); } const TranspositionType& nestedExpression() const { return m_transpositions; } diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h index 8d6089b2d..c5a0b0930 100644 --- a/Eigen/src/Core/util/Constants.h +++ b/Eigen/src/Core/util/Constants.h @@ -453,7 +453,7 @@ namespace Architecture /** \internal \ingroup enums * Enum used as template parameter in GeneralProduct. */ -enum { DefaultProduct=0, CoeffBasedProductMode, LazyCoeffBasedProductMode, LazyProduct, OuterProduct, InnerProduct, GemvProduct, GemmProduct }; +enum { DefaultProduct=0, LazyProduct, AliasFreeProduct, CoeffBasedProductMode, LazyCoeffBasedProductMode, OuterProduct, InnerProduct, GemvProduct, GemmProduct }; /** \internal \ingroup enums * Enum used in experimental parallel implementation. */ diff --git a/Eigen/src/SparseCore/SparsePermutation.h b/Eigen/src/SparseCore/SparsePermutation.h index b15128979..7b5eb4c22 100644 --- a/Eigen/src/SparseCore/SparsePermutation.h +++ b/Eigen/src/SparseCore/SparsePermutation.h @@ -90,10 +90,10 @@ template struct product_promote_storage_type >::PlainObject template -struct product_evaluator, ProductTag, PermutationShape, SparseShape, typename traits::Scalar, typename traits::Scalar> +struct product_evaluator, ProductTag, PermutationShape, SparseShape, typename traits::Scalar, typename traits::Scalar> : public evaluator::ReturnType>::type { - typedef Product XprType; + typedef Product XprType; typedef typename permutation_matrix_product::ReturnType PlainObject; typedef typename evaluator::type Base; @@ -109,10 +109,10 @@ protected: }; template -struct product_evaluator, ProductTag, SparseShape, PermutationShape, typename traits::Scalar, typename traits::Scalar> +struct product_evaluator, ProductTag, SparseShape, PermutationShape, typename traits::Scalar, typename traits::Scalar> : public evaluator::ReturnType>::type { - typedef Product XprType; + typedef Product XprType; typedef typename permutation_matrix_product::ReturnType PlainObject; typedef typename evaluator::type Base;