fix LU and QR solve when rank==0, fix LLT when the matrix is purely 0

This commit is contained in:
Gael Guennebaud 2010-07-12 16:42:38 +02:00
parent 468863f3a0
commit c44bbabdcc
3 changed files with 8 additions and 4 deletions

View File

@ -136,7 +136,7 @@ void LLT<MatrixType>::compute(const MatrixType& a)
for (int j = 1; j < size; ++j) for (int j = 1; j < size; ++j)
{ {
x = ei_real(a.coeff(j,j)) - m_matrix.row(j).start(j).squaredNorm(); x = ei_real(a.coeff(j,j)) - m_matrix.row(j).start(j).squaredNorm();
if (x < cutoff) if (x <= cutoff)
{ {
m_isPositiveDefinite = false; m_isPositiveDefinite = false;
continue; continue;

View File

@ -515,9 +515,10 @@ bool LU<MatrixType>::solve(
if(!ei_isMuchSmallerThan(c.coeff(row,col), biggest_in_c, m_precision)) if(!ei_isMuchSmallerThan(c.coeff(row,col), biggest_in_c, m_precision))
return false; return false;
} }
m_lu.corner(TopLeft, m_rank, m_rank) if(m_rank>0)
.template marked<UpperTriangular>() m_lu.corner(TopLeft, m_rank, m_rank)
.solveTriangularInPlace(c.corner(TopLeft, m_rank, c.cols())); .template marked<UpperTriangular>()
.solveTriangularInPlace(c.corner(TopLeft, m_rank, c.cols()));
// Step 4 // Step 4
result->resize(m_lu.cols(), b.cols()); result->resize(m_lu.cols(), b.cols());

View File

@ -276,6 +276,9 @@ bool QR<MatrixType>::solve(
// Q^T without explicitly forming matrixQ(). Investigate. // Q^T without explicitly forming matrixQ(). Investigate.
*result = matrixQ().transpose()*b; *result = matrixQ().transpose()*b;
if(m_rank==0)
return result.isZero();
if(!isSurjective()) if(!isSurjective())
{ {
// is result is in the image of R ? // is result is in the image of R ?