Skip to content

Commit

Permalink
Merge pull request #112 from SciML/bigprealloc
Browse files Browse the repository at this point in the history
Allow bigfloats through dualcaches
  • Loading branch information
ChrisRackauckas authored Aug 16, 2024
2 parents 98e4b02 + 2cf2bd2 commit e2df7ec
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/PreallocationTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,39 @@ const dualcache = DiffCache
Returns the `Dual` or normal cache array stored in `dc` based on the type of `u`.
"""
function get_tmp(dc::DiffCache, u::T) where {T <: ForwardDiff.Dual}
nelem = div(sizeof(T), sizeof(eltype(dc.dual_du))) * length(dc.du)
if nelem > length(dc.dual_du)
enlargediffcache!(dc, nelem)
if isbitstype(T)
nelem = div(sizeof(T), sizeof(eltype(dc.dual_du))) * length(dc.du)
if nelem > length(dc.dual_du)
enlargediffcache!(dc, nelem)
end
_restructure(dc.du, reinterpret(T, view(dc.dual_du, 1:nelem)))
else
_restructure(dc.du, zeros(T, size(dc.du)))
end
_restructure(dc.du, reinterpret(T, view(dc.dual_du, 1:nelem)))
end

function get_tmp(dc::DiffCache, ::Type{T}) where {T <: ForwardDiff.Dual}
nelem = div(sizeof(T), sizeof(eltype(dc.dual_du))) * length(dc.du)
if nelem > length(dc.dual_du)
enlargediffcache!(dc, nelem)
if isbitstype(T)
nelem = div(sizeof(T), sizeof(eltype(dc.dual_du))) * length(dc.du)
if nelem > length(dc.dual_du)
enlargediffcache!(dc, nelem)
end
_restructure(dc.du, reinterpret(T, view(dc.dual_du, 1:nelem)))
else
_restructure(dc.du, zeros(T, size(dc.du)))
end
_restructure(dc.du, reinterpret(T, view(dc.dual_du, 1:nelem)))
end

function get_tmp(dc::DiffCache, u::AbstractArray{T}) where {T <: ForwardDiff.Dual}
nelem = div(sizeof(T), sizeof(eltype(dc.dual_du))) * length(dc.du)
if nelem > length(dc.dual_du)
enlargediffcache!(dc, nelem)
if isbitstype(T)
nelem = div(sizeof(T), sizeof(eltype(dc.dual_du))) * length(dc.du)
if nelem > length(dc.dual_du)
enlargediffcache!(dc, nelem)
end
_restructure(dc.du, reinterpret(T, view(dc.dual_du, 1:nelem)))
else
_restructure(dc.du, zeros(T, size(dc.du)))
end
_restructure(dc.du, reinterpret(T, view(dc.dual_du, 1:nelem)))
end

function get_tmp(dc::DiffCache, u::Union{Number, AbstractArray})
Expand Down

0 comments on commit e2df7ec

Please sign in to comment.