aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/permutationmatrices.cpp
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2011-01-26 16:33:23 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2011-01-26 16:33:23 +0100
commit15ef62ca43c2e08c1e2fefb751b994441e019376 (patch)
tree85b8e86cedb33e44f259275a814ec983d802b855 /test/permutationmatrices.cpp
parent84448b058c1611a0eae45212007d02a0c5457f5c (diff)
extend PermutationMatrix and Transpositions to support arbitrary interger types and to support the Map/Wrapper model via base and derived classes
Diffstat (limited to 'test/permutationmatrices.cpp')
-rw-r--r--test/permutationmatrices.cpp11
1 files changed, 10 insertions, 1 deletions
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<typename MatrixType> void permutationmatrices(const MatrixType& m)
Options = MatrixType::Options };
typedef PermutationMatrix<Rows> LeftPermutationType;
typedef Matrix<int, Rows, 1> LeftPermutationVectorType;
+ typedef Map<LeftPermutationType> MapLeftPerm;
typedef PermutationMatrix<Cols> RightPermutationType;
typedef Matrix<int, Cols, 1> RightPermutationVectorType;
+ typedef Map<RightPermutationType> MapRightPerm;
Index rows = m.rows();
Index cols = m.cols();
@@ -76,13 +78,20 @@ template<typename MatrixType> 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<Scalar,Rows,Rows> lm2(lp2);
VERIFY_IS_APPROX((lp*lp2).toDenseMatrix().template cast<Scalar>(), lm*lm2);
+ VERIFY_IS_APPROX((lv.asPermutation()*lv2.asPermutation()).toDenseMatrix().template cast<Scalar>(), lm*lm2);
+ VERIFY_IS_APPROX((MapLeftPerm(lv.data(),lv.size())*MapLeftPerm(lv2.data(),lv2.size())).toDenseMatrix().template cast<Scalar>(), lm*lm2);
LeftPermutationType identityp;
identityp.setIdentity(rows);
@@ -123,7 +132,7 @@ template<typename MatrixType> void permutationmatrices(const MatrixType& m)
rm = rp;
rm.col(i).swap(rm.col(j));
VERIFY_IS_APPROX(rm, rp2.toDenseMatrix().template cast<Scalar>());
- }
+ }
}
void test_permutationmatrices()