@@ -15,18 +15,20 @@ Let's create a new wrapper for a simple LU-factorization which uses only the
15
15
basic machinery. A simplified version is:
16
16
17
17
``` julia
18
- struct MyLUFactorization{P} <: SciMLBase.AbstractLinearAlgorithm end
18
+ struct MyLUFactorization{P} <: LinearSolve.SciMLLinearSolveAlgorithm end
19
19
20
- function init_cacheval (alg:: MyLUFactorization , A, b, u, Pl, Pr, maxiters, abstol, reltol,
21
- verbose)
20
+ function LinearSolve . init_cacheval (alg:: MyLUFactorization , A, b, u, Pl, Pr, maxiters:: Int , abstol, reltol,
21
+ verbose:: Bool , assump :: LinearSolve.OperatorAssumptions )
22
22
lu! (convert (AbstractMatrix, A))
23
23
end
24
24
25
- function SciMLBase. solve! (cache:: LinearCache , alg:: MyLUFactorization ; kwargs... )
25
+ function SciMLBase. solve! (cache:: LinearSolve. LinearCache , alg:: MyLUFactorization ; kwargs... )
26
26
if cache. isfresh
27
+ A = cache. A
27
28
A = convert (AbstractMatrix, A)
28
29
fact = lu! (A)
29
- cache = set_cacheval (cache, fact)
30
+ cache. cacheval = fact
31
+ cache. isfresh = false
30
32
end
31
33
y = ldiv! (cache. u, cache. cacheval, cache. b)
32
34
SciMLBase. build_linear_solution (alg, y, nothing , cache)
@@ -39,7 +41,7 @@ need to cache their own things, and so there's one value `cacheval` that is
39
41
for the algorithms to modify. The function:
40
42
41
43
``` julia
42
- init_cacheval (alg:: MyLUFactorization , A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose)
44
+ init_cacheval (alg:: MyLUFactorization , A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose, assump )
43
45
```
44
46
45
47
is what is called at ` init ` time to create the first ` cacheval ` . Note that this
@@ -51,13 +53,13 @@ LU-factorization to get an `LU{T, Matrix{T}}` which it puts into the `cacheval`
51
53
so it is typed for future use.
52
54
53
55
After the ` init_cacheval ` , the only thing left to do is to define
54
- ` SciMLBase.solve(cache::LinearCache, alg::MyLUFactorization) ` . Many algorithms
56
+ ` SciMLBase.solve! (cache::LinearCache, alg::MyLUFactorization) ` . Many algorithms
55
57
may use a lazy matrix-free representation of the operator ` A ` . Thus, if the
56
58
algorithm requires a concrete matrix, like LU-factorization does, the algorithm
57
59
should ` convert(AbstractMatrix,cache.A) ` . The flag ` cache.isfresh ` states whether
58
60
` A ` has changed since the last ` solve ` . Since we only need to factorize when
59
61
` A ` is new, the factorization part of the algorithm is done in a ` if cache.isfresh ` .
60
- ` cache = set_cacheval( cache, fact) ` puts the new factorization into the cache,
62
+ ` cache.cacheval = fact; cache.isfresh = false ` puts the new factorization into the cache,
61
63
so it's updated for future solves. Then ` y = ldiv!(cache.u, cache.cacheval, cache.b) `
62
64
performs the solve and a linear solution is returned via
63
65
` SciMLBase.build_linear_solution(alg,y,nothing,cache) ` .
0 commit comments