Skip to content

Commit 0baf80e

Browse files
committed
Return a nice error if we detect that the preconditioner is not SPD in CG
1 parent ef9bb41 commit 0baf80e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/cg.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ kwargs_cg = (:M, :ldiv, :radius, :linesearch, :atol, :rtol, :itmax, :timemax, :v
143143
MisI || mulorldiv!(z, M, r, ldiv)
144144
kcopy!(n, p, z) # p ← z
145145
γ = kdotr(n, r, z)
146+
γ 0 || error("The preconditioner `M` is not symmetric positive definite.")
146147
rNorm = sqrt(γ)
147148
history && push!(rNorms, rNorm)
148149
if γ == 0
@@ -214,6 +215,7 @@ kwargs_cg = (:M, :ldiv, :radius, :linesearch, :atol, :rtol, :itmax, :timemax, :v
214215
kaxpy!(n, -α, Ap, r)
215216
MisI || mulorldiv!(z, M, r, ldiv)
216217
γ_next = kdotr(n, r, z)
218+
γ_next 0 || error("The preconditioner `M` is not symmetric positive definite.")
217219
rNorm = sqrt(γ_next)
218220
history && push!(rNorms, rNorm)
219221

0 commit comments

Comments
 (0)