Skip to content

Commit d50ff3d

Browse files
Merge pull request #18 from SciML/compat
add backwards compatability via a Val dispatch
2 parents 8be6569 + fd12dc4 commit d50ff3d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
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 <[email protected]>"]
4-
version = "0.2.1"
4+
version = "0.2.2"
55

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

src/PreallocationTools.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ or specifying an array of chunk_sizes.
2525
"""
2626
dualcache(u::AbstractArray, N::Int=ForwardDiff.pickchunksize(length(u)); levels::Int = 1) = DiffCache(u, size(u), N*ones(Int, levels))
2727
dualcache(u::AbstractArray, N::AbstractArray{<:Int}) = DiffCache(u, size(u), N)
28+
dualcache(u::AbstractArray, ::Val{N}; levels::Int = 1) where N = dualcache(u,N;levels)
2829

2930
"""
3031
3132
`get_tmp(dc::DiffCache, u)`
3233
33-
Returns the `Dual` or normal cache array stored in `dc` based on the type of `u`.
34+
Returns the `Dual` or normal cache array stored in `dc` based on the type of `u`.
3435
3536
"""
3637
function get_tmp(dc::DiffCache, u::T) where T<:ForwardDiff.Dual
@@ -63,7 +64,7 @@ get_tmp(dc::DiffCache, u::AbstractArray) = dc.du
6364

6465
function enlargedualcache!(dc, nelem) #warning comes only once per dualcache.
6566
chunksize = div(nelem, length(dc.du)) - 1
66-
@warn "The supplied dualcache was too small and was enlarged. This incurrs allocations
67+
@warn "The supplied dualcache was too small and was enlarged. This incurrs allocations
6768
on the first call to get_tmp. If few calls to get_tmp occur and optimal performance is essential,
6869
consider changing 'N'/chunk size of this dualcache to $chunksize."
6970
resize!(dc.dual_du, nelem)

0 commit comments

Comments
 (0)