@@ -37,7 +37,17 @@ function set_p(cache, p)
37
37
# @set! cache.isfresh = true
38
38
end
39
39
40
- function SciMLBase. init (prob:: LinearProblem , alg; kwargs... )
40
+ function set_cacheval (cache:: LinearCache ,alg)
41
+ if cache. isfresh
42
+ @set! cache. cacheval = alg
43
+ @set! cache. isfresh = false
44
+ end
45
+ return cache
46
+ end
47
+
48
+ function SciMLBase. init (prob:: LinearProblem , alg;
49
+ alias_A = false , alias_b = false ,
50
+ kwargs... )
41
51
@unpack A, b, p = prob
42
52
if alg isa LUFactorization
43
53
fact = lu_instance (A)
@@ -48,41 +58,53 @@ function SciMLBase.init(prob::LinearProblem, alg; kwargs...)
48
58
end
49
59
Pr = nothing
50
60
Pl = nothing
61
+
62
+ A = alias_A ? A : copy (A)
63
+ b = alias_b ? b : copy (b)
64
+
51
65
cache = LinearCache {typeof(A),typeof(b),typeof(p),typeof(alg),Tfact,typeof(Pr),typeof(Pl)} (
52
66
A, b, p, alg, fact, true , Pr, Pl
53
67
)
54
68
return cache
55
69
end
56
70
57
- SciMLBase. solve! (prob:: LinearProblem , alg; kwargs... ) = solve! (init (prob, alg; kwargs... ))
58
- SciMLBase. solve! (cache) = solve! (cache, cache. alg)
71
+ SciMLBase. solve (prob:: LinearProblem , alg; kwargs... ) = solve (init (prob, alg; kwargs... ))
72
+ SciMLBase. solve (cache) = solve (cache, cache. alg)
59
73
60
74
struct LUFactorization{P} <: AbstractLinearAlgorithm
61
75
pivot:: P
62
76
end
63
- LUFactorization () = LUFactorization (Val (true ))
77
+ function LUFactorization ()
78
+ pivot = @static if VERSION < v " 1.7beta"
79
+ Val (true )
80
+ else
81
+ RowMaximum ()
82
+ end
83
+ LUFactorization (pivot)
84
+ end
64
85
65
- function SciMLBase. solve! (cache:: LinearCache , alg:: LUFactorization )
86
+ function SciMLBase. solve (cache:: LinearCache , alg:: LUFactorization )
66
87
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
88
+ cache = set_cacheval (cache,lu! (cache. A, alg. pivot))
71
89
ldiv! (cache. cacheval, cache. b)
72
90
end
73
91
74
92
struct QRFactorization{P} <: AbstractLinearAlgorithm
75
93
pivot:: P
76
94
blocksize:: Int
77
95
end
78
- QRFactorization () = QRFactorization (Val (false ), 16 )
96
+ function QRFactorization ()
97
+ pivot = @static if VERSION < v " 1.7beta"
98
+ Val (false )
99
+ else
100
+ NoPivot ()
101
+ end
102
+ QRFactorization (pivot, 16 )
103
+ end
79
104
80
- function SciMLBase. solve! (cache:: LinearCache , alg:: QRFactorization )
105
+ function SciMLBase. solve (cache:: LinearCache , alg:: QRFactorization )
81
106
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
107
+ cache = set_cacheval (cache,qr! (cache. A. A, alg. pivot; blocksize= alg. blocksize))
86
108
ldiv! (cache. cacheval, cache. b)
87
109
end
88
110
@@ -92,12 +114,9 @@ struct SVDFactorization{A} <: AbstractLinearAlgorithm
92
114
end
93
115
SVDFactorization () = SVDFactorization (false , LinearAlgebra. DivideAndConquer ())
94
116
95
- function SciMLBase. solve! (cache:: LinearCache , alg:: SVDFactorization )
117
+ function SciMLBase. solve (cache:: LinearCache , alg:: SVDFactorization )
96
118
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
119
+ cache = set_cacheval (cache,svd! (cache. A; full= alg. full, alg= alg. alg))
101
120
ldiv! (cache. cacheval, cache. b)
102
121
end
103
122
0 commit comments