Skip to content

Commit e379918

Browse files
Merge pull request #89 from SciML/type
allow for dispatching get_tmp on the type
2 parents 6636083 + c5a7702 commit e379918

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PreallocationTools"
22
uuid = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
33
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>"]
4-
version = "0.4.13"
4+
version = "0.4.14"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/PreallocationTools.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ function get_tmp(dc::FixedSizeDiffCache, u::T) where {T <: ForwardDiff.Dual}
4646
end
4747
end
4848

49+
function get_tmp(dc::FixedSizeDiffCache, u::Type{T}) where {T <: ForwardDiff.Dual}
50+
x = reinterpret(T, dc.dual_du)
51+
if chunksize(T) === chunksize(eltype(dc.dual_du))
52+
x
53+
else
54+
@view x[axes(dc.du)...]
55+
end
56+
end
57+
4958
function get_tmp(dc::FixedSizeDiffCache, u::AbstractArray{T}) where {T <: ForwardDiff.Dual}
5059
x = reinterpret(T, dc.dual_du)
5160
if chunksize(T) === chunksize(eltype(dc.dual_du))
@@ -116,6 +125,14 @@ function get_tmp(dc::DiffCache, u::T) where {T <: ForwardDiff.Dual}
116125
_restructure(dc.du, reinterpret(T, view(dc.dual_du, 1:nelem)))
117126
end
118127

128+
function get_tmp(dc::DiffCache, u::Type{T}) where {T <: ForwardDiff.Dual}
129+
nelem = div(sizeof(T), sizeof(eltype(dc.dual_du))) * length(dc.du)
130+
if nelem > length(dc.dual_du)
131+
enlargediffcache!(dc, nelem)
132+
end
133+
_restructure(dc.du, reinterpret(T, view(dc.dual_du, 1:nelem)))
134+
end
135+
119136
function get_tmp(dc::DiffCache, u::AbstractArray{T}) where {T <: ForwardDiff.Dual}
120137
nelem = div(sizeof(T), sizeof(eltype(dc.dual_du))) * length(dc.du)
121138
if nelem > length(dc.dual_du)

0 commit comments

Comments
 (0)