Skip to content

Always return convergence history #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
haampie opened this issue Dec 28, 2017 · 3 comments
Open

Always return convergence history #185

haampie opened this issue Dec 28, 2017 · 3 comments

Comments

@haampie
Copy link
Member

haampie commented Dec 28, 2017

Right now there is no way of querying whether the method is converged other than retrieving the full convergence history with log = true.

I would suggest always returning a minimal convergence history, without the resnorm array, which at least allows you to query whether it is converged and how many iterations that took. Setting log = true would then collect info during the iterations as well.

It would look like this:

julia> x, history = cg(A, b);
julia> history
Converged after 10 iterations.

Maybe we could make the history object immutable as well.

@andreasnoack
Copy link
Member

Sounds reasonable. This could potentially also make the functions type stable but now that we have constant propagation this might not be an issue anymore (but would have to check on 0.7).

@mohamed82008
Copy link
Member

Goes part of the way: #238

@gdalle
Copy link

gdalle commented Mar 27, 2022

Hi! I'm not sure I understand why constant propagation solves this issue?

julia> using IterativeSolvers

julia> n = 100;

julia> A = rand(n, n);

julia> A = A + A' + 2*n*I;

julia> b = rand(n);

julia> @code_warntype cg(A, b)
MethodInstance for IterativeSolvers.cg(::Matrix{Float64}, ::Vector{Float64})
  from cg(A, b; kwargs...) in IterativeSolvers at /home/guillaume/.julia/packages/IterativeSolvers/rhYBz/src/cg.jl:162
Arguments
  #self#::Core.Const(IterativeSolvers.cg)
  A::Matrix{Float64}
  b::Vector{Float64}
Body::Union{Tuple{Vector{Float64}, ConvergenceHistory{_A, Nothing} where _A}, Vector{Float64}}
1%1 = Core.NamedTuple()::Core.Const(NamedTuple())
│   %2 = Base.pairs(%1)::Core.Const(Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}())
│   %3 = IterativeSolvers.:(var"#cg#22")(%2, #self#, A, b)::Union{Tuple{Vector{Float64}, ConvergenceHistory{_A, Nothing} where _A}, Vector{Float64}}
└──      return %3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants