From e7d809d4349fd4048777be71f1c803d0b13f8fe8 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Mon, 24 May 2010 17:43:50 +0100 Subject: Update eigenvalues() and operatorNorm() methods in MatrixBase. * use SelfAdjointView instead of Eigen2's SelfAdjoint flag. * add tests and documentation. * allow eigenvalues() for non-selfadjoint matrices. * they no longer depend only on SelfAdjointEigenSolver, so move them to a separate file --- test/eigensolver_complex.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'test/eigensolver_complex.cpp') diff --git a/test/eigensolver_complex.cpp b/test/eigensolver_complex.cpp index b3d9ac24b..5c5d7b38f 100644 --- a/test/eigensolver_complex.cpp +++ b/test/eigensolver_complex.cpp @@ -26,6 +26,21 @@ #include #include +/* Check that two column vectors are approximately equal upto permutations, + by checking that the k-th power sums are equal for k = 1, ..., vec1.rows() */ +template +void verify_is_approx_upto_permutation(const VectorType& vec1, const VectorType& vec2) +{ + VERIFY(vec1.cols() == 1); + VERIFY(vec2.cols() == 1); + VERIFY(vec1.rows() == vec2.rows()); + for (int k = 1; k <= vec1.rows(); ++k) + { + VERIFY_IS_APPROX(vec1.array().pow(k).sum(), vec2.array().pow(k).sum()); + } +} + + template void eigensolver(const MatrixType& m) { /* this test covers the following files: @@ -48,11 +63,17 @@ template void eigensolver(const MatrixType& m) ComplexEigenSolver ei1(a); VERIFY_IS_APPROX(a * ei1.eigenvectors(), ei1.eigenvectors() * ei1.eigenvalues().asDiagonal()); - + // Note: If MatrixType is real then a.eigenvalues() uses EigenSolver and thus + // another algorithm so results may differ slightly + verify_is_approx_upto_permutation(a.eigenvalues(), ei1.eigenvalues()); + // Regression test for issue #66 MatrixType z = MatrixType::Zero(rows,cols); ComplexEigenSolver eiz(z); VERIFY((eiz.eigenvalues().cwiseEqual(0)).all()); + + MatrixType id = MatrixType::Identity(rows, cols); + VERIFY_IS_APPROX(id.operatorNorm(), RealScalar(1)); } void test_eigensolver_complex() -- cgit v1.2.3