11using SparseDiffTools, ForwardDiff, FiniteDiff, Zygote, IterativeSolvers
22using LinearAlgebra, Test
3- import SciMLOperators: update_coefficients, update_coefficients!
43
54using Random
65Random. seed! (123 )
@@ -85,22 +84,28 @@ update_coefficients!(f, x, 1.0, 1.0)
8584@test L * v ≈ auto_jacvec (f, x, v)
8685@test mul! (dy, L, v) ≈ auto_jacvec (f, x, v)
8786dy= 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 )
8989@test mul! (dy, L, v) ≈ auto_jacvec (f, v, v)
9090dy= 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)
9193
9294L = JacVec (f, x, 1.0 , 1.0 ; autodiff = AutoFiniteDiff ())
9395update_coefficients! (f, x, 1.0 , 1.0 )
9496@test L * x ≈ num_jacvec (f, x, x)
9597@test L * v ≈ num_jacvec (f, x, v)
9698@test mul! (dy, L, v)≈ num_jacvec (f, x, v) rtol= 1e-6
9799dy= 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 )
99102@test mul! (dy, L, v)≈ num_jacvec (f, v, v) rtol= 1e-6
100103dy= 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
101106
102107out = similar (v)
103- gmres! (out, L, v)
108+ @test_nowarn gmres! (out, L, v)
104109
105110@info " HesVec"
106111
@@ -113,9 +118,12 @@ num_hesvec(g, x, x)
113118@test L * v ≈ num_hesvec (g, x, v) rtol= 1e-2
114119@test mul! (dy, L, v)≈ num_hesvec (g, x, v) rtol= 1e-2
115120dy= 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 )
117123@test mul! (dy, L, v)≈ num_hesvec (g, v, v) rtol= 1e-2
118124dy= 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
119127
120128L = HesVec (g, x, 1.0 , 1.0 )
121129update_coefficients! (g, x, 1.0 , 1.0 )
@@ -125,9 +133,12 @@ num_hesvec(g, x, x)
125133@test L * v ≈ numauto_hesvec (g, x, v)
126134@test mul! (dy, L, v)≈ numauto_hesvec (g, x, v) rtol= 1e-8
127135dy= 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 )
129138@test mul! (dy, L, v)≈ numauto_hesvec (g, v, v) rtol= 1e-8
130139dy= 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
131142
132143out = similar (v)
133144gmres! (out, L, v)
@@ -141,9 +152,12 @@ update_coefficients!(g, x, 1.0, 1.0)
141152@test L * v ≈ autoback_hesvec (g, x, v)
142153@test mul! (dy, L, v)≈ autoback_hesvec (g, x, v) rtol= 1e-8
143154dy= 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 )
145157@test mul! (dy, L, v)≈ autoback_hesvec (g, v, v) rtol= 1e-8
146158dy= 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
147161
148162out = similar (v)
149163gmres! (out, L, v)
@@ -159,20 +173,26 @@ update_coefficients!(g, x, 1.0, 1.0)
159173@test L * v ≈ num_hesvec (g, x, v) rtol= 1e-2
160174@test mul! (dy, L, v)≈ num_hesvec (g, x, v) rtol= 1e-2
161175dy= 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
164177@test mul! (dy, L, v)≈ num_hesvec (g, v, v) rtol= 1e-2
165178dy= 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
166181
167182L = HesVecGrad (h, x, 1.0 , 1.0 )
168- update_coefficients! (h, x, 1.0 , 1.0 )
169183update_coefficients! (g, x, 1.0 , 1.0 )
184+ update_coefficients! (h, x, 1.0 , 1.0 )
170185@test L * x ≈ autonum_hesvec (g, x, x)
171186@test L * v ≈ numauto_hesvec (g, x, v)
172187@test mul! (dy, L, v)≈ numauto_hesvec (g, x, v) rtol= 1e-8
173188dy= 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
176190@test mul! (dy, L, v)≈ numauto_hesvec (g, v, v) rtol= 1e-8
177191dy= 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)
178198#
0 commit comments