diff options
author | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2014-02-06 11:06:06 +0000 |
---|---|---|
committer | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2014-02-06 11:06:06 +0000 |
commit | ff8d81762d6612b812db6385b1096c6a8b1006cc (patch) | |
tree | 7069f05daf1c1868ed459ccd785ad2abaf3f8107 /test/cholesky.cpp | |
parent | 6c527bd811a4bbb122093fcc9ba9b7bd86963855 (diff) |
Fix bug #736: LDLT isPositive returns false for a positive semidefinite matrix
Add unit test covering this case.
Diffstat (limited to 'test/cholesky.cpp')
-rw-r--r-- | test/cholesky.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/test/cholesky.cpp b/test/cholesky.cpp index 378525a83..b980dc572 100644 --- a/test/cholesky.cpp +++ b/test/cholesky.cpp @@ -263,8 +263,8 @@ template<typename MatrixType> void cholesky_bug241(const MatrixType& m) // 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<typename MatrixType> void cholesky_indefinite(const MatrixType& m) +// See http://forum.kde.org/viewtopic.php?f=74&t=106942 and bug 736 +template<typename MatrixType> void cholesky_definiteness(const MatrixType& m) { eigen_assert(m.rows() == 2 && m.cols() == 2); MatrixType mat; @@ -280,6 +280,24 @@ template<typename MatrixType> void cholesky_indefinite(const MatrixType& m) VERIFY(!ldlt.isNegative()); VERIFY(!ldlt.isPositive()); } + { + mat << 0, 0, 0, 0; + LDLT<MatrixType> ldlt(mat); + VERIFY(ldlt.isNegative()); + VERIFY(ldlt.isPositive()); + } + { + mat << 0, 0, 0, 1; + LDLT<MatrixType> ldlt(mat); + VERIFY(!ldlt.isNegative()); + VERIFY(ldlt.isPositive()); + } + { + mat << -1, 0, 0, 0; + LDLT<MatrixType> ldlt(mat); + VERIFY(ldlt.isNegative()); + VERIFY(!ldlt.isPositive()); + } } template<typename MatrixType> void cholesky_verify_assert() @@ -309,7 +327,7 @@ void test_cholesky() CALL_SUBTEST_1( cholesky(Matrix<double,1,1>()) ); CALL_SUBTEST_3( cholesky(Matrix2d()) ); CALL_SUBTEST_3( cholesky_bug241(Matrix2d()) ); - CALL_SUBTEST_3( cholesky_indefinite(Matrix2d()) ); + CALL_SUBTEST_3( cholesky_definiteness(Matrix2d()) ); CALL_SUBTEST_4( cholesky(Matrix3f()) ); CALL_SUBTEST_5( cholesky(Matrix4d()) ); s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE); |