mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-13 16:41:50 +08:00
Fix conjugate-gradient for very small rhs
(grafted from 1141bcf7940cf18974f72fcad3febc41e07bc6ec )
This commit is contained in:
parent
92cd158c01
commit
bc000deaae
@ -50,7 +50,8 @@ void conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& x,
|
|||||||
tol_error = 0;
|
tol_error = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RealScalar threshold = tol*tol*rhsNorm2;
|
const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)();
|
||||||
|
RealScalar threshold = numext::maxi(tol*tol*rhsNorm2,considerAsZero);
|
||||||
RealScalar residualNorm2 = residual.squaredNorm();
|
RealScalar residualNorm2 = residual.squaredNorm();
|
||||||
if (residualNorm2 < threshold)
|
if (residualNorm2 < threshold)
|
||||||
{
|
{
|
||||||
@ -58,7 +59,7 @@ void conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& x,
|
|||||||
tol_error = sqrt(residualNorm2 / rhsNorm2);
|
tol_error = sqrt(residualNorm2 / rhsNorm2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
VectorType p(n);
|
VectorType p(n);
|
||||||
p = precond.solve(residual); // initial search direction
|
p = precond.solve(residual); // initial search direction
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user