1
1
using SparseDiffTools, ForwardDiff, FiniteDiff, Zygote, IterativeSolvers
2
2
using LinearAlgebra, Test
3
- import SciMLOperators: update_coefficients, update_coefficients!
4
3
5
4
using Random
6
5
Random. seed! (123 )
@@ -85,22 +84,28 @@ update_coefficients!(f, x, 1.0, 1.0)
85
84
@test L * v ≈ auto_jacvec (f, x, v)
86
85
@test mul! (dy, L, v) ≈ auto_jacvec (f, x, v)
87
86
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b) ≈ a* auto_jacvec (f,x,v) + b* _dy
88
- update_coefficients_for_test! (L, v, 3.0 , 4.0 )
87
+ update_coefficients! (L, v, 3.0 , 4.0 )
88
+ update_coefficients! (f, v, 3.0 , 4.0 )
89
89
@test mul! (dy, L, v) ≈ auto_jacvec (f, v, v)
90
90
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b) ≈ a* auto_jacvec (f,x,v) + b* _dy
91
+ update_coefficients! (f, v, 5.0 , 6.0 )
92
+ @test L (dy, v, 5.0 , 6.0 ) ≈ auto_jacvec (f,x,v)
91
93
92
94
L = JacVec (f, x, 1.0 , 1.0 ; autodiff = AutoFiniteDiff ())
93
95
update_coefficients! (f, x, 1.0 , 1.0 )
94
96
@test L * x ≈ num_jacvec (f, x, x)
95
97
@test L * v ≈ num_jacvec (f, x, v)
96
98
@test mul! (dy, L, v)≈ num_jacvec (f, x, v) rtol= 1e-6
97
99
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b) ≈ a* num_jacvec (f,x,v) + b* _dy rtol= 1e-6
98
- update_coefficients_for_test! (L, v, 3.0 , 4.0 )
100
+ update_coefficients! (L, v, 3.0 , 4.0 )
101
+ update_coefficients! (f, v, 3.0 , 4.0 )
99
102
@test mul! (dy, L, v)≈ num_jacvec (f, v, v) rtol= 1e-6
100
103
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b) ≈ a* num_jacvec (f,x,v) + b* _dy rtol= 1e-6
104
+ update_coefficients! (f, v, 5.0 , 6.0 )
105
+ @test L (dy, v, 5.0 , 6.0 ) ≈ num_jacvec (f,x,v) rtol= 1e-6
101
106
102
107
out = similar (v)
103
- gmres! (out, L, v)
108
+ @test_nowarn gmres! (out, L, v)
104
109
105
110
@info " HesVec"
106
111
@@ -113,9 +118,12 @@ num_hesvec(g, x, x)
113
118
@test L * v ≈ num_hesvec (g, x, v) rtol= 1e-2
114
119
@test mul! (dy, L, v)≈ num_hesvec (g, x, v) rtol= 1e-2
115
120
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b) ≈ a* num_hesvec (g,x,v) + b* _dy rtol= 1e-2
116
- update_coefficients_for_test! (L, v, 3.0 , 4.0 )
121
+ update_coefficients! (L, v, 3.0 , 4.0 )
122
+ update_coefficients! (g, v, 3.0 , 4.0 )
117
123
@test mul! (dy, L, v)≈ num_hesvec (g, v, v) rtol= 1e-2
118
124
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b) ≈ a* num_hesvec (g,x,v) + b* _dy rtol= 1e-2
125
+ update_coefficients! (g, v, 5.0 , 6.0 )
126
+ @test L (dy, v, 5.0 , 6.0 ) ≈ num_hesvec (g,x,v) rtol= 1e-2
119
127
120
128
L = HesVec (g, x, 1.0 , 1.0 )
121
129
update_coefficients! (g, x, 1.0 , 1.0 )
@@ -125,9 +133,12 @@ num_hesvec(g, x, x)
125
133
@test L * v ≈ numauto_hesvec (g, x, v)
126
134
@test mul! (dy, L, v)≈ numauto_hesvec (g, x, v) rtol= 1e-8
127
135
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* numauto_hesvec (g,x,v)+ b* _dy rtol= 1e-8
128
- update_coefficients_for_test! (L, v, 3.0 , 4.0 )
136
+ update_coefficients! (L, v, 3.0 , 4.0 )
137
+ update_coefficients! (g, v, 3.0 , 4.0 )
129
138
@test mul! (dy, L, v)≈ numauto_hesvec (g, v, v) rtol= 1e-8
130
139
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* numauto_hesvec (g,x,v)+ b* _dy rtol= 1e-8
140
+ update_coefficients! (g, v, 5.0 , 6.0 )
141
+ @test L (dy, v, 5.0 , 6.0 ) ≈ numauto_hesvec (g,x,v) rtol= 1e-2
131
142
132
143
out = similar (v)
133
144
gmres! (out, L, v)
@@ -141,9 +152,12 @@ update_coefficients!(g, x, 1.0, 1.0)
141
152
@test L * v ≈ autoback_hesvec (g, x, v)
142
153
@test mul! (dy, L, v)≈ autoback_hesvec (g, x, v) rtol= 1e-8
143
154
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* autoback_hesvec (g,x,v)+ b* _dy rtol= 1e-8
144
- update_coefficients_for_test! (L, v, 3.0 , 4.0 )
155
+ update_coefficients! (L, v, 3.0 , 4.0 )
156
+ update_coefficients! (g, v, 3.0 , 4.0 )
145
157
@test mul! (dy, L, v)≈ autoback_hesvec (g, v, v) rtol= 1e-8
146
158
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* autoback_hesvec (g,x,v)+ b* _dy rtol= 1e-8
159
+ update_coefficients! (g, v, 5.0 , 6.0 )
160
+ @test L (dy, v, 5.0 , 6.0 ) ≈ autoback_hesvec (g,x,v) rtol= 1e-2
147
161
148
162
out = similar (v)
149
163
gmres! (out, L, v)
@@ -159,20 +173,26 @@ update_coefficients!(g, x, 1.0, 1.0)
159
173
@test L * v ≈ num_hesvec (g, x, v) rtol= 1e-2
160
174
@test mul! (dy, L, v)≈ num_hesvec (g, x, v) rtol= 1e-2
161
175
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* num_hesvec (g,x,v)+ b* _dy rtol= 1e-2
162
- update_coefficients_for_test! (L, v, 3.0 , 4.0 )
163
- update_coefficients! (g, x, 3.0 , 4.0 )
176
+ for op in (L, g, h) update_coefficients! (op, v, 3.0 , 4.0 ) end
164
177
@test mul! (dy, L, v)≈ num_hesvec (g, v, v) rtol= 1e-2
165
178
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* num_hesvec (g,x,v)+ b* _dy rtol= 1e-2
179
+ update_coefficients! (g, v, 5.0 , 6.0 )
180
+ @test L (dy, v, 5.0 , 6.0 ) ≈ num_hesvec (g,x,v) rtol= 1e-2
166
181
167
182
L = HesVecGrad (h, x, 1.0 , 1.0 )
168
- update_coefficients! (h, x, 1.0 , 1.0 )
169
183
update_coefficients! (g, x, 1.0 , 1.0 )
184
+ update_coefficients! (h, x, 1.0 , 1.0 )
170
185
@test L * x ≈ autonum_hesvec (g, x, x)
171
186
@test L * v ≈ numauto_hesvec (g, x, v)
172
187
@test mul! (dy, L, v)≈ numauto_hesvec (g, x, v) rtol= 1e-8
173
188
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* numauto_hesvec (g,x,v)+ b* _dy rtol= 1e-8
174
- update_coefficients_for_test! (L, v, 3.0 , 4.0 )
175
- update_coefficients! (g, x, 3.0 , 4.0 )
189
+ for op in (L, g, h) update_coefficients! (op, v, 3.0 , 4.0 ) end
176
190
@test mul! (dy, L, v)≈ numauto_hesvec (g, v, v) rtol= 1e-8
177
191
dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* numauto_hesvec (g,x,v)+ b* _dy rtol= 1e-8
192
+ update_coefficients! (g, v, 5.0 , 6.0 )
193
+ update_coefficients! (h, v, 5.0 , 6.0 )
194
+ @test L (dy, v, 5.0 , 6.0 ) ≈ num_hesvec (g,x,v) rtol= 1e-2
195
+
196
+ out = similar (v)
197
+ gmres! (out, L, v)
178
198
#
0 commit comments