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

Commit babd518

Browse files
committed
rm BackHesVec, and move autoback_hesvec to HesVec(autodiff=AutoZygote())
1 parent bc46b6b commit babd518

File tree

3 files changed

+5
-39
lines changed

3 files changed

+5
-39
lines changed

src/SparseDiffTools.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export contract_color,
4949
autonum_hesvec, autonum_hesvec!,
5050
num_hesvecgrad, num_hesvecgrad!,
5151
auto_hesvecgrad, auto_hesvecgrad!,
52-
JacVec, HesVec, BackHesVec, HesVecGrad, VecJac,
52+
JacVec, HesVec, HesVecGrad, VecJac,
5353
update_coefficients, update_coefficients!,
5454
value!
5555

src/differentiation/jaches_products.jl

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -271,32 +271,6 @@ function HesVec(f, u::AbstractArray, p = nothing, t = nothing; autodiff = AutoFo
271271
cache3 = similar(u)
272272

273273
(cache1, cache2, cache3), numauto_hesvec, numauto_hesvec!
274-
else
275-
@error("Set autodiff to either AutoForwardDiff(), or AutoFiniteDiff()")
276-
end
277-
278-
outofplace = static_hasmethod(f, typeof((u,)))
279-
isinplace = static_hasmethod(f, typeof((u,)))
280-
281-
if !(isinplace) & !(outofplace)
282-
error("$f must have signature f(u).")
283-
end
284-
285-
L = FwdModeAutoDiffVecProd(f, u, cache, vecprod, vecprod!)
286-
287-
FunctionOperator(L, u, u;
288-
isinplace = isinplace, outofplace = outofplace,
289-
p = p, t = t, islinear = true,
290-
)
291-
end
292-
293-
function BackHesVec(f, u::AbstractArray, p = nothing, t = nothing; autodiff = AutoFiniteDiff())
294-
295-
cache, vecprod, vecprod! = if autodiff isa AutoFiniteDiff
296-
cache1 = similar(u)
297-
cache2 = similar(u)
298-
299-
(cache1, cache2), numback_hesvec, numback_hesvec!
300274
elseif autodiff isa AutoZygote
301275
@assert static_hasmethod(autoback_hesvec, typeof((f, u, u))) "To use AutoZygote() AD, first load Zygote with `using Zygote`, or `import Zygote`"
302276

@@ -306,6 +280,8 @@ function BackHesVec(f, u::AbstractArray, p = nothing, t = nothing; autodiff = Au
306280
cache2 = copy(u)
307281

308282
(cache1, cache2), autoback_hesvec, autoback_hesvec!
283+
else
284+
@error("Set autodiff to either AutoForwardDiff(), or AutoFiniteDiff()")
309285
end
310286

311287
outofplace = static_hasmethod(f, typeof((u,)))

test/test_jaches_products.jl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,12 @@ dy=rand(N);_dy=copy(dy);@test mul!(dy,L,v,a,b)≈a*numauto_hesvec(g,x,v)+b*_dy r
113113
out = similar(v)
114114
gmres!(out, L, v)
115115

116-
@info "BackHesVec"
117116
using Zygote
117+
118118
x = rand(N)
119119
v = rand(N)
120120

121-
L = BackHesVec(g, x)
122-
@test L * x numback_hesvec(g, x, x) rtol = 1e-2
123-
@test L * v numback_hesvec(g, x, v) rtol = 1e-2
124-
@test mul!(dy, L, v)numback_hesvec(g, x, v) rtol=1e-2
125-
dy=rand(N);_dy=copy(dy);@test mul!(dy,L,v,a,b) a*numback_hesvec(g,x,v) + b*_dy rtol=1e-2
126-
update_coefficients!(L, v, nothing, 0.0)
127-
@test mul!(dy, L, v)numback_hesvec(g, v, v) rtol=1e-2
128-
dy=rand(N);_dy=copy(dy);@test mul!(dy,L,v,a,b) a*numback_hesvec(g,x,v) + b*_dy rtol=1e-2
129-
130-
L = BackHesVec(g, x, autodiff = AutoZygote())
121+
L = HesVec(g, x, autodiff = AutoZygote())
131122
@test L * x autoback_hesvec(g, x, x)
132123
@test L * v autoback_hesvec(g, x, v)
133124
@test mul!(dy, L, v)autoback_hesvec(g, x, v) rtol=1e-8
@@ -139,7 +130,6 @@ dy=rand(N);_dy=copy(dy);@test mul!(dy,L,v,a,b)≈a*autoback_hesvec(g,x,v)+b*_dy
139130
out = similar(v)
140131
gmres!(out, L, v)
141132

142-
143133
@info "HesVecGrad"
144134

145135
x = rand(N)

0 commit comments

Comments
 (0)