Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes some bugs and aligns code and documentation for LazyBufferCache. In order of commits:
b = LazyBufferCache(f)
produces caches of arbitrary lengths whenf
is a closure.f
not being passed through tonew
in the constructor, makingb.lengthmap
an uninitialized instance oftypeof(f)
. (I'm surprised this is even allowed.)f
through tonew
b[x]
andb[y]
return the same buffer as long asx
andy
have the same eltype, regardless of sizes and array types/storageeltype(x)
used as key tob.bufs
, not size and array type(typeof(x), f(size(x)))
as keytypeof(similar(u, size)) === typeof(u)
. This does not hold for allAbstractArray
s; ranges like1:5
are the canonical counterexamples. This hardly seems relevant for LazyBufferCache use cases, so I've left it as is.f
is actually used as size map, not length map, so the LBC can both accept and return arrays of arbitrary dimension, not just vectors. In particular, matrices are already supported, contrary to what a comment in the code claims.b.lengthmap
tob.sizemap
.Some tests are probably in order, I'll get to that tomorrow.