2525# Define state-dependent functions for operator tests
2626
2727include (" update_coeffs_testutils.jl" )
28- f = WrapFunc (_f, ones (N), 1.0 , 1.0 )
29- g = WrapFunc (_g, ones (N), 1.0 , 1.0 )
30- h = WrapFunc (_h, ones (N), 1.0 , 1.0 )
28+ f = WrapFunc (_f, 1.0 , 1.0 )
29+ g = WrapFunc (_g, 1.0 , 1.0 )
30+ h = WrapFunc (_h, 1.0 , 1.0 )
3131
3232# ##
3333
@@ -80,6 +80,7 @@ cache4 = ForwardDiff.Dual{typeof(ForwardDiff.Tag(Nothing, eltype(x))), eltype(x)
8080@info " JacVec"
8181
8282L = JacVec (f, x, 1.0 , 1.0 )
83+ update_coefficients! (f, x, 1.0 , 1.0 )
8384@test L * x ≈ auto_jacvec (f, x, x)
8485@test L * v ≈ auto_jacvec (f, x, v)
8586@test mul! (dy, L, v) ≈ auto_jacvec (f, x, v)
@@ -89,6 +90,7 @@ update_coefficients_for_test!(L, v, 3.0, 4.0)
8990dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b) ≈ a* auto_jacvec (f,x,v) + b* _dy
9091
9192L = JacVec (f, x, 1.0 , 1.0 ; autodiff = AutoFiniteDiff ())
93+ update_coefficients! (f, x, 1.0 , 1.0 )
9294@test L * x ≈ num_jacvec (f, x, x)
9395@test L * v ≈ num_jacvec (f, x, v)
9496@test mul! (dy, L, v)≈ num_jacvec (f, x, v) rtol= 1e-6
@@ -105,15 +107,20 @@ gmres!(out, L, v)
105107x = rand (N)
106108v = rand (N)
107109L = HesVec (g, x, 1.0 , 1.0 , autodiff = AutoFiniteDiff ())
108- @test L * x ≈ num_hesvec (g, x, x)
109- @test L * v ≈ num_hesvec (g, x, v)
110+ update_coefficients! (g, x, 1.0 , 1.0 )
111+ @test L * x ≈ num_hesvec (g, x, x) rtol= 1e-2
112+ num_hesvec (g, x, x)
113+ @test L * v ≈ num_hesvec (g, x, v) rtol= 1e-2
110114@test mul! (dy, L, v)≈ num_hesvec (g, x, v) rtol= 1e-2
111115dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b) ≈ a* num_hesvec (g,x,v) + b* _dy rtol= 1e-2
112116update_coefficients_for_test! (L, v, 3.0 , 4.0 )
113117@test mul! (dy, L, v)≈ num_hesvec (g, v, v) rtol= 1e-2
114118dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b) ≈ a* num_hesvec (g,x,v) + b* _dy rtol= 1e-2
115119
116120L = HesVec (g, x, 1.0 , 1.0 )
121+ update_coefficients! (g, x, 1.0 , 1.0 )
122+ numauto_hesvec (g, x, x)
123+ num_hesvec (g, x, x)
117124@test L * x ≈ numauto_hesvec (g, x, x)
118125@test L * v ≈ numauto_hesvec (g, x, v)
119126@test mul! (dy, L, v)≈ numauto_hesvec (g, x, v) rtol= 1e-8
@@ -129,6 +136,7 @@ x = rand(N)
129136v = rand (N)
130137
131138L = HesVec (g, x, 1.0 , 1.0 ; autodiff = AutoZygote ())
139+ update_coefficients! (g, x, 1.0 , 1.0 )
132140@test L * x ≈ autoback_hesvec (g, x, x)
133141@test L * v ≈ autoback_hesvec (g, x, v)
134142@test mul! (dy, L, v)≈ autoback_hesvec (g, x, v) rtol= 1e-8
@@ -145,23 +153,26 @@ gmres!(out, L, v)
145153x = rand (N)
146154v = rand (N)
147155L = HesVecGrad (h, x, 1.0 , 1.0 ; autodiff = AutoFiniteDiff ())
156+ update_coefficients! (h, x, 1.0 , 1.0 )
157+ update_coefficients! (g, x, 1.0 , 1.0 )
148158@test L * x ≈ num_hesvec (g, x, x) rtol= 1e-2
149159@test L * v ≈ num_hesvec (g, x, v) rtol= 1e-2
150160@test mul! (dy, L, v)≈ num_hesvec (g, x, v) rtol= 1e-2
151161dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* num_hesvec (g,x,v)+ b* _dy rtol= 1e-2
152162update_coefficients_for_test! (L, v, 3.0 , 4.0 )
163+ update_coefficients! (g, x, 3.0 , 4.0 )
153164@test mul! (dy, L, v)≈ num_hesvec (g, v, v) rtol= 1e-2
154165dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* num_hesvec (g,x,v)+ b* _dy rtol= 1e-2
155166
156167L = HesVecGrad (h, x, 1.0 , 1.0 )
168+ update_coefficients! (h, x, 1.0 , 1.0 )
169+ update_coefficients! (g, x, 1.0 , 1.0 )
157170@test L * x ≈ autonum_hesvec (g, x, x)
158171@test L * v ≈ numauto_hesvec (g, x, v)
159172@test mul! (dy, L, v)≈ numauto_hesvec (g, x, v) rtol= 1e-8
160173dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* numauto_hesvec (g,x,v)+ b* _dy rtol= 1e-8
161174update_coefficients_for_test! (L, v, 3.0 , 4.0 )
175+ update_coefficients! (g, x, 3.0 , 4.0 )
162176@test mul! (dy, L, v)≈ numauto_hesvec (g, v, v) rtol= 1e-8
163177dy= rand (N);_dy= copy (dy);@test mul! (dy,L,v,a,b)≈ a* numauto_hesvec (g,x,v)+ b* _dy rtol= 1e-8
164-
165- out = similar (v)
166- gmres! (out, L, v)
167178#
0 commit comments