From 362fcabc440ad6404250fe83c7583367d99629d5 Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Sat, 14 Jan 2012 22:34:18 +0100 Subject: [PATCH] Check for positive definiteness in SimplicialLLT --- Eigen/src/SparseCholesky/SimplicialCholesky.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Eigen/src/SparseCholesky/SimplicialCholesky.h b/Eigen/src/SparseCholesky/SimplicialCholesky.h index 4aa366343..ae322f38a 100644 --- a/Eigen/src/SparseCholesky/SimplicialCholesky.h +++ b/Eigen/src/SparseCholesky/SimplicialCholesky.h @@ -764,18 +764,24 @@ void SimplicialCholeskyBase::factorize(const MatrixType& a) ++m_nonZerosPerCol[i]; /* increment count of nonzeros in col i */ } if(DoLDLt) + { m_diag[k] = d; + if(d == Scalar(0)) + { + ok = false; /* failure, D(k,k) is zero */ + break; + } + } else { Index p = Lp[k]+m_nonZerosPerCol[k]++; Li[p] = k ; /* store L(k,k) = sqrt (d) in column k */ + if(d <= Scalar(0)) { + ok = false; /* failure, matrix is not positive definite */ + break; + } Lx[p] = internal::sqrt(d) ; } - if(d == Scalar(0)) - { - ok = false; /* failure, D(k,k) is zero */ - break; - } } m_info = ok ? Success : NumericalIssue;