@@ -9,37 +9,52 @@ const Dual64 = ForwardDiff.Dual{Nothing, Float64, 1}
9
9
n = 8
10
10
A = Matrix (I, n, n)
11
11
b = ones (n)
12
+ # Real-valued systems
12
13
A1 = A / 1 ;
13
14
b1 = rand (n);
14
15
x1 = zero (b);
16
+ # A2 is similar to A1; created to test cache reuse
15
17
A2 = A / 2 ;
16
18
b2 = rand (n);
17
19
x2 = zero (b);
20
+ # Complex systems + mismatched types with eltype(tol)
21
+ A3 = A1 .| > ComplexF32
22
+ b3 = b1 .| > ComplexF32
23
+ x3 = x1 .| > ComplexF32
24
+ # A4 is similar to A3; created to test cache reuse
25
+ A4 = A2 .| > ComplexF32
26
+ b4 = b2 .| > ComplexF32
27
+ x4 = x2 .| > ComplexF32
18
28
19
29
prob1 = LinearProblem (A1, b1; u0 = x1)
20
30
prob2 = LinearProblem (A2, b2; u0 = x2)
31
+ prob3 = LinearProblem (A3, b3; u0 = x3)
32
+ prob4 = LinearProblem (A4, b4; u0 = x4)
21
33
22
34
cache_kwargs = (; verbose = true , abstol = 1e-8 , reltol = 1e-8 , maxiter = 30 )
23
35
24
36
function test_interface (alg, prob1, prob2)
25
- A1 = prob1. A
26
- b1 = prob1. b
27
- x1 = prob1. u0
28
- A2 = prob2. A
29
- b2 = prob2. b
30
- x2 = prob2. u0
37
+ A1, b1 = prob1. A, prob1. b
38
+ A2, b2 = prob2. A, prob2. b
31
39
32
40
sol = solve (prob1, alg; cache_kwargs... )
33
41
@test A1 * sol. u ≈ b1
34
42
43
+ sol = solve (prob2, alg; cache_kwargs... )
44
+ @test A2 * sol. u ≈ b2
45
+
46
+ # Test cache resue: base mechanism
35
47
cache = SciMLBase. init (prob1, alg; cache_kwargs... ) # initialize cache
36
48
sol = solve! (cache)
37
49
@test A1 * sol. u ≈ b1
50
+
51
+ # Test cache resue: only A changes
38
52
cache. A = deepcopy (A2)
39
53
sol = solve! (cache; cache_kwargs... )
40
54
@test A2 * sol. u ≈ b1
41
55
42
- cache. A = A2
56
+ # Test cache resue: both A and b change
57
+ cache. A = deepcopy (A2)
43
58
cache. b = b2
44
59
sol = solve! (cache; cache_kwargs... )
45
60
@test A2 * sol. u ≈ b2
50
65
@testset " LinearSolve" begin
51
66
@testset " Default Linear Solver" begin
52
67
test_interface (nothing , prob1, prob2)
68
+ test_interface (nothing , prob3, prob4)
53
69
54
70
A1 = prob1. A * prob1. A'
55
71
b1 = prob1. b
@@ -202,25 +218,24 @@ end
202
218
end
203
219
end
204
220
205
- test_algs = if VERSION >= v " 1.9" && LinearSolve. usemkl
206
- (LUFactorization (),
207
- QRFactorization (),
208
- SVDFactorization (),
209
- RFLUFactorization (),
210
- MKLLUFactorization (),
211
- LinearSolve. defaultalg (prob1. A, prob1. b))
212
- else
213
- (LUFactorization (),
214
- QRFactorization (),
215
- SVDFactorization (),
216
- RFLUFactorization (),
217
- LinearSolve. defaultalg (prob1. A, prob1. b))
221
+
222
+ test_algs = [
223
+ LUFactorization (),
224
+ QRFactorization (),
225
+ SVDFactorization (),
226
+ RFLUFactorization (),
227
+ LinearSolve. defaultalg (prob1. A, prob1. b),
228
+ ]
229
+
230
+ if VERSION >= v " 1.9" && LinearSolve. usemkl
231
+ push! (test_algs, MKLLUFactorization ())
218
232
end
219
233
220
234
@testset " Concrete Factorizations" begin
221
235
for alg in test_algs
222
236
@testset " $alg " begin
223
237
test_interface (alg, prob1, prob2)
238
+ VERSION >= v " 1.9" && (alg isa MKLLUFactorization || test_interface (alg, prob3, prob4))
224
239
end
225
240
end
226
241
if LinearSolve. appleaccelerate_isavailable ()
@@ -232,15 +247,16 @@ end
232
247
for fact_alg in (lu, lu!,
233
248
qr, qr!,
234
249
cholesky,
235
- # cholesky!,
236
- # ldlt, ldlt!,
250
+ # cholesky!,
251
+ # ldlt, ldlt!,
237
252
bunchkaufman, bunchkaufman!,
238
253
lq, lq!,
239
254
svd, svd!,
240
255
LinearAlgebra. factorize)
241
256
@testset " fact_alg = $fact_alg " begin
242
257
alg = GenericFactorization (fact_alg = fact_alg)
243
258
test_interface (alg, prob1, prob2)
259
+ test_interface (alg, prob3, prob4)
244
260
end
245
261
end
246
262
end
@@ -251,13 +267,17 @@ end
251
267
252
268
@testset " KrylovJL" begin
253
269
kwargs = (; gmres_restart = 5 )
254
- for alg in ((" Default" , KrylovJL (kwargs... )),
270
+ algorithms = (
271
+ (" Default" , KrylovJL (kwargs... )),
255
272
(" CG" , KrylovJL_CG (kwargs... )),
256
273
(" GMRES" , KrylovJL_GMRES (kwargs... )),
257
- # ("BICGSTAB",KrylovJL_BICGSTAB(kwargs...)),
258
- (" MINRES" , KrylovJL_MINRES (kwargs... )))
259
- @testset " $(alg[1 ]) " begin
260
- test_interface (alg[2 ], prob1, prob2)
274
+ # ("BICGSTAB",KrylovJL_BICGSTAB(kwargs...)),
275
+ (" MINRES" , KrylovJL_MINRES (kwargs... ))
276
+ )
277
+ for (name, algorithm) in algorithms
278
+ @testset " $name " begin
279
+ test_interface (algorithm, prob1, prob2)
280
+ test_interface (algorithm, prob3, prob4)
261
281
end
262
282
end
263
283
end
274
294
)
275
295
@testset " $(alg[1 ]) " begin
276
296
test_interface (alg[2 ], prob1, prob2)
297
+ test_interface (alg[2 ], prob3, prob4)
277
298
end
278
299
end
279
300
end
287
308
(" GMRES" , KrylovKitJL_GMRES (kwargs... )))
288
309
@testset " $(alg[1 ]) " begin
289
310
test_interface (alg[2 ], prob1, prob2)
311
+ test_interface (alg[2 ], prob3, prob4)
290
312
end
291
313
@test alg[2 ] isa KrylovKitJL
292
314
end
0 commit comments