Skip to content

Commit

Permalink
Merge pull request #101 from LilithHafner/lh/lbc-sizemap-int
Browse files Browse the repository at this point in the history
Continue to support sizemaps that return Int in LazyBufferCache
  • Loading branch information
ChrisRackauckas authored Feb 10, 2024
2 parents 20722a4 + 33c0aaa commit a1234f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/PreallocationTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ struct LazyBufferCache{F <: Function}
LazyBufferCache(f::F = identity) where {F <: Function} = new{F}(Dict(), f) # start with empty dict
end

similar_type(x::AbstractArray, s::Integer) = similar_type(x, (s,))
function similar_type(x::AbstractArray{T}, s::NTuple{N, Integer}) where {T, N}
# The compiler is smart enough to not allocate
# here for simple types like Array and SubArray
Expand Down
6 changes: 6 additions & 0 deletions test/general_lbc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ y = view(x, 1:900)
@inferred cache[y]
@test 0 == @allocated cache[y]

cache_17 = LazyBufferCache(Returns(17))
x = 1:10
@inferred cache_17[x]
@test 0 == @allocated cache_17[x]
@test size(cache_17[x]) == (17,)

cache = GeneralLazyBufferCache(T -> Vector{T}(undef, 1000))
# GeneralLazyBufferCache is documented not to infer.
# @inferred cache[Float64]
Expand Down

0 comments on commit a1234f2

Please sign in to comment.