From 3af4c6c1c9327411d13386e4719ce48f866c7567 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 19 Jun 2015 11:50:24 +0200 Subject: Make Transpositions use evaluators --- Eigen/src/Core/Transpositions.h | 127 +++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 73 deletions(-) (limited to 'Eigen/src/Core/Transpositions.h') diff --git a/Eigen/src/Core/Transpositions.h b/Eigen/src/Core/Transpositions.h index b08df1ead..dad4f56c9 100644 --- a/Eigen/src/Core/Transpositions.h +++ b/Eigen/src/Core/Transpositions.h @@ -41,10 +41,6 @@ namespace Eigen { * \sa class PermutationMatrix */ -namespace internal { -template struct transposition_matrix_product_retval; -} - template class TranspositionsBase { @@ -325,77 +321,32 @@ class TranspositionsWrapper const typename IndicesType::Nested m_indices; }; + + /** \returns the \a matrix with the \a transpositions applied to the columns. */ -template -inline const internal::transposition_matrix_product_retval -operator*(const MatrixBase& matrix, - const TranspositionsBase &transpositions) +template +EIGEN_DEVICE_FUNC +const Product +operator*(const MatrixBase &matrix, + const TranspositionsBase& transpositions) { - return internal::transposition_matrix_product_retval - - (transpositions.derived(), matrix.derived()); + return Product + (matrix.derived(), transpositions.derived()); } /** \returns the \a matrix with the \a transpositions applied to the rows. */ -template -inline const internal::transposition_matrix_product_retval - -operator*(const TranspositionsBase &transpositions, - const MatrixBase& matrix) +template +EIGEN_DEVICE_FUNC +const Product +operator*(const TranspositionsBase &transpositions, + const MatrixBase& matrix) { - return internal::transposition_matrix_product_retval - - (transpositions.derived(), matrix.derived()); + return Product + (transpositions.derived(), matrix.derived()); } -namespace internal { - -template -struct traits > -{ - typedef typename MatrixType::PlainObject ReturnType; -}; - -template -struct transposition_matrix_product_retval - : public ReturnByValue > -{ - typedef typename remove_all::type MatrixTypeNestedCleaned; - typedef typename TranspositionType::StorageIndex StorageIndex; - - transposition_matrix_product_retval(const TranspositionType& tr, const MatrixType& matrix) - : m_transpositions(tr), m_matrix(matrix) - {} - - inline Index rows() const { return m_matrix.rows(); } - inline Index cols() const { return m_matrix.cols(); } - - template inline void evalTo(Dest& dst) const - { - const Index size = m_transpositions.size(); - StorageIndex j = 0; - - if(!(is_same::value && extract_data(dst) == extract_data(m_matrix))) - dst = m_matrix; - - for(Index k=(Transposed?size-1:0) ; Transposed?k>=0:k > /** \returns the \a matrix with the inverse transpositions applied to the columns. */ - template friend - inline const internal::transposition_matrix_product_retval - operator*(const MatrixBase& matrix, const Transpose& trt) + template friend + const Product + operator*(const MatrixBase& matrix, const Transpose& trt) { - return internal::transposition_matrix_product_retval(trt.m_transpositions, matrix.derived()); + return Product(matrix.derived(), trt.derived()); } /** \returns the \a matrix with the inverse transpositions applied to the rows. */ - template - inline const internal::transposition_matrix_product_retval - operator*(const MatrixBase& matrix) const + template + const Product + operator*(const MatrixBase& matrix) const { - return internal::transposition_matrix_product_retval(m_transpositions, matrix.derived()); + return Product(*this, matrix.derived()); } protected: const TranspositionType& m_transpositions; }; +namespace internal { + +// TODO currently a Transpositions expression has the form Transpositions or TranspositionsWrapper +// or their transpose; in the future shape should be defined by the expression traits +template +struct evaluator_traits > +{ + typedef typename storage_kind_to_evaluator_kind::Kind Kind; + typedef TranspositionsShape Shape; + static const int AssumeAliasing = 0; +}; + +template +struct evaluator_traits > +{ + typedef typename storage_kind_to_evaluator_kind::Kind Kind; + typedef TranspositionsShape Shape; + static const int AssumeAliasing = 0; +}; + +template +struct evaluator_traits > > +{ + typedef typename storage_kind_to_evaluator_kind::Kind Kind; + typedef TranspositionsShape Shape; + static const int AssumeAliasing = 0; +}; + +} // end namespace internal + } // end namespace Eigen #endif // EIGEN_TRANSPOSITIONS_H -- cgit v1.2.3