mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
Refactor matrix_function test in preparation of next commit.
This commit is contained in:
parent
9251cfed9b
commit
a4a2671fd0
@ -25,28 +25,19 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <unsupported/Eigen/MatrixFunctions>
|
#include <unsupported/Eigen/MatrixFunctions>
|
||||||
|
|
||||||
// Returns either a matrix with iid random entries or a matrix with
|
// Returns a matrix with eigenvalues clustered around 0, 1 and 2.
|
||||||
// clustered eigenvalues. Matrices with clustered eigenvalue clusters
|
|
||||||
// lead to different code paths in MatrixFunction.h and are thus
|
|
||||||
// useful for testing.
|
|
||||||
template<typename MatrixType>
|
template<typename MatrixType>
|
||||||
MatrixType createRandomMatrix(const int size)
|
MatrixType randomMatrixWithRealEivals(const int size)
|
||||||
{
|
{
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
typedef typename MatrixType::RealScalar RealScalar;
|
typedef typename MatrixType::RealScalar RealScalar;
|
||||||
MatrixType result;
|
|
||||||
if (ei_random<int>(0,1) == 0) {
|
|
||||||
result = MatrixType::Random(size, size);
|
|
||||||
} else {
|
|
||||||
MatrixType diag = MatrixType::Zero(size, size);
|
MatrixType diag = MatrixType::Zero(size, size);
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
diag(i, i) = Scalar(RealScalar(ei_random<int>(0,2)))
|
diag(i, i) = Scalar(RealScalar(ei_random<int>(0,2)))
|
||||||
+ ei_random<Scalar>() * Scalar(RealScalar(0.01));
|
+ ei_random<Scalar>() * Scalar(RealScalar(0.01));
|
||||||
}
|
}
|
||||||
MatrixType A = MatrixType::Random(size, size);
|
MatrixType A = MatrixType::Random(size, size);
|
||||||
result = A.inverse() * diag * A;
|
return A.inverse() * diag * A;
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename MatrixType>
|
template<typename MatrixType>
|
||||||
@ -109,14 +100,24 @@ void testGonioFunctions(const MatrixType& A)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename MatrixType>
|
template<typename MatrixType>
|
||||||
void testMatrixType(const MatrixType& m)
|
void testMatrix(const MatrixType& A)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < g_repeat; i++) {
|
|
||||||
MatrixType A = createRandomMatrix<MatrixType>(m.rows());
|
|
||||||
testMatrixExponential(A);
|
testMatrixExponential(A);
|
||||||
testHyperbolicFunctions(A);
|
testHyperbolicFunctions(A);
|
||||||
testGonioFunctions(A);
|
testGonioFunctions(A);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename MatrixType>
|
||||||
|
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++) {
|
||||||
|
testMatrix(MatrixType::Random(size, size).eval());
|
||||||
|
testMatrix(randomMatrixWithRealEivals<MatrixType>(size));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_matrix_function()
|
void test_matrix_function()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user