mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-14 20:56:00 +08:00
finally, the correct way of dealing with zero matrices in solve()
This commit is contained in:
parent
b8106e97b4
commit
3288e5157a
@ -534,7 +534,16 @@ bool LU<MatrixType>::solve(
|
|||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
ei_assert(m_originalMatrix != 0 && "LU is not initialized.");
|
ei_assert(m_originalMatrix != 0 && "LU is not initialized.");
|
||||||
if(m_rank==0) return false;
|
result->resize(m_lu.cols(), b.cols());
|
||||||
|
if(m_rank==0)
|
||||||
|
{
|
||||||
|
if(b.squaredNorm() == RealScalar(0))
|
||||||
|
{
|
||||||
|
result->setZero();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1}.
|
/* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1}.
|
||||||
* So we proceed as follows:
|
* So we proceed as follows:
|
||||||
@ -577,7 +586,6 @@ bool LU<MatrixType>::solve(
|
|||||||
.solveInPlace(c.corner(TopLeft, m_rank, c.cols()));
|
.solveInPlace(c.corner(TopLeft, m_rank, c.cols()));
|
||||||
|
|
||||||
// Step 4
|
// Step 4
|
||||||
result->resize(m_lu.cols(), b.cols());
|
|
||||||
for(int i = 0; i < m_rank; ++i) result->row(m_q.coeff(i)) = c.row(i);
|
for(int i = 0; i < m_rank; ++i) result->row(m_q.coeff(i)) = c.row(i);
|
||||||
for(int i = m_rank; i < m_lu.cols(); ++i) result->row(m_q.coeff(i)).setZero();
|
for(int i = m_rank; i < m_lu.cols(); ++i) result->row(m_q.coeff(i)).setZero();
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user