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,19 +764,25 @@ 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;
else
{ {
Index p = Lp[k]+m_nonZerosPerCol[k]++; m_diag[k] = d;
Li[p] = k ; /* store L(k,k) = sqrt (d) in column k */
Lx[p] = internal::sqrt(d) ;
}
if(d == Scalar(0)) if(d == Scalar(0))
{ {
ok = false; /* failure, D(k,k) is zero */ ok = false; /* failure, D(k,k) is zero */
break; 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) ;
}
}
m_info = ok ? Success : NumericalIssue; m_info = ok ? Success : NumericalIssue;
m_factorizationIsOk = true; m_factorizationIsOk = true;