Skip to content

Commit deb294a

Browse files
Merge pull request #137 from daviehh/master
remove duplicate code
2 parents 850bfa3 + b233dbd commit deb294a

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/PreallocationTools.jl

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,7 @@ This function enables seamless switching between regular and automatic different
5757
computations without manual cache management.
5858
"""
5959
function get_tmp(dc::FixedSizeDiffCache, u::Union{Number, AbstractArray})
60-
if promote_type(eltype(dc.du), eltype(u)) <: eltype(dc.du)
61-
dc.du
62-
else
63-
if length(dc.du) > length(dc.any_du)
64-
resize!(dc.any_du, length(dc.du))
65-
end
66-
_restructure(dc.du, dc.any_du)
67-
end
60+
get_tmp(dc, eltype(u))
6861
end
6962

7063
function get_tmp(dc::FixedSizeDiffCache, ::Type{T}) where {T <: Number}
@@ -171,10 +164,12 @@ elements and issues a one-time warning suggesting an appropriate chunk size for
171164
optimal performance.
172165
173166
## Arguments
167+
174168
- `dc`: The `DiffCache` object to enlarge
175169
- `nelem`: The new required number of elements
176170
177171
## Notes
172+
178173
The warning is shown only once per `DiffCache` instance to avoid spam. For optimal
179174
performance in production code, pre-allocate with the suggested chunk size to avoid
180175
runtime allocations.
@@ -273,7 +268,7 @@ function Base.resize!(dc::DiffCache, n::Integer)
273268
else
274269
throw(ArgumentError("resize! is only supported for DiffCache with vector arrays, got $(typeof(dc.du))"))
275270
end
276-
# dual_du is often pre-allocated for ForwardDiff dual numbers,
271+
# dual_du is often pre-allocated for ForwardDiff dual numbers,
277272
# and may need special handling based on chunk size
278273
# Only resize if it's a vector
279274
if dc.dual_du isa AbstractVector

0 commit comments

Comments
 (0)