@@ -14,7 +14,7 @@ dualarraycreator(args...) = nothing
14
14
15
15
function FixedSizeDiffCache (u:: AbstractArray{T} , siz,
16
16
:: Type{Val{chunk_size}} ) where {T, chunk_size}
17
- x = dualarraycreator (u, siz, Val{chunk_size})
17
+ x = dualarraycreator (u, siz, Val{chunk_size})
18
18
xany = Any[]
19
19
FixedSizeDiffCache (deepcopy (u), x, xany)
20
20
end
@@ -233,6 +233,44 @@ function get_tmp(b::GeneralLazyBufferCache, u::T) where {T}
233
233
end
234
234
Base. getindex (b:: GeneralLazyBufferCache , u:: T ) where {T} = get_tmp (b, u)
235
235
236
+ # resize! methods for PreallocationTools types
237
+ # Note: resize! only works for 1D arrays (vectors)
238
+ function Base. resize! (dc:: DiffCache , n:: Integer )
239
+ # Only resize if the array is a vector
240
+ if dc. du isa AbstractVector
241
+ resize! (dc. du, n)
242
+ else
243
+ throw (ArgumentError (" resize! is only supported for DiffCache with vector arrays, got $(typeof (dc. du)) " ))
244
+ end
245
+ # dual_du is often pre-allocated for ForwardDiff dual numbers,
246
+ # and may need special handling based on chunk size
247
+ # Only resize if it's a vector
248
+ if dc. dual_du isa AbstractVector
249
+ resize! (dc. dual_du, n)
250
+ end
251
+ # Always resize the any_du cache
252
+ resize! (dc. any_du, n)
253
+ return dc
254
+ end
255
+
256
+ function Base. resize! (dc:: FixedSizeDiffCache , n:: Integer )
257
+ # Only resize if the array is a vector
258
+ if dc. du isa AbstractVector
259
+ resize! (dc. du, n)
260
+ else
261
+ throw (ArgumentError (" resize! is only supported for FixedSizeDiffCache with vector arrays, got $(typeof (dc. du)) " ))
262
+ end
263
+ # dual_du is often pre-allocated for ForwardDiff dual numbers,
264
+ # and may need special handling based on chunk size
265
+ # Only resize if it's a vector
266
+ if dc. dual_du isa AbstractVector
267
+ resize! (dc. dual_du, n)
268
+ end
269
+ # Always resize the any_du cache
270
+ resize! (dc. any_du, n)
271
+ return dc
272
+ end
273
+
236
274
export GeneralLazyBufferCache, FixedSizeDiffCache, DiffCache, LazyBufferCache, dualcache
237
275
export get_tmp
238
276
0 commit comments