1
1
function SciMLBase. solve (cache:: LinearCache , alg:: AbstractFactorization ; kwargs... )
2
2
if cache. isfresh
3
- fact = init_cacheval (alg, cache. A, cache. b, cache. u)
3
+ fact = do_factorization (alg, cache. A, cache. b, cache. u)
4
4
cache = set_cacheval (cache, fact)
5
5
end
6
6
7
7
y = ldiv! (cache. u, cache. cacheval, cache. b)
8
8
SciMLBase. build_linear_solution (alg,y,nothing ,cache)
9
9
end
10
10
11
+ # Bad fallback: will fail if `A` is just a stand-in
12
+ # This should instead just create the factorization type.
13
+ init_cacheval (alg:: AbstractFactorization , A, b, u) = do_factorization (alg, A, b, u)
14
+
11
15
# # LU Factorizations
12
16
13
17
struct LUFactorization{P} <: AbstractFactorization
@@ -23,7 +27,7 @@ function LUFactorization()
23
27
LUFactorization (pivot)
24
28
end
25
29
26
- function init_cacheval (alg:: LUFactorization , A, b, u)
30
+ function do_factorization (alg:: LUFactorization , A, b, u)
27
31
A isa Union{AbstractMatrix,AbstractDiffEqOperator} ||
28
32
error (" LU is not defined for $(typeof (A)) " )
29
33
@@ -34,12 +38,14 @@ function init_cacheval(alg::LUFactorization, A, b, u)
34
38
return fact
35
39
end
36
40
41
+ init_cacheval (alg:: LUFactorization , A, b, u) = ArrayInterface. lu_instance (A)
42
+
37
43
# This could be a GenericFactorization perhaps?
38
44
Base. @kwdef struct UMFPACKFactorization <: AbstractFactorization
39
45
reuse_symbolic:: Bool = true
40
46
end
41
47
42
- function init_cacheval (:: UMFPACKFactorization , A, b, u)
48
+ function do_factorization (:: UMFPACKFactorization , A, b, u)
43
49
if A isa AbstractDiffEqOperator
44
50
A = A. A
45
51
end
@@ -62,7 +68,7 @@ function SciMLBase.solve(cache::LinearCache, alg::UMFPACKFactorization)
62
68
SuiteSparse. UMFPACK. umfpack_symbolic! (cache. cacheval)
63
69
fact = lu! (cache. cacheval, A)
64
70
else
65
- fact = init_cacheval (alg, A, cache. b, cache. u)
71
+ fact = do_factorization (alg, A, cache. b, cache. u)
66
72
end
67
73
cache = set_cacheval (cache, fact)
68
74
end
@@ -75,7 +81,7 @@ Base.@kwdef struct KLUFactorization <: AbstractFactorization
75
81
reuse_symbolic:: Bool = true
76
82
end
77
83
78
- function init_cacheval (:: KLUFactorization , A, b, u)
84
+ function do_factorization (:: KLUFactorization , A, b, u)
79
85
if A isa AbstractDiffEqOperator
80
86
A = A. A
81
87
end
@@ -98,7 +104,7 @@ function SciMLBase.solve(cache::LinearCache, alg::KLUFactorization)
98
104
KLU. klu_analyze! (cache. cacheval)
99
105
fact = klu! (cache. cacheval, A)
100
106
else
101
- fact = init_cacheval (alg, A, cache. b, cache. u)
107
+ fact = do_factorization (alg, A, cache. b, cache. u)
102
108
end
103
109
cache = set_cacheval (cache, fact)
104
110
end
@@ -123,7 +129,7 @@ function QRFactorization()
123
129
QRFactorization (pivot, 16 )
124
130
end
125
131
126
- function init_cacheval (alg:: QRFactorization , A, b, u)
132
+ function do_factorization (alg:: QRFactorization , A, b, u)
127
133
A isa Union{AbstractMatrix,AbstractDiffEqOperator} ||
128
134
error (" QR is not defined for $(typeof (A)) " )
129
135
143
149
144
150
SVDFactorization () = SVDFactorization (false , LinearAlgebra. DivideAndConquer ())
145
151
146
- function init_cacheval (alg:: SVDFactorization , A, b, u)
152
+ function do_factorization (alg:: SVDFactorization , A, b, u)
147
153
A isa Union{AbstractMatrix,AbstractDiffEqOperator} ||
148
154
error (" SVD is not defined for $(typeof (A)) " )
149
155
164
170
GenericFactorization (;fact_alg = LinearAlgebra. factorize) =
165
171
GenericFactorization (fact_alg)
166
172
167
- function init_cacheval (alg:: GenericFactorization , A, b, u)
173
+ function do_factorization (alg:: GenericFactorization , A, b, u)
168
174
A isa Union{AbstractMatrix,AbstractDiffEqOperator} ||
169
175
error (" GenericFactorization is not defined for $(typeof (A)) " )
170
176
0 commit comments