From a4a2671fd0b8429a0e4a4a19f28e1f7befb85df8 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Sat, 13 Feb 2010 22:38:27 +0000 Subject: Refactor matrix_function test in preparation of next commit. --- unsupported/test/matrix_function.cpp | 43 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'unsupported/test/matrix_function.cpp') diff --git a/unsupported/test/matrix_function.cpp b/unsupported/test/matrix_function.cpp index 446fa7ec3..d1f5824d8 100644 --- a/unsupported/test/matrix_function.cpp +++ b/unsupported/test/matrix_function.cpp @@ -25,28 +25,19 @@ #include "main.h" #include -// Returns either a matrix with iid random entries or a matrix with -// clustered eigenvalues. Matrices with clustered eigenvalue clusters -// lead to different code paths in MatrixFunction.h and are thus -// useful for testing. +// Returns a matrix with eigenvalues clustered around 0, 1 and 2. template -MatrixType createRandomMatrix(const int size) +MatrixType randomMatrixWithRealEivals(const int size) { typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::RealScalar RealScalar; - MatrixType result; - if (ei_random(0,1) == 0) { - result = MatrixType::Random(size, size); - } else { - MatrixType diag = MatrixType::Zero(size, size); - for (int i = 0; i < size; ++i) { - diag(i, i) = Scalar(RealScalar(ei_random(0,2))) - + ei_random() * Scalar(RealScalar(0.01)); - } - MatrixType A = MatrixType::Random(size, size); - result = A.inverse() * diag * A; + MatrixType diag = MatrixType::Zero(size, size); + for (int i = 0; i < size; ++i) { + diag(i, i) = Scalar(RealScalar(ei_random(0,2))) + + ei_random() * Scalar(RealScalar(0.01)); } - return result; + MatrixType A = MatrixType::Random(size, size); + return A.inverse() * diag * A; } template @@ -108,14 +99,24 @@ void testGonioFunctions(const MatrixType& A) } } +template +void testMatrix(const MatrixType& A) +{ + testMatrixExponential(A); + testHyperbolicFunctions(A); + testGonioFunctions(A); +} + template void testMatrixType(const MatrixType& m) { + // Matrices with clustered eigenvalue lead to different code paths + // in MatrixFunction.h and are thus useful for testing. + + const int size = m.rows(); for (int i = 0; i < g_repeat; i++) { - MatrixType A = createRandomMatrix(m.rows()); - testMatrixExponential(A); - testHyperbolicFunctions(A); - testGonioFunctions(A); + testMatrix(MatrixType::Random(size, size).eval()); + testMatrix(randomMatrixWithRealEivals(size)); } } -- cgit v1.2.3