-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functionality for slicing with unit ranges that preserves block information #347
Comments
Generally, the result of an indexing operation has the same axes as that of the indices. This lets us use results such as |
@jishnub that seems like a reasonable rule, but to clarify do you think
|
Responding to #356 (comment). It seems like we could have both worlds, where the rule is that if you slice with a The use case I have in mind is designing a The alternative is that if we want to perform a slice with a |
To me, it seems like we need two things here:
Meanwhile, we may also be able to improve the default indexing behavior of an indexing operation like |
That could be a good way to go. Then I think if I was designing things from scratch I would make it the other way around, and have I suppose Agreed that a generic way to implement |
@jishnub what do you think julia> using BlockArrays
julia> a = BlockArray(randn(4, 4), [2, 2], [2, 2])
2×2-blocked 4×4 BlockMatrix{Float64}:
0.381752 0.999573 │ 0.861305 -0.114894
-0.4414 -1.44202 │ 0.906593 -0.383571
──────────────────────┼──────────────────────
0.575925 -1.25182 │ 0.672723 -1.18554
0.480034 0.899287 │ -0.519823 -1.36788
julia> r = blockedrange([1, 2, 1])
3-blocked 4-element BlockedUnitRange{Vector{Int64}}:
1
─
2
3
─
4
julia> @blocked a[r, r]
# ... Should it preserve the blocks of julia> a[blockedrange([2, 2]), blockedrange([2, 2])]
2×2-blocked 4×4 BlockMatrix{Float64}:
0.381752 0.999573 │ 0.861305 -0.114894
-0.4414 -1.44202 │ 0.906593 -0.383571
──────────────────────┼──────────────────────
0.575925 -1.25182 │ 0.672723 -1.18554
0.480034 0.899287 │ -0.519823 -1.36788 or should it combine the blocking of the input indices and the axes of julia> a[blockedrange([1, 1, 1, 1]), blockedrange([1, 1, 1, 1])]
4×4-blocked 4×4 BlockMatrix{Float64}:
0.381752 │ 0.999573 │ 0.861305 │ -0.114894
───────────┼─────────────┼─────────────┼───────────
-0.4414 │ -1.44202 │ 0.906593 │ -0.383571
───────────┼─────────────┼─────────────┼───────────
0.575925 │ -1.25182 │ 0.672723 │ -1.18554
───────────┼─────────────┼─────────────┼───────────
0.480034 │ 0.899287 │ -0.519823 │ -1.36788 which could be based on julia> foreach(display, BlockArrays.combine_blockaxes.((r, r), axes(a)))
4-blocked 4-element BlockedUnitRange{Vector{Int64}}:
1
─
2
─
3
─
4
4-blocked 4-element BlockedUnitRange{Vector{Int64}}:
1
─
2
─
3
─
4 I'm asking because I may start implementing |
I think it makes sense to combine the blocks. This way, we obtain:
The alternative doesn't provide an easy way to combine the blocks, which may be useful as well. Since it's usually easy to go from a blocked to a non-blocked index (e.g. |
Makes sense to me. |
Indexing with
UnitRange
does not preserve the blocking of blocked arrays:and:
It would be nice to have convenient functionality for indexing with
UnitRange
that does preserve blocking.The text was updated successfully, but these errors were encountered: