Introduce eachblockaxes
, more general blocklengths
#476
+167
−21
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.
Introduces and exports
eachblockaxes
, which is analogous to the redefinition ofblocksizes
introduced in #399. It outputs a (lazy) array with a sizeblocksize(A)
that when you index into it it returns the axes of the corresponding block ofA
. It also defines a private functionBlockArrays.eachblockaxes1
analogous toBase.axes1
for getting the axes of the blocks in the first dimension.The motivation for this is related to the discussion in #446, this helps with use cases where the blocks of a block array have non-trivial axes, for example they themselves might be blocked, have a Kronecker structure, have extra information like symmetry sector information (which is an application of graded vector spaces), have labels that need to be preserved, etc.
It also introduces a generalization of
blocklengths
beyondAbstractUnitRange{<:Integer}
to anyAbstractArray
by outputting a (lazy) array that when you index into it returns the length of the corresponding block.This PR also changes the implementation of
blocksizes
. Before, it was implemented as a lazy version ofsize.(blocks(A))
. Now, it is based on a newProductArray
type, where theblocklengths
of the axes in each dimension are stored and accessed. Then,ProductArray
can be shared with and used for the implementation ofeachblockaxes
. I think that design is easier to reason about and in the case ofeachblockaxes
it is easier to make the element type concrete.Related to #369 and #446.