@@ -264,26 +264,27 @@ f(du, u) # Otherwise
264
264
"""
265
265
function JacVec (f, u:: AbstractArray , p = nothing , t = nothing ; fu = nothing ,
266
266
autodiff = AutoForwardDiff (), tag = DeivVecTag (), kwargs... )
267
+ ff = JacFunctionWrapper (f, fu, u, p, t)
268
+ fu === nothing && (fu = __internal_oop (ff) ? ff (u) : u)
269
+
267
270
cache, vecprod, vecprod! = if autodiff isa AutoFiniteDiff
268
- cache1 = similar (u )
271
+ cache1 = similar (fu )
269
272
cache2 = similar (u)
270
273
271
274
(cache1, cache2), num_jacvec, num_jacvec!
272
275
elseif autodiff isa AutoForwardDiff
273
276
cache1 = Dual{
274
277
typeof (ForwardDiff. Tag (tag, eltype (u))), eltype (u), 1 ,
275
278
}. (u, ForwardDiff. Partials .(tuple .(u)))
276
-
277
- cache2 = copy (cache1)
279
+ cache2 = Dual{
280
+ typeof (ForwardDiff. Tag (tag, eltype (fu))), eltype (fu), 1 ,
281
+ }. (fu, ForwardDiff. Partials .(tuple .(fu)))
278
282
279
283
(cache1, cache2), auto_jacvec, auto_jacvec!
280
284
else
281
285
error (" Set autodiff to either AutoForwardDiff(), or AutoFiniteDiff()" )
282
286
end
283
287
284
- ff = JacFunctionWrapper (f, fu, u, p, t)
285
- fu === nothing && (fu = __internal_oop (ff) ? ff (u) : u)
286
-
287
288
op = FwdModeAutoDiffVecProd (ff, u, cache, vecprod, vecprod!)
288
289
289
290
return FunctionOperator (op, u, fu; isinplace = Val (true ), outofplace = Val (true ), p, t,
0 commit comments