From 15ef62ca43c2e08c1e2fefb751b994441e019376 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 26 Jan 2011 16:33:23 +0100 Subject: extend PermutationMatrix and Transpositions to support arbitrary interger types and to support the Map/Wrapper model via base and derived classes --- test/permutationmatrices.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'test/permutationmatrices.cpp') diff --git a/test/permutationmatrices.cpp b/test/permutationmatrices.cpp index b9b3bbbca..d0fa01310 100644 --- a/test/permutationmatrices.cpp +++ b/test/permutationmatrices.cpp @@ -51,8 +51,10 @@ template void permutationmatrices(const MatrixType& m) Options = MatrixType::Options }; typedef PermutationMatrix LeftPermutationType; typedef Matrix LeftPermutationVectorType; + typedef Map MapLeftPerm; typedef PermutationMatrix RightPermutationType; typedef Matrix RightPermutationVectorType; + typedef Map MapRightPerm; Index rows = m.rows(); Index cols = m.cols(); @@ -76,13 +78,20 @@ template void permutationmatrices(const MatrixType& m) VERIFY_IS_APPROX(m_permuted, lm*m_original*rm); VERIFY_IS_APPROX(lp.inverse()*m_permuted*rp.inverse(), m_original); + VERIFY_IS_APPROX(lv.asPermutation().inverse()*m_permuted*rv.asPermutation().inverse(), m_original); + VERIFY_IS_APPROX(MapLeftPerm(lv.data(),lv.size()).inverse()*m_permuted*MapRightPerm(rv.data(),rv.size()).inverse(), m_original); + VERIFY((lp*lp.inverse()).toDenseMatrix().isIdentity()); + VERIFY((lv.asPermutation()*lv.asPermutation().inverse()).toDenseMatrix().isIdentity()); + VERIFY((MapLeftPerm(lv.data(),lv.size())*MapLeftPerm(lv.data(),lv.size()).inverse()).toDenseMatrix().isIdentity()); LeftPermutationVectorType lv2; randomPermutationVector(lv2, rows); LeftPermutationType lp2(lv2); Matrix lm2(lp2); VERIFY_IS_APPROX((lp*lp2).toDenseMatrix().template cast(), lm*lm2); + VERIFY_IS_APPROX((lv.asPermutation()*lv2.asPermutation()).toDenseMatrix().template cast(), lm*lm2); + VERIFY_IS_APPROX((MapLeftPerm(lv.data(),lv.size())*MapLeftPerm(lv2.data(),lv2.size())).toDenseMatrix().template cast(), lm*lm2); LeftPermutationType identityp; identityp.setIdentity(rows); @@ -123,7 +132,7 @@ template void permutationmatrices(const MatrixType& m) rm = rp; rm.col(i).swap(rm.col(j)); VERIFY_IS_APPROX(rm, rp2.toDenseMatrix().template cast()); - } + } } void test_permutationmatrices() -- cgit v1.2.3