Check for positive definiteness in SimplicialLLT

This commit is contained in:
Christoph Hertzberg 2012-01-14 22:34:18 +01:00
parent 5e4dfa4a09
commit 362fcabc44

View File

@ -764,18 +764,24 @@ void SimplicialCholeskyBase<Derived>::factorize(const MatrixType& a)
++m_nonZerosPerCol[i]; /* increment count of nonzeros in col i */ ++m_nonZerosPerCol[i]; /* increment count of nonzeros in col i */
} }
if(DoLDLt) if(DoLDLt)
{
m_diag[k] = d; m_diag[k] = d;
if(d == Scalar(0))
{
ok = false; /* failure, D(k,k) is zero */
break;
}
}
else else
{ {
Index p = Lp[k]+m_nonZerosPerCol[k]++; Index p = Lp[k]+m_nonZerosPerCol[k]++;
Li[p] = k ; /* store L(k,k) = sqrt (d) in column 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) ; Lx[p] = internal::sqrt(d) ;
} }
if(d == Scalar(0))
{
ok = false; /* failure, D(k,k) is zero */
break;
}
} }
m_info = ok ? Success : NumericalIssue; m_info = ok ? Success : NumericalIssue;