11using SparseDiffTools, ForwardDiff, FiniteDiff, Zygote, IterativeSolvers
22using LinearAlgebra, Test
3+ using SparseDiffTools: get_tag, DeivVecTag
34
45using Random
56Random. seed! (123 )
6- N = 300
77
8+ struct MyTag end
9+
10+ N = 300
811x = rand (N)
912v = rand (N)
1013
@@ -104,6 +107,10 @@ _dy = copy(dy);
104107update_coefficients! (f, v, 5.0 , 6.0 )
105108@test L (dy, v, 5.0 , 6.0 ) ≈ auto_jacvec (f, v, v)
106109
110+ # GMRES test
111+ out = similar (v)
112+ @test_nowarn gmres! (out, L, v)
113+
107114L = JacVec (f, copy (x), 1.0 , 1.0 ; autodiff = AutoFiniteDiff ())
108115update_coefficients! (f, x, 1.0 , 1.0 )
109116@test L * x ≈ num_jacvec (f, x, x)
@@ -121,9 +128,16 @@ _dy = copy(dy);
121128update_coefficients! (f, v, 5.0 , 6.0 )
122129@test L (dy, v, 5.0 , 6.0 )≈ num_jacvec (f, v, v) rtol= 1e-6
123130
131+ # GMRES test
124132out = similar (v)
125133@test_nowarn gmres! (out, L, v)
126134
135+ # Tag test
136+ L = JacVec (f, copy (x), 1.0 , 1.0 )
137+ @test get_tag (L. op. cache[1 ]) === ForwardDiff. Tag{DeivVecTag, eltype (x)}
138+ L = JacVec (f, copy (x), 1.0 , 1.0 ; tag = MyTag ())
139+ @test get_tag (L. op. cache[1 ]) === ForwardDiff. Tag{MyTag, eltype (x)}
140+
127141@info " HesVec"
128142
129143L = HesVec (g, copy (x), 1.0 , 1.0 , autodiff = AutoFiniteDiff ())
@@ -159,6 +173,7 @@ _dy = copy(dy);
159173update_coefficients! (g, v, 5.0 , 6.0 )
160174@test L (dy, v, 5.0 , 6.0 ) ≈ numauto_hesvec (g, v, v)
161175
176+ # GMRES test
162177out = similar (v)
163178gmres! (out, L, v)
164179
@@ -179,9 +194,16 @@ _dy = copy(dy);
179194update_coefficients! (g, v, 5.0 , 6.0 )
180195@test L (dy, v, 5.0 , 6.0 ) ≈ autoback_hesvec (g, v, v)
181196
197+ # GMRES test
182198out = similar (v)
183199gmres! (out, L, v)
184200
201+ # Tag test
202+ L = HesVec (g, copy (x), 1.0 , 1.0 ; autodiff = AutoZygote ())
203+ @test get_tag (L. op. cache[1 ]) === ForwardDiff. Tag{DeivVecTag, eltype (x)}
204+ L = HesVec (g, copy (x), 1.0 , 1.0 ; autodiff = AutoZygote (), tag = MyTag ())
205+ @test get_tag (L. op. cache[1 ]) === ForwardDiff. Tag{MyTag, eltype (x)}
206+
185207@info " HesVecGrad"
186208
187209L = HesVecGrad (h, copy (x), 1.0 , 1.0 ; autodiff = AutoFiniteDiff ())
@@ -203,6 +225,10 @@ _dy = copy(dy);
203225update_coefficients! (g, v, 5.0 , 6.0 )
204226@test L (dy, v, 5.0 , 6.0 )≈ num_hesvec (g, v, v) rtol= 1e-2
205227
228+ # GMRES test
229+ out = similar (v)
230+ gmres! (out, L, v)
231+
206232L = HesVecGrad (h, copy (x), 1.0 , 1.0 )
207233update_coefficients! (g, x, 1.0 , 1.0 )
208234update_coefficients! (h, x, 1.0 , 1.0 )
@@ -223,6 +249,7 @@ update_coefficients!(g, v, 5.0, 6.0)
223249update_coefficients! (h, v, 5.0 , 6.0 )
224250@test L (dy, v, 5.0 , 6.0 ) ≈ numauto_hesvec (g, v, v)
225251
252+ # GMRES test
226253out = similar (v)
227254gmres! (out, L, v)
228255
@@ -231,4 +258,10 @@ gmres!(out, L, v)
231258@test x ≈ x0
232259@test v ≈ v0
233260
261+ # Tag test
262+ L = HesVecGrad (g, copy (x), 1.0 , 1.0 )
263+ @test get_tag (L. op. cache[1 ]) === ForwardDiff. Tag{DeivVecTag, eltype (x)}
264+ L = HesVecGrad (g, copy (x), 1.0 , 1.0 ; tag = MyTag ())
265+ @test get_tag (L. op. cache[1 ]) === ForwardDiff. Tag{MyTag, eltype (x)}
266+
234267#
0 commit comments