Skip to content

Commit a1234f2

Browse files
Merge pull request #101 from LilithHafner/lh/lbc-sizemap-int
Continue to support sizemaps that return Int in LazyBufferCache
2 parents 20722a4 + 33c0aaa commit a1234f2

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/PreallocationTools.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ struct LazyBufferCache{F <: Function}
209209
LazyBufferCache(f::F = identity) where {F <: Function} = new{F}(Dict(), f) # start with empty dict
210210
end
211211

212+
similar_type(x::AbstractArray, s::Integer) = similar_type(x, (s,))
212213
function similar_type(x::AbstractArray{T}, s::NTuple{N, Integer}) where {T, N}
213214
# The compiler is smart enough to not allocate
214215
# here for simple types like Array and SubArray

test/general_lbc.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ y = view(x, 1:900)
4141
@inferred cache[y]
4242
@test 0 == @allocated cache[y]
4343

44+
cache_17 = LazyBufferCache(Returns(17))
45+
x = 1:10
46+
@inferred cache_17[x]
47+
@test 0 == @allocated cache_17[x]
48+
@test size(cache_17[x]) == (17,)
49+
4450
cache = GeneralLazyBufferCache(T -> Vector{T}(undef, 1000))
4551
# GeneralLazyBufferCache is documented not to infer.
4652
# @inferred cache[Float64]

0 commit comments

Comments
 (0)