add a unit test for permutation applied to sparse objects

This commit is contained in:
Gael Guennebaud
2011-10-11 13:45:27 +02:00
parent 3172749f32
commit cd3c2451b6
4 changed files with 155 additions and 17 deletions

View File

@@ -355,6 +355,23 @@ void createRandomPIMatrixOfRank(typename MatrixType::Index desired_rank, typenam
m = qra.householderQ() * d * qrb.householderQ();
}
template<typename PermutationVectorType>
void randomPermutationVector(PermutationVectorType& v, typename PermutationVectorType::Index size)
{
typedef typename PermutationVectorType::Index Index;
typedef typename PermutationVectorType::Scalar Scalar;
v.resize(size);
for(Index i = 0; i < size; ++i) v(i) = Scalar(i);
if(size == 1) return;
for(Index n = 0; n < 3 * size; ++n)
{
Index i = internal::random<Index>(0, size-1);
Index j;
do j = internal::random<Index>(0, size-1); while(j==i);
std::swap(v(i), v(j));
}
}
} // end namespace Eigen
template<typename T> struct GetDifferentType;