Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit e77e83f

Browse files
committed
add tests
1 parent 61bcde0 commit e77e83f

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

test/test_jaches_products.jl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using SparseDiffTools, ForwardDiff, FiniteDiff, Zygote, IterativeSolvers
22
using LinearAlgebra, Test
3+
using SparseDiffTools: get_tag, DeivVecTag
34

45
using Random
56
Random.seed!(123)
6-
N = 300
77

8+
struct MyTag end
9+
10+
N = 300
811
x = rand(N)
912
v = rand(N)
1013

@@ -104,6 +107,10 @@ _dy = copy(dy);
104107
update_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+
107114
L = JacVec(f, copy(x), 1.0, 1.0; autodiff = AutoFiniteDiff())
108115
update_coefficients!(f, x, 1.0, 1.0)
109116
@test L * x num_jacvec(f, x, x)
@@ -121,9 +128,16 @@ _dy = copy(dy);
121128
update_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
124132
out = 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

129143
L = HesVec(g, copy(x), 1.0, 1.0, autodiff = AutoFiniteDiff())
@@ -159,6 +173,7 @@ _dy = copy(dy);
159173
update_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
162177
out = similar(v)
163178
gmres!(out, L, v)
164179

@@ -179,9 +194,16 @@ _dy = copy(dy);
179194
update_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
182198
out = similar(v)
183199
gmres!(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

187209
L = HesVecGrad(h, copy(x), 1.0, 1.0; autodiff = AutoFiniteDiff())
@@ -203,6 +225,10 @@ _dy = copy(dy);
203225
update_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+
206232
L = HesVecGrad(h, copy(x), 1.0, 1.0)
207233
update_coefficients!(g, x, 1.0, 1.0)
208234
update_coefficients!(h, x, 1.0, 1.0)
@@ -223,6 +249,7 @@ update_coefficients!(g, v, 5.0, 6.0)
223249
update_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
226253
out = similar(v)
227254
gmres!(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

Comments
 (0)