mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-11 11:19:02 +08:00
Handle zero right hand side in CG and GMRES
This commit is contained in:
parent
9bfeeba1c5
commit
4107b371e3
@ -48,6 +48,12 @@ void conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& x,
|
||||
VectorType z(n), tmp(n);
|
||||
RealScalar absNew = internal::real(residual.dot(p)); // the square of the absolute value of r scaled by invM
|
||||
RealScalar rhsNorm2 = rhs.squaredNorm();
|
||||
// Check Zero right hand side
|
||||
if(!rhsNorm2)
|
||||
{
|
||||
x.setZero();
|
||||
return;
|
||||
}
|
||||
RealScalar residualNorm2 = 0;
|
||||
RealScalar threshold = tol*tol*rhsNorm2;
|
||||
int i = 0;
|
||||
|
@ -348,7 +348,8 @@ public:
|
||||
template<typename Rhs,typename Dest>
|
||||
void _solve(const Rhs& b, Dest& x) const
|
||||
{
|
||||
x.setZero();
|
||||
x = b;
|
||||
if(!x.squaredNorm()) return; // Check Zero right hand side
|
||||
_solveWithGuess(b,x);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user