JuliaArrays / JuliaArrays/BlockArrays.jl
`blockedrange([Base.OneTo(2), Base.OneTo(3)])` as a generalization of `blockedrange([2, 3])`
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 254
- Forks
- 39
- PR merge metrics
- No merged PRs in 30d
Description
The proposal is to define a more general version of blockedrange that supports passing a list of axes of the blocks, rather than just the lengths of the blocks, i.e. support blockisequal(blockedrange([Base.OneTo(2), Base.OneTo(3)]), blockedrange([2, 3])).
The reasoning is that blocks themselves may have more structure than what is just captured by their length, for example in GradedUnitRanges.jl we define a generalization of blocked unit ranges that also have symmetry sectors associated with the blocks (i.e. it is a graded vector space). Another example might be blocked ranges where the blocks themselves have a block structure. A more general blockedrange constructor would make it easier to write generic code for blocked ranges which preserves that kind of information, for example a more generic function for slicing a blocked unit range with a BlockRange could be written as:
function Base.getindex(b::AbstractBlockedUnitRange, I::BlockRange{1})
blockaxeses = only.(axes.(blocks(b)))
blockaxeses_new = blockaxes[Int.(I)]
start = first(b[first(I)]) - 1
return blockedrange(start, blockaxeses_new)
end
blockedrange is a great constructor because the way I see it, it is the "inverse" of blocklengths, i.e. for a one-based blocked range like r = blockedrange([2, 2]), blockisequal(r, blockedrange(blocklengths(r))). Another way to see it is that it allows the concatenation or direct sum of axes in such a way that you get out a blocked unit range/axis.
Note that this is also related to the proposal here: https://github.com/JuliaArrays/BlockArrays.jl/issues/369#issuecomment-2028437671 for defining a function blockaxeses(a::AbstractArray) == axes.(blocks(a)) as a generalization of blocksizes(a) == size.(blocks(a)) introduced in #399, in which case a way to recreate a one-based blocked unit range r would be blockedrange(blockaxeses(r)).
I'm also open to suggestions on other names besides blockedrange for this, this might be overloading that syntax too much, but I think it is a good interface and I can't think of a better name. Another way I have been thinking about this is in terms of a more general concept of direct summing or concatenating axes, i.e. axis_cat([Base.OneTo(2), Base.OneTo(3)]) == Base.OneTo(5) (say to get the axes resulting from cat), but I'm not sure I like that name and anyway this would be a blocked version of that function.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing blockedrange, blocklengths, blockisequal, blocks, and AbstractBlockedUnitRange interfaces, then read the related discussions in issues #369 and #399. Resolve whether the proposed axis-list constructor or another name is appropriate, and define behavior that preserves block-axis structure while retaining the existing length-based behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100