Skip to content

Commit 952957f

Browse files
committed
Add test for working "reuse_precs=true"
1 parent 536f8ec commit 952957f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/basictests.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,30 @@ end
284284
end
285285
end
286286

287+
@testset "Reuse precs" begin
288+
num_precs_calls = 0
289+
290+
function countingprecs(A, p = nothing)
291+
num_precs_calls += 1
292+
(BlockJacobiPreconditioner(A, 2), I)
293+
end
294+
295+
n = 10
296+
A = spdiagm(-1 => -ones(n - 1), 0 => fill(10.0, n), 1 => -ones(n - 1))
297+
b = rand(n)
298+
p = LinearProblem(A, b)
299+
x0 = solve(p, KrylovJL_CG(precs = countingprecs, ldiv = false))
300+
cache = x0.cache
301+
x0 = copy(x0)
302+
for i in 4:(n - 3)
303+
A[i, i + 3] -= 1.0e-4
304+
A[i - 3, i] -= 1.0e-4
305+
end
306+
LinearSolve.reinit!(cache; A, reuse_precs = true)
307+
x1 = copy(solve!(cache))
308+
@test all(x0 .< x1) && num_precs_calls == 1
309+
end
310+
287311
if VERSION >= v"1.9-"
288312
@testset "IterativeSolversJL" begin
289313
kwargs = (; gmres_restart = 5)

0 commit comments

Comments
 (0)