@@ -197,20 +197,22 @@ function cg_update(ws,A)
197197 update (ws;iteration,Pl,A)
198198end
199199
200- function cg_step (x,ws,b,phase= :start ;kwargs... )
200+ function cg_step (x,ws,b,phase= :start ;zero_guess = false , kwargs... )
201201 (;dx,r,u,A,ρ,iteration,current,target) = ws. state
202202 (;reltol,abstol,norm,Pl) = ws. options
203203 s = u
204204 if phase === :start
205205 iteration = 0
206206 phase = :advance
207207 copyto! (r,b)
208- mul! (s,A,x)
209- axpy! (- one (eltype (s)),s,r)
210- # r .-= s
208+ if ! zero_guess
209+ mul! (s,A,x)
210+ axpy! (- one (eltype (s)),s,r)
211+ # r .-= s
212+ end
211213 current = norm (r)
212214 target = max (reltol* current,abstol)
213- dx . = zero (eltype (dx))
215+ fill! (dx, zero (eltype (dx) ))
214216 ρ = one (eltype (x))
215217 ws = update (ws;iteration,ρ,current,target)
216218 print_progress_header (ws)
@@ -228,7 +230,6 @@ function cg_step(x,ws,b,phase=:start;kwargs...)
228230 # x .+= α .* dx
229231 axpy! (- α,s,r)
230232 # r .-= α .* s
231- current = norm (r)
232233 iteration += 1
233234 current = norm (r)
234235 ws = update (ws;iteration,ρ,current)
0 commit comments