@@ -166,6 +166,26 @@ function DI.prepare_derivative(
166
166
return FiniteDiffTwoArgDerivativePrep (cache, relstep, absstep, dir)
167
167
end
168
168
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
+
169
189
function DI. value_and_derivative (
170
190
f!,
171
191
y,
@@ -257,6 +277,28 @@ function DI.prepare_jacobian(
257
277
return FiniteDiffTwoArgJacobianPrep (cache, relstep, absstep, dir)
258
278
end
259
279
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
+
260
302
function DI. value_and_jacobian (
261
303
f!,
262
304
y,
0 commit comments