mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Bug567 : Fix iterative solvers to immediately return when the initial guess is the true solution and for trivial solution
This commit is contained in:
@@ -44,6 +44,11 @@ bool bicgstab(const MatrixType& mat, const Rhs& rhs, Dest& x,
|
||||
VectorType r0 = r;
|
||||
|
||||
RealScalar r0_sqnorm = rhs.squaredNorm();
|
||||
if(r0_sqnorm == 0)
|
||||
{
|
||||
x.setZero();
|
||||
return true;
|
||||
}
|
||||
Scalar rho = 1;
|
||||
Scalar alpha = 1;
|
||||
Scalar w = 1;
|
||||
|
||||
@@ -41,21 +41,29 @@ void conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& x,
|
||||
int n = mat.cols();
|
||||
|
||||
VectorType residual = rhs - mat * x; //initial residual
|
||||
VectorType p(n);
|
||||
|
||||
RealScalar rhsNorm2 = rhs.squaredNorm();
|
||||
if(rhsNorm2 == 0)
|
||||
{
|
||||
x.setZero();
|
||||
iters = 0;
|
||||
tol_error = 0;
|
||||
return;
|
||||
}
|
||||
RealScalar threshold = tol*tol*rhsNorm2;
|
||||
RealScalar residualNorm2 = residual.squaredNorm();
|
||||
if (residualNorm2 < threshold)
|
||||
{
|
||||
iters = 0;
|
||||
tol_error = sqrt(residualNorm2 / rhsNorm2);
|
||||
return;
|
||||
}
|
||||
|
||||
VectorType p(n);
|
||||
p = precond.solve(residual); //initial search direction
|
||||
|
||||
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;
|
||||
while(i < maxIters)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user