From fd5749f51c899941323a2c3a2b1e152102bacebe Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Sun, 22 Jul 2012 21:39:38 +0100 Subject: LDLT: Report sign consistent with D for indefinite matrices. See http://forum.kde.org/viewtopic.php?f=74&t=106942 --- test/cholesky.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/cholesky.cpp') diff --git a/test/cholesky.cpp b/test/cholesky.cpp index 14e01c006..49c79f9c8 100644 --- a/test/cholesky.cpp +++ b/test/cholesky.cpp @@ -262,6 +262,19 @@ template void cholesky_bug241(const MatrixType& m) VERIFY_IS_APPROX(matA * vecX, vecB); } +// LDLT is not guaranteed to work for indefinite matrices, but happens to work fine if matrix is diagonal. +// This test checks that LDLT reports correctly that matrix is indefinite. +// See http://forum.kde.org/viewtopic.php?f=74&t=106942 +template void cholesky_indefinite(const MatrixType& m) +{ + eigen_assert(m.rows() == 2 && m.cols() == 2); + MatrixType mat; + mat << 1, 0, 0, -1; + LDLT ldlt(mat); + VERIFY(!ldlt.isNegative()); + VERIFY(!ldlt.isPositive()); +} + template void cholesky_verify_assert() { MatrixType tmp; @@ -289,6 +302,7 @@ void test_cholesky() CALL_SUBTEST_1( cholesky(Matrix()) ); CALL_SUBTEST_3( cholesky(Matrix2d()) ); CALL_SUBTEST_3( cholesky_bug241(Matrix2d()) ); + CALL_SUBTEST_3( cholesky_indefinite(Matrix2d()) ); CALL_SUBTEST_4( cholesky(Matrix3f()) ); CALL_SUBTEST_5( cholesky(Matrix4d()) ); s = internal::random(1,EIGEN_TEST_MAX_SIZE); -- cgit v1.2.3