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)
185
185
```
186
186
187
187
A ` 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.
191
190
192
191
Note that ` LazyBufferCache ` does cause a dynamic dispatch, though it is type-stable.
193
192
This gives it a ~ 100ns overhead, and thus on very small problems it can reduce
Original file line number Diff line number Diff line change 75
75
"""
76
76
b = LazyBufferCache(f=identity)
77
77
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.
81
81
82
82
"""
83
83
struct LazyBufferCache{F<: Function }
84
84
bufs:: Dict # a dictionary mapping types to buffers
85
- lengthmap :: F
85
+ sizemap :: F
86
86
LazyBufferCache (f:: F = identity) where {F<: Function } = new {F} (Dict (), f) # start with empty dict
87
87
end
88
88
89
89
# override the [] method
90
90
function 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
94
94
end :: T # declare type since b.bufs dictionary is untyped
95
95
return buf
96
96
end
You can’t perform that action at this time.
0 commit comments