Skip to content

Commit ec78668

Browse files
authored
fix jacobian(_, AutoFiniteDiff(fdjtype=Val(:central)))
FiniteDiff requires `x1==x` for central mode autodiff.
1 parent a5ecbe0 commit ec78668

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • DifferentiationInterface/ext/DifferentiationInterfaceFiniteDiffExt

DifferentiationInterface/ext/DifferentiationInterfaceFiniteDiffExt/onearg.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,12 @@ function DI.prepare_jacobian_nokwarg(
346346
) where {C}
347347
_sig = DI.signature(f, backend, x, contexts...; strict)
348348
fc = DI.fix_tail(f, map(DI.unwrap, contexts)...)
349-
y = fc(x)
350-
x1 = similar(x)
351-
fx = similar(y)
349+
x1 = if backend.fdjtype == Val(:Central)
350+
copy(x)
351+
else
352+
similar(x)
353+
end
354+
fx = fc(x)
352355
fx1 = similar(y)
353356
cache = JacobianCache(x1, fx, fx1, fdjtype(backend))
354357
relstep = if isnothing(backend.relstep)

0 commit comments

Comments
 (0)