From b25eb5fdaade6c20457a411fd08e17acc54f3349 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 16 Nov 2009 09:39:07 -0500 Subject: [PATCH] PermutationMatrix: add inverse() and product of permutations --- Eigen/src/Core/PermutationMatrix.h | 30 +++++++++++++++++++++++++++--- test/permutationmatrices.cpp | 9 +++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h index aaccb4e7b..1c66cde8e 100644 --- a/Eigen/src/Core/PermutationMatrix.h +++ b/Eigen/src/Core/PermutationMatrix.h @@ -105,10 +105,10 @@ class PermutationMatrix : public AnyMatrixBase @@ -126,7 +126,31 @@ class PermutationMatrix : public AnyMatrixBase + inline PermutationMatrix operator*(const PermutationMatrix& other) const + { return PermutationMatrix(Product, *this, other); } + protected: IndicesType m_indices; diff --git a/test/permutationmatrices.cpp b/test/permutationmatrices.cpp index 13b01cd83..ec3a8541c 100644 --- a/test/permutationmatrices.cpp +++ b/test/permutationmatrices.cpp @@ -72,6 +72,15 @@ template void permutationmatrices(const MatrixType& m) Matrix rm(rp); VERIFY_IS_APPROX(m_permuted, lm*m_original*rm); + + VERIFY_IS_APPROX(lp.inverse()*m_permuted*rp.inverse(), m_original); + VERIFY((lp*lp.inverse()).toDenseMatrix().isIdentity()); + + LeftPermutationVectorType lv2; + randomPermutationVector(lv2, rows); + LeftPermutationType lp2(lv2); + Matrix lm2(lp2); + VERIFY_IS_APPROX((lp*lp2).toDenseMatrix().template cast(), lm2*lm); } void test_permutationmatrices()