Skip to content

Commit b1e4bf4

Browse files
committed
Add tests
1 parent d738dcc commit b1e4bf4

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
9494
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
9595

9696
[targets]
97-
test = ["Test", "IterativeSolvers", "InteractiveUtils", "JET", "KrylovKit", "Pkg", "Random", "SafeTestsets", "MultiFloats", "ForwardDiff", "HYPRE", "MPI", "MKL_jll"]
97+
test = ["Test", "IterativeSolvers", "InteractiveUtils", "JET", "KrylovKit", "Pkg", "Random", "SafeTestsets", "MultiFloats", "ForwardDiff", "HYPRE", "MPI", "MKL_jll", "BlockDiagonals"]

src/simplegmres.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ function _init_cacheval(::Val{false}, alg::SimpleGMRES, A, b, u, Pl, Pr, maxiter
169169
q = PlisI ? similar(u, 0) : similar(u, n)
170170
p = PrisI ? similar(u, 0) : similar(u, n)
171171
x = u
172+
x .= zero(T)
172173

173174
w = similar(u, n)
174175
V = [similar(u) for _ in 1:memory]
@@ -398,6 +399,7 @@ function _init_cacheval(::Val{true}, alg::SimpleGMRES, A, b, u, Pl, Pr, maxiters
398399
q = PlisI ? similar(u, 0) : similar(u, n)
399400
p = PrisI ? similar(u, 0) : similar(u, n)
400401
x = u
402+
x .= zero(T)
401403

402404
w = similar(u, n)
403405
V = [similar(u) for _ in 1:memory]

test/basictests.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ end
235235
end
236236
end
237237

238+
@testset "Simple GMRES: restart = $restart" for restart in (true, false)
239+
test_interface(SimpleGMRES(; restart), prob1, prob2)
240+
end
241+
238242
@testset "KrylovJL" begin
239243
kwargs = (; gmres_restart = 5)
240244
for alg in (("Default", KrylovJL(kwargs...)),
@@ -412,7 +416,7 @@ end
412416

413417
@testset "DirectLdiv!" begin
414418
function get_operator(A, u; add_inverse = true)
415-
419+
416420
function f(u, p, t)
417421
println("using FunctionOperator OOP mul")
418422
A * u
@@ -470,3 +474,28 @@ lp = LinearProblem(A, b; u0 = view(u0, :));
470474
truesol = solve(lp, LUFactorization())
471475
krylovsol = solve(lp, KrylovJL_GMRES())
472476
@test truesol krylovsol
477+
478+
# Block Diagonals
479+
using BlockDiagonals
480+
481+
@testset "Block Diagonal Specialization" begin
482+
A = BlockDiagonal([rand(2, 2) for _ in 1:3])
483+
b = rand(size(A, 1))
484+
485+
if VERSION > v"1.9-"
486+
x1 = zero(b)
487+
x2 = zero(b)
488+
prob1 = LinearProblem(A, b, x1)
489+
prob2 = LinearProblem(A, b, x2)
490+
test_interface(SimpleGMRES(), prob1, prob2)
491+
end
492+
493+
x1 = zero(b)
494+
x2 = zero(b)
495+
prob1 = LinearProblem(Array(A), b, x1)
496+
prob2 = LinearProblem(Array(A), b, x2)
497+
498+
test_interface(SimpleGMRES(; blocksize=2), prob1, prob2)
499+
500+
@test solve(prob1, SimpleGMRES(; blocksize=2)).u solve(prob2, SimpleGMRES()).u
501+
end

test/gpu/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
BlockDiagonals = "0a1fb500-61f7-11e9-3c65-f5ef3456f9f0"
23
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
34
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
45
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"

test/gpu/cuda.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,32 @@ function test_interface(alg, prob1, prob2)
4242
return
4343
end
4444

45-
test_interface(CudaOffloadFactorization(), prob1, prob2)
45+
@testset "CudaOffloadFactorization" begin
46+
test_interface(CudaOffloadFactorization(), prob1, prob2)
47+
end
48+
49+
@testset "Simple GMRES: restart = $restart" for restart in (true, false)
50+
test_interface(SimpleGMRES(; restart), prob1, prob2)
51+
end
4652

4753
A1 = prob1.A;
4854
b1 = prob1.b;
4955
x1 = prob1.u0;
5056
y = solve(prob1)
5157
@test A1 * y b1
58+
59+
using BlockDiagonals
60+
61+
@testset "Block Diagonal Specialization" begin
62+
A = BlockDiagonal([rand(2, 2) for _ in 1:3]) |> cu
63+
b = rand(size(A, 1)) |> cu
64+
65+
x1 = zero(b)
66+
x2 = zero(b)
67+
prob1 = LinearProblem(A, b, x1)
68+
prob2 = LinearProblem(A, b, x2)
69+
70+
test_interface(SimpleGMRES(; blocksize=2), prob1, prob2)
71+
72+
@test solve(prob1, SimpleGMRES(; blocksize=2)).u solve(prob2, SimpleGMRES()).u
73+
end

0 commit comments

Comments
 (0)