@@ -223,24 +223,25 @@ function (L::FwdModeAutoDiffVecProd)(dv, v, p, t)
223223 L. vecprod! (dv, L. f, L. u, v, L. cache... )
224224end
225225
226- function JacVec (f, u:: AbstractArray , p = nothing , t = nothing ; autodiff = true )
226+ function JacVec (f, u:: AbstractArray , p = nothing , t = nothing ; autodiff = AutoForwardDiff () )
227227
228- if autodiff
228+ cache, vecprod, vecprod! = if autodiff isa AutoFiniteDiff
229+ cache1 = similar (u)
230+ cache2 = similar (u)
231+
232+ (cache1, cache2), num_jacvec, num_jacvec!
233+ elseif autodiff isa AutoForwardDiff
229234 cache1 = Dual{
230235 typeof (ForwardDiff. Tag (DeivVecTag (),eltype (u))), eltype (u), 1
231236 }. (u, ForwardDiff. Partials .(tuple .(u)))
232237
233238 cache2 = copy (cache1)
239+
240+ (cache1, cache2), auto_jacvec, auto_jacvec!
234241 else
235- cache1 = similar (u)
236- cache2 = similar (u)
242+ @error (" Set autodiff to either AutoForwardDiff(), or AutoFiniteDiff()" )
237243 end
238244
239- cache = (cache1, cache2,)
240-
241- vecprod = autodiff ? auto_jacvec : num_jacvec
242- vecprod! = autodiff ? auto_jacvec! : num_jacvec!
243-
244245 outofplace = static_hasmethod (f, typeof ((u,)))
245246 isinplace = static_hasmethod (f, typeof ((u, u,)))
246247
@@ -256,22 +257,23 @@ function JacVec(f, u::AbstractArray, p = nothing, t = nothing; autodiff = true)
256257 )
257258end
258259
259- function HesVec (f, u:: AbstractArray , p = nothing , t = nothing ; autodiff = true )
260+ function HesVec (f, u:: AbstractArray , p = nothing , t = nothing ; autodiff = AutoForwardDiff () )
260261
261- if autodiff
262- cache1 = ForwardDiff. GradientConfig (f, u)
263- cache2 = similar (u)
264- cache3 = similar (u)
265- else
262+ cache, vecprod, vecprod! = if autodiff isa AutoFiniteDiff
266263 cache1 = similar (u)
267264 cache2 = similar (u)
268265 cache3 = similar (u)
269- end
270266
271- cache = (cache1, cache2, cache3,)
267+ (cache1, cache2, cache3), num_hesvec, num_hesvec!
268+ elseif autodiff isa AutoForwardDiff
269+ cache1 = ForwardDiff. GradientConfig (f, u)
270+ cache2 = similar (u)
271+ cache3 = similar (u)
272272
273- vecprod = autodiff ? numauto_hesvec : num_hesvec
274- vecprod! = autodiff ? numauto_hesvec! : num_hesvec!
273+ (cache1, cache2, cache3), numauto_hesvec, numauto_hesvec!
274+ else
275+ @error (" Set autodiff to either AutoForwardDiff(), or AutoFiniteDiff()" )
276+ end
275277
276278 outofplace = static_hasmethod (f, typeof ((u,)))
277279 isinplace = static_hasmethod (f, typeof ((u,)))
@@ -288,24 +290,24 @@ function HesVec(f, u::AbstractArray, p = nothing, t = nothing; autodiff = true)
288290 )
289291end
290292
291- function HesVecGrad (f, u:: AbstractArray , p = nothing , t = nothing ; autodiff = true )
293+ function HesVecGrad (f, u:: AbstractArray , p = nothing , t = nothing ; autodiff = AutoForwardDiff ())
294+
295+ cache, vecprod, vecprod! = if autodiff isa AutoFiniteDiff
296+ cache1 = similar (u)
297+ cache2 = similar (u)
292298
293- if autodiff
299+ (cache1, cache2), num_hesvecgrad, num_hesvecgrad!
300+ elseif autodiff isa AutoForwardDiff
294301 cache1 = Dual{
295302 typeof (ForwardDiff. Tag (DeivVecTag (), eltype (u))), eltype (u), 1
296303 }. (u, ForwardDiff. Partials .(tuple .(u)))
297-
298304 cache2 = copy (cache1)
305+
306+ (cache1, cache2), auto_hesvecgrad, auto_hesvecgrad!
299307 else
300- cache1 = similar (u)
301- cache2 = similar (u)
308+ @error (" Set autodiff to either AutoForwardDiff(), or AutoFiniteDiff()" )
302309 end
303310
304- cache = (cache1, cache2,)
305-
306- vecprod = autodiff ? auto_hesvecgrad : num_hesvecgrad
307- vecprod! = autodiff ? auto_hesvecgrad! : num_hesvecgrad!
308-
309311 outofplace = static_hasmethod (f, typeof ((u,)))
310312 isinplace = static_hasmethod (f, typeof ((u, u,)))
311313
0 commit comments