IterativeSolvers.jl
IterativeSolvers.jl copied to clipboard
Always return convergence history
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.
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).
Goes part of the way: #238
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