Skip to content

Commit 2df173f

Browse files
committed
Use full array type and size as LBC key
Required to behave as promised in the docstring
1 parent 349bb58 commit 2df173f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/PreallocationTools.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ struct LazyBufferCache{F<:Function}
8787
end
8888

8989
# override the [] method
90-
function Base.getindex(b::LazyBufferCache, u::AbstractArray{T}) where {T}
90+
function Base.getindex(b::LazyBufferCache, u::T) where {T<:AbstractArray}
9191
n = b.lengthmap(size(u)) # required buffer length
92-
buf = get!(b.bufs, T) do
93-
similar(u, T, n) # buffer to allocate if it was not found in b.bufs
94-
end::typeof(u) # declare type since b.bufs dictionary is untyped
95-
# Doesn't work well with matrices, needs more thought!
96-
#return resize!(buf, n) # resize the buffer if needed, e.g. if problem was resized
92+
buf = get!(b.bufs, (T, n)) do
93+
similar(u, n) # buffer to allocate if it was not found in b.bufs
94+
end::T # declare type since b.bufs dictionary is untyped
95+
return buf
9796
end
9897

9998
export dualcache, get_tmp, LazyBufferCache

0 commit comments

Comments
 (0)