@@ -37,6 +37,12 @@ function set_p(cache, p)
37
37
# @set! cache.isfresh = true
38
38
end
39
39
40
+ function set_cacheval (cache:: LinearCache ,alg)
41
+ if cache. isfresh
42
+ @set! cache. cacheval = alg
43
+ @set! cache. isfresh = false
44
+ end
45
+
40
46
function SciMLBase. init (prob:: LinearProblem , alg; kwargs... )
41
47
@unpack A, b, p = prob
42
48
if alg isa LUFactorization
@@ -54,20 +60,17 @@ function SciMLBase.init(prob::LinearProblem, alg; kwargs...)
54
60
return cache
55
61
end
56
62
57
- SciMLBase. solve! (prob:: LinearProblem , alg; kwargs... ) = solve! (init (prob, alg; kwargs... ))
58
- SciMLBase. solve! (cache) = solve! (cache, cache. alg)
63
+ SciMLBase. solve (prob:: LinearProblem , alg; kwargs... ) = solve (init (prob, alg; kwargs... ))
64
+ SciMLBase. solve (cache) = solve (cache, cache. alg)
59
65
60
66
struct LUFactorization{P} <: AbstractLinearAlgorithm
61
67
pivot:: P
62
68
end
63
69
LUFactorization () = LUFactorization (Val (true ))
64
70
65
- function SciMLBase. solve! (cache:: LinearCache , alg:: LUFactorization )
71
+ function SciMLBase. solve (cache:: LinearCache , alg:: LUFactorization )
66
72
cache. A isa Union{AbstractMatrix, AbstractDiffEqOperator} || error (" LU is not defined for $(typeof (prob. A)) " )
67
- if cache. isfresh
68
- @set! cache. cacheval = lu! (cache. A, alg. pivot)
69
- @set! cache. isfresh = false
70
- end
73
+ set_cacheval (cache,lu! (cache. A, alg. pivot))
71
74
ldiv! (cache. cacheval, cache. b)
72
75
end
73
76
@@ -77,12 +80,9 @@ struct QRFactorization{P} <: AbstractLinearAlgorithm
77
80
end
78
81
QRFactorization () = QRFactorization (Val (false ), 16 )
79
82
80
- function SciMLBase. solve! (cache:: LinearCache , alg:: QRFactorization )
83
+ function SciMLBase. solve (cache:: LinearCache , alg:: QRFactorization )
81
84
cache. A isa Union{AbstractMatrix, AbstractDiffEqOperator} || error (" QR is not defined for $(typeof (prob. A)) " )
82
- if cache. isfresh
83
- @set! cache. cacheval = qr! (cache. A. A, alg. pivot; blocksize= alg. blocksize)
84
- @set! cache. isfresh = false
85
- end
85
+ set_cacheval (cache,qr! (cache. A. A, alg. pivot; blocksize= alg. blocksize))
86
86
ldiv! (cache. cacheval, cache. b)
87
87
end
88
88
@@ -92,12 +92,9 @@ struct SVDFactorization{A} <: AbstractLinearAlgorithm
92
92
end
93
93
SVDFactorization () = SVDFactorization (false , LinearAlgebra. DivideAndConquer ())
94
94
95
- function SciMLBase. solve! (cache:: LinearCache , alg:: SVDFactorization )
95
+ function SciMLBase. solve (cache:: LinearCache , alg:: SVDFactorization )
96
96
cache. A isa Union{AbstractMatrix, AbstractDiffEqOperator} || error (" SVD is not defined for $(typeof (prob. A)) " )
97
- if cache. isfresh
98
- @set! cache. cacheval = svd! (cache. A; full= alg. full, alg= alg. alg)
99
- @set! cache. isfresh = false
100
- end
97
+ set_cacheval (cache,svd! (cache. A; full= alg. full, alg= alg. alg))
101
98
ldiv! (cache. cacheval, cache. b)
102
99
end
103
100
0 commit comments