Commit 02cdfcf4 authored by Davis King's avatar Davis King

Made the code in chol() more robust to indefinite matrices.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403867
parent 116cf434
......@@ -1088,6 +1088,8 @@ convergence:
if (A.size() == 0)
return L;
const T eps = std::numeric_limits<T>::epsilon();
// compute the upper left corner
if (A(0,0) > 0)
L(0,0) = std::sqrt(A(0,0));
......@@ -1095,10 +1097,10 @@ convergence:
// compute the first column
for (long r = 1; r < A.nr(); ++r)
{
if (L(0,0) > 0)
if (L(0,0) > eps*A(r,0))
L(r,0) = A(r,0)/L(0,0);
else
L(r,0) = A(r,0);
return L;
}
// now compute all the other columns
......@@ -1121,10 +1123,10 @@ convergence:
{
temp -= L(r,i)*L(c,i);
}
if (L(c,c) > 0)
if (L(c,c) > eps*temp)
L(r,c) = temp/L(c,c);
else
L(r,c) = temp;
return L;
}
}
......
......@@ -82,6 +82,11 @@ namespace
type temp;
DLIB_TEST_MSG( (temp= max(abs(test.get_l()*trans(test.get_l()) - m))) < eps,temp);
{
matrix<type> mat = chol(m);
DLIB_TEST_MSG( (temp= max(abs(mat*trans(mat) - m))) < eps,temp);
}
matrix<type> m2;
matrix<type,0,1> col;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment