JuliaLinearAlgebra / IterativeSolvers.jl

Iterative algorithms for solving linear systems, eigensystems, and singular value problems
MIT License
403 stars 106 forks source link

Absolute and relative tolerance for linear solvers #280

Closed ranocha closed 3 years ago

ranocha commented 3 years ago

This PR adds keyword arguments abstol and reltol to iterative solvers for linear system and deprecates the former keyword tol (which is now reltol).

Since this is my first contribution to IterativeSolvers.jl, I would like to get some feedback on this work to improve this PR. Thanks!

If this approach is acceptable, I will continue to work on the other iterative solvers and adapt them accordingly.

By the way, I noticed that CG doesn't respect the stopping criterion described in the docs, see also #244. I think it would be good to fix this (as described in my comment in cg.jl).

Closes #207 by adding the keyword argument abstol.

Closes #244 by fixing the convergence criterion for CG (reltol should be relative to the initial residual instead of the RHS b).

ranocha commented 3 years ago

I made all the changes to the iterative solvers for "simple" linear problems. Since the solvers for least-squares problems use a different setup of tolerances, I didn't adapt them. It would be nice to have another round of reviews to improve this PR :slightly_smiling_face:

mschauer commented 3 years ago

Can one express the logic/stopping criteria with reltol and abstol using isapprox from base?

ranocha commented 3 years ago

Can one express the logic/stopping criteria with reltol and abstol using isapprox from base?

isapprox(x, y) returns true if

norm(x-y) <= max(atol, rtol*max(norm(x), norm(y)))

Our stopping criterion is

norm(residual) <= max(abstol, reltol * initial_residual_norm)

Hence, I don't see a possibility to do that.

mschauer commented 3 years ago

I see, thanks.

ranocha commented 3 years ago

@haampie Can we merge this? The decreased coverage is only caused by the new depwarns.

haampie commented 3 years ago

Hi @ranocha , I haven't had the chance to review yet. Tomorrow I can do that

haampie commented 3 years ago

Thank you!