Skip to content

Commit 72faa93

Browse files
author
oscarddssmith
committed
update precs when cache.isfresh
1 parent 1c30db0 commit 72faa93

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

ext/LinearSolvePardisoExt.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::PardisoJL; kwargs
132132
@unpack A, b, u = cache
133133
A = convert(AbstractMatrix, A)
134134
if cache.isfresh
135+
if hasproperty(alg, :precs) && !isnothing(alg.precs)
136+
Pl, Pr = cache.alg.precs(x, cache.p)
137+
cache.Pl = Pl
138+
cache.Pr = Pr
139+
end
135140
phase = alg.cache_analysis ? Pardiso.NUM_FACT : Pardiso.ANALYSIS_NUM_FACT
136141
Pardiso.set_phase!(cache.cacheval, phase)
137142
Pardiso.pardiso(cache.cacheval, A, eltype(A)[])

src/common.jl

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,8 @@ mutable struct LinearCache{TA, Tb, Tu, Tp, Talg, Tc, Tl, Tr, Ttol, issq, S}
8484
end
8585

8686
function Base.setproperty!(cache::LinearCache, name::Symbol, x)
87-
if name === :A
88-
if hasproperty(cache.alg, :precs) && !isnothing(cache.alg.precs)
89-
Pl, Pr = cache.alg.precs(x, cache.p)
90-
setfield!(cache, :Pl, Pl)
91-
setfield!(cache, :Pr, Pr)
92-
end
87+
if name === :A || name === :p
9388
setfield!(cache, :isfresh, true)
94-
elseif name === :p
95-
if hasproperty(cache.alg, :precs) && !isnothing(cache.alg.precs)
96-
Pl, Pr = cache.alg.precs(cache.A, x)
97-
setfield!(cache, :Pl, Pl)
98-
setfield!(cache, :Pr, Pr)
99-
end
10089
elseif name === :b
10190
# In case there is something that needs to be done when b is updated
10291
update_cacheval!(cache, :b, x)
@@ -224,20 +213,7 @@ function SciMLBase.reinit!(cache::LinearCache;
224213
u = cache.u,
225214
p = nothing,
226215
reinit_cache = false,)
227-
(; alg, cacheval, abstol, reltol, maxiters, verbose, assumptions, sensealg) = cache
228-
229-
precs = (hasproperty(alg, :precs) && !isnothing(alg.precs)) ? alg.precs : DEFAULT_PRECS
230-
Pl, Pr = if isnothing(A) || isnothing(p)
231-
if isnothing(A)
232-
A = cache.A
233-
end
234-
if isnothing(p)
235-
p = cache.p
236-
end
237-
precs(A, p)
238-
else
239-
(cache.Pl, cache.Pr)
240-
end
216+
(; alg, cacheval, abstol, reltol, maxiters, verbose, assumptions, sensealg, Pl, Pr) = cache
241217
isfresh = true
242218

243219
if reinit_cache
@@ -250,8 +226,6 @@ function SciMLBase.reinit!(cache::LinearCache;
250226
cache.b = b
251227
cache.u = u
252228
cache.p = p
253-
cache.Pl = Pl
254-
cache.Pr = Pr
255229
cache.isfresh = true
256230
end
257231
end

src/iterative_wrappers.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ end
226226

227227
function SciMLBase.solve!(cache::LinearCache, alg::KrylovJL; kwargs...)
228228
if cache.isfresh
229+
if hasproperty(alg, :precs) && !isnothing(alg.precs)
230+
Pl, Pr = cache.alg.precs(x, cache.p)
231+
cache.Pl = Pl
232+
cache.Pr = Pr
233+
end
229234
solver = init_cacheval(alg, cache.A, cache.b, cache.u, cache.Pl, cache.Pr,
230235
cache.maxiters, cache.abstol, cache.reltol, cache.verbose,
231236
cache.assumptions, zeroinit = false)

0 commit comments

Comments
 (0)