File tree Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -185,9 +185,8 @@ LazyBufferCache(f::F=identity)
185185```
186186
187187A ` LazyBufferCache ` is a ` Dict ` -like type for the caches which automatically defines
188- new cache vectors on demand when they are required. The function ` f ` is a length
189- map which maps ` length_of_cache = f(length(u)) ` , which by default creates cache
190- vectors of the same length.
188+ new cache arrays on demand when they are required. The function ` f ` maps
189+ ` size_of_cache = f(size(u)) ` , which by default creates cache arrays of the same size.
191190
192191Note that ` LazyBufferCache ` does cause a dynamic dispatch, though it is type-stable.
193192This gives it a ~ 100ns overhead, and thus on very small problems it can reduce
Original file line number Diff line number Diff line change 7575"""
7676 b = LazyBufferCache(f=identity)
7777
78- A lazily allocated buffer object. Given a vector `u`, `b[u]` returns a `Vector` of the
79- same element type and length `f(length (u))` (defaulting to the same length ), which is
80- allocated as needed and then cached within `b` for subsequent usage.
78+ A lazily allocated buffer object. Given an array `u`, `b[u]` returns an array of the
79+ same type and size `f(size (u))` (defaulting to the same size ), which is allocated as
80+ needed and then cached within `b` for subsequent usage.
8181
8282"""
8383struct LazyBufferCache{F<: Function }
8484 bufs:: Dict # a dictionary mapping types to buffers
85- lengthmap :: F
85+ sizemap :: F
8686 LazyBufferCache (f:: F = identity) where {F<: Function } = new {F} (Dict (), f) # start with empty dict
8787end
8888
8989# override the [] method
9090function Base. getindex (b:: LazyBufferCache , u:: T ) where {T<: AbstractArray }
91- n = b. lengthmap (size (u)) # required buffer length
92- buf = get! (b. bufs, (T, n )) do
93- similar (u, n ) # buffer to allocate if it was not found in b.bufs
91+ s = b. sizemap (size (u)) # required buffer size
92+ buf = get! (b. bufs, (T, s )) do
93+ similar (u, s ) # buffer to allocate if it was not found in b.bufs
9494 end :: T # declare type since b.bufs dictionary is untyped
9595 return buf
9696end
You can’t perform that action at this time.
0 commit comments