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)
{
x = ei_real(a.coeff(j,j)) - m_matrix.row(j).start(j).squaredNorm();
if (x < cutoff)
if (x <= cutoff)
{
m_isPositiveDefinite = false;
continue;

View File

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

View File

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