@@ -27,20 +27,20 @@ function test_interface(alg, prob1, prob2)
27
27
b2 = prob2. b
28
28
x2 = prob2. u0
29
29
30
- y = solve (prob1, alg; cache_kwargs... )
31
- @test A1 * y ≈ b1
30
+ sol = solve (prob1, alg; cache_kwargs... )
31
+ @test A1 * sol . u ≈ b1
32
32
33
33
cache = SciMLBase. init (prob1, alg; cache_kwargs... ) # initialize cache
34
- y = solve (cache)
35
- @test A1 * y ≈ b1
34
+ sol = solve (cache)
35
+ @test A1 * sol . u ≈ b1
36
36
37
- cache = LinearSolve. set_A (cache, copy (A2))
38
- y = solve (cache; cache_kwargs... )
39
- @test A2 * y ≈ b1
37
+ cache = LinearSolve. set_A (cache, deepcopy (A2))
38
+ sol = solve (cache; cache_kwargs... )
39
+ @test A2 * sol . u ≈ b1
40
40
41
41
cache = LinearSolve. set_b (cache, b2)
42
- y = solve (cache; cache_kwargs... )
43
- @test A2 * y ≈ b2
42
+ sol = solve (cache; cache_kwargs... )
43
+ @test A2 * sol . u ≈ b2
44
44
45
45
return
46
46
end
@@ -359,26 +359,58 @@ end
359
359
b2 = rand (n)
360
360
x2 = zero (b1)
361
361
362
- function sol_func (A, b, u, p, newA, Pl, Pr, solverdata; verbose = true , kwargs... )
363
- if verbose == true
364
- println (" out-of-place solve" )
362
+ @testset " LinearSolveFunction" begin
363
+ function sol_func (A, b, u, p, newA, Pl, Pr, solverdata; verbose = true , kwargs... )
364
+ if verbose == true
365
+ println (" out-of-place solve" )
366
+ end
367
+ u = A \ b
365
368
end
366
- u = A \ b
367
- end
368
369
369
- function sol_func! (A, b, u, p, newA, Pl, Pr, solverdata; verbose = true , kwargs... )
370
- if verbose == true
371
- println (" in-place solve" )
370
+ function sol_func! (A, b, u, p, newA, Pl, Pr, solverdata; verbose = true , kwargs... )
371
+ if verbose == true
372
+ println (" in-place solve" )
373
+ end
374
+ ldiv! (u, A, b)
375
+ end
376
+
377
+ prob1 = LinearProblem (A1, b1; u0 = x1)
378
+ prob2 = LinearProblem (A1, b1; u0 = x1)
379
+
380
+ for alg in (LinearSolveFunction (sol_func),
381
+ LinearSolveFunction (sol_func!))
382
+ test_interface (alg, prob1, prob2)
372
383
end
373
- ldiv! (u, A, b)
374
384
end
375
385
376
- prob1 = LinearProblem (A1, b1; u0 = x1)
377
- prob2 = LinearProblem (A1, b1; u0 = x1)
386
+ @testset " DirectLdiv!" begin
387
+ function get_operator (A, u)
388
+ F = lu (A)
378
389
379
- for alg in (LinearSolveFunction (sol_func),
380
- LinearSolveFunction (sol_func!))
381
- test_interface (alg, prob1, prob2)
390
+ function f (du, u, p, t)
391
+ println (" using FunctionOperator mul!" )
392
+ mul! (du, A, u)
393
+ end
394
+
395
+ function fi (du, u, p, t)
396
+ println (" using FunctionOperator ldiv!" )
397
+ ldiv! (du, F, u)
398
+ end
399
+
400
+ FunctionOperator (f, u, u; isinplace= true , op_inverse= fi)
401
+ end
402
+
403
+ op1 = get_operator (A1, x1* 0 )
404
+ op2 = get_operator (A2, x2* 0 )
405
+
406
+ prob1 = LinearProblem (op1, b1; u0 = x1)
407
+ prob2 = LinearProblem (op2, b2; u0 = x2)
408
+
409
+ @test LinearSolve. defaultalg (op1, x1) isa DirectLdiv!
410
+ @test LinearSolve. defaultalg (op2, x2) isa DirectLdiv!
411
+
412
+ test_interface (DirectLdiv! (), prob1, prob2)
413
+ test_interface (nothing , prob1, prob2)
382
414
end
383
415
end
384
416
end # testset
0 commit comments