diff --git a/Eigen/Core b/Eigen/Core index 713d18a6d..7cf431320 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -382,8 +382,6 @@ using std::ptrdiff_t; #include "src/Core/DiagonalMatrix.h" #include "src/Core/Diagonal.h" #include "src/Core/DiagonalProduct.h" -#include "src/Core/PermutationMatrix.h" -#include "src/Core/Transpositions.h" #include "src/Core/Redux.h" #include "src/Core/Visitor.h" #include "src/Core/Fuzzy.h" @@ -393,6 +391,8 @@ using std::ptrdiff_t; #include "src/Core/GeneralProduct.h" #include "src/Core/Solve.h" #include "src/Core/Inverse.h" +#include "src/Core/PermutationMatrix.h" +#include "src/Core/Transpositions.h" #include "src/Core/TriangularMatrix.h" #include "src/Core/SelfAdjointView.h" #include "src/Core/products/GeneralBlockPanelKernel.h" diff --git a/Eigen/src/Core/Inverse.h b/Eigen/src/Core/Inverse.h index 8e6b275f7..8ba1a12d9 100644 --- a/Eigen/src/Core/Inverse.h +++ b/Eigen/src/Core/Inverse.h @@ -47,11 +47,12 @@ public: typedef typename XprType::PlainObject PlainObject; typedef typename internal::ref_selector::type XprTypeNested; typedef typename internal::remove_all::type XprTypeNestedCleaned; + typedef typename internal::ref_selector::type Nested; explicit Inverse(const XprType &xpr) : m_xpr(xpr) {} - + EIGEN_DEVICE_FUNC Index rows() const { return m_xpr.rows(); } EIGEN_DEVICE_FUNC Index cols() const { return m_xpr.cols(); } diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h index b5f7e4a54..90e1df233 100644 --- a/Eigen/src/Core/PermutationMatrix.h +++ b/Eigen/src/Core/PermutationMatrix.h @@ -2,7 +2,7 @@ // for linear algebra. // // Copyright (C) 2009 Benoit Jacob -// Copyright (C) 2009-2011 Gael Guennebaud +// Copyright (C) 2009-2015 Gael Guennebaud // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed @@ -13,9 +13,6 @@ namespace Eigen { -// TODO: this does not seems to be needed at all: -// template class PermutedImpl; - /** \class PermutationBase * \ingroup Core_Module * @@ -67,8 +64,9 @@ class PermutationBase : public EigenBase DenseMatrixType; typedef PermutationMatrix PlainPermutationType; + typedef PlainPermutationType PlainObject; using Base::derived; - typedef Transpose TransposeReturnType; + typedef Inverse InverseReturnType; typedef void Scalar; #endif @@ -196,14 +194,14 @@ class PermutationBase : public EigenBase * * \note \note_try_to_help_rvo */ - inline TransposeReturnType inverse() const - { return TransposeReturnType(derived()); } + inline InverseReturnType inverse() const + { return InverseReturnType(derived()); } /** \returns the tranpose permutation matrix. * * \note \note_try_to_help_rvo */ - inline TransposeReturnType transpose() const - { return TransposeReturnType(derived()); } + inline InverseReturnType transpose() const + { return InverseReturnType(derived()); } /**** multiplication helpers to hopefully get RVO ****/ @@ -238,7 +236,7 @@ class PermutationBase : public EigenBase * \note \note_try_to_help_rvo */ template - inline PlainPermutationType operator*(const Transpose >& other) const + inline PlainPermutationType operator*(const InverseImpl& other) const { return PlainPermutationType(internal::PermPermProduct, *this, other.eval()); } /** \returns the product of an inverse permutation with another permutation. @@ -246,7 +244,7 @@ class PermutationBase : public EigenBase * \note \note_try_to_help_rvo */ template friend - inline PlainPermutationType operator*(const Transpose >& other, const PermutationBase& perm) + inline PlainPermutationType operator*(const InverseImpl& other, const PermutationBase& perm) { return PlainPermutationType(internal::PermPermProduct, other.eval(), perm); } /** \returns the determinant of the permutation matrix, which is either 1 or -1 depending on the parity of the permutation. @@ -398,13 +396,13 @@ class PermutationMatrix : public PermutationBase - PermutationMatrix(const Transpose >& other) - : m_indices(other.nestedExpression().size()) + PermutationMatrix(const InverseImpl& other) + : m_indices(other.derived().nestedExpression().size()) { eigen_internal_assert(m_indices.size() <= NumTraits::highest()); StorageIndex end = StorageIndex(m_indices.size()); for (StorageIndex i=0; i PermutationMatrix(internal::PermPermProduct_t, const Lhs& lhs, const Rhs& rhs) @@ -564,84 +562,61 @@ operator*(const PermutationBase &permutation, (permutation.derived(), matrix.derived()); } -namespace internal { -/* Template partial specialization for transposed/inverse permutations */ - -template -struct traits > > - : traits -{}; - -} // end namespace internal - -// TODO: the specificties should be handled by the evaluator, -// at the very least we should only specialize TransposeImpl -template -class Transpose > - : public EigenBase > > +template +class InverseImpl + : public EigenBase > { - typedef Derived PermutationType; - typedef typename PermutationType::IndicesType IndicesType; typedef typename PermutationType::PlainPermutationType PlainPermutationType; + typedef internal::traits PermTraits; + protected: + InverseImpl() {} public: + typedef Inverse InverseType; + using EigenBase >::derived; #ifndef EIGEN_PARSED_BY_DOXYGEN - typedef internal::traits Traits; - typedef typename Derived::DenseMatrixType DenseMatrixType; + typedef typename PermutationType::DenseMatrixType DenseMatrixType; enum { - Flags = Traits::Flags, - RowsAtCompileTime = Traits::RowsAtCompileTime, - ColsAtCompileTime = Traits::ColsAtCompileTime, - MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime, - MaxColsAtCompileTime = Traits::MaxColsAtCompileTime + RowsAtCompileTime = PermTraits::RowsAtCompileTime, + ColsAtCompileTime = PermTraits::ColsAtCompileTime, + MaxRowsAtCompileTime = PermTraits::MaxRowsAtCompileTime, + MaxColsAtCompileTime = PermTraits::MaxColsAtCompileTime }; - typedef typename Traits::Scalar Scalar; - typedef typename Traits::StorageIndex StorageIndex; #endif - Transpose(const PermutationType& p) : m_permutation(p) {} - - inline Index rows() const { return m_permutation.rows(); } - inline Index cols() const { return m_permutation.cols(); } - #ifndef EIGEN_PARSED_BY_DOXYGEN template void evalTo(MatrixBase& other) const { other.setZero(); - for (Index i=0; i friend - const Product - operator*(const MatrixBase& matrix, const Transpose& trPerm) + const Product + operator*(const MatrixBase& matrix, const InverseType& 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(derived(), matrix.derived()); } - - const PermutationType& nestedExpression() const { return m_permutation; } - - protected: - const PermutationType& m_permutation; }; template diff --git a/Eigen/src/Core/ProductEvaluators.h b/Eigen/src/Core/ProductEvaluators.h index c2a7314bd..7dea15a30 100755 --- a/Eigen/src/Core/ProductEvaluators.h +++ b/Eigen/src/Core/ProductEvaluators.h @@ -908,20 +908,20 @@ struct generic_product_impl }; template -struct generic_product_impl, Rhs, PermutationShape, MatrixShape, ProductTag> +struct generic_product_impl, Rhs, PermutationShape, MatrixShape, ProductTag> { template - static void evalTo(Dest& dst, const Transpose& lhs, const Rhs& rhs) + static void evalTo(Dest& dst, const Inverse& lhs, const Rhs& rhs) { permutation_matrix_product::run(dst, lhs.nestedExpression(), rhs); } }; template -struct generic_product_impl, MatrixShape, PermutationShape, ProductTag> +struct generic_product_impl, MatrixShape, PermutationShape, ProductTag> { template - static void evalTo(Dest& dst, const Lhs& lhs, const Transpose& rhs) + static void evalTo(Dest& dst, const Lhs& lhs, const Inverse& rhs) { permutation_matrix_product::run(dst, rhs.nestedExpression(), lhs); } diff --git a/Eigen/src/SparseCore/SparsePermutation.h b/Eigen/src/SparseCore/SparsePermutation.h index d63607b6c..3c58e3b4f 100644 --- a/Eigen/src/SparseCore/SparsePermutation.h +++ b/Eigen/src/SparseCore/SparsePermutation.h @@ -144,23 +144,22 @@ operator*( const PermutationBase& perm, const SparseMatrixBase(perm.derived(), matrix.derived()); } -// TODO, the following specializations should not be needed as Transpose should be a PermutationBase. /** \returns the matrix with the inverse permutation applied to the columns. */ -template -inline const Product > > -operator*(const SparseMatrixBase& matrix, const Transpose >& tperm) +template +inline const Product > +operator*(const SparseMatrixBase& matrix, const InverseImpl& tperm) { - return Product > >(matrix.derived(), tperm); + return Product >(matrix.derived(), tperm.derived()); } /** \returns the matrix with the inverse permutation applied to the rows. */ -template -inline const Product >, SparseDerived> -operator*(const Transpose >& tperm, const SparseMatrixBase& matrix) +template +inline const Product, SparseDerived> +operator*(const InverseImpl& tperm, const SparseMatrixBase& matrix) { - return Product >, SparseDerived>(tperm, matrix.derived()); + return Product, SparseDerived>(tperm.derived(), matrix.derived()); } } // end namespace Eigen