@@ -166,6 +166,26 @@ function DI.prepare_derivative(
166166 return FiniteDiffTwoArgDerivativePrep (cache, relstep, absstep, dir)
167167end
168168
169+ function DI. prepare!_derivative (
170+ f!,
171+ y,
172+ old_prep:: FiniteDiffTwoArgDerivativePrep ,
173+ backend:: AutoFiniteDiff ,
174+ x,
175+ contexts:: Vararg{DI.Context,C} ,
176+ ) where {C}
177+ if y isa Vector
178+ (; cache) = old_prep
179+ cache. fx isa Union{Number,Nothing} || resize! (cache. fx, length (y))
180+ cache. c1 isa Union{Number,Nothing} || resize! (cache. c1, length (y))
181+ cache. c2 isa Union{Number,Nothing} || resize! (cache. c2, length (y))
182+ cache. c3 isa Union{Number,Nothing} || resize! (cache. c3, length (y))
183+ return old_prep
184+ else
185+ return DI. prepare_derivative (f!, y, backend, x, contexts... )
186+ end
187+ end
188+
169189function DI. value_and_derivative (
170190 f!,
171191 y,
@@ -257,6 +277,28 @@ function DI.prepare_jacobian(
257277 return FiniteDiffTwoArgJacobianPrep (cache, relstep, absstep, dir)
258278end
259279
280+ function DI. prepare!_jacobian (
281+ f!,
282+ y,
283+ old_prep:: FiniteDiffTwoArgJacobianPrep ,
284+ backend:: AutoFiniteDiff ,
285+ x,
286+ contexts:: Vararg{DI.Context,C} ,
287+ ) where {C}
288+ if x isa Vector && y isa Vector
289+ (; cache) = old_prep
290+ cache. x1 isa Union{Number,Nothing} || resize! (cache. x1, length (x))
291+ cache. x2 isa Union{Number,Nothing} || resize! (cache. x2, length (x))
292+ cache. fx isa Union{Number,Nothing} || resize! (cache. fx, length (y))
293+ cache. fx1 isa Union{Number,Nothing} || resize! (cache. fx1, length (y))
294+ cache. colorvec = 1 : length (x)
295+ cache. sparsity = nothing
296+ return old_prep
297+ else
298+ return DI. prepare_jacobian (f!, y, backend, x, contexts... )
299+ end
300+ end
301+
260302function DI. value_and_jacobian (
261303 f!,
262304 y,
0 commit comments