Indexing SOneTo with IdentityUnitRange preserves indices#922
Open
jishnub wants to merge 4 commits intoJuliaArrays:masterfrom
Open
Indexing SOneTo with IdentityUnitRange preserves indices#922jishnub wants to merge 4 commits intoJuliaArrays:masterfrom
jishnub wants to merge 4 commits intoJuliaArrays:masterfrom
Conversation
Member
Author
|
After 47ce9a0: julia> sm = @SMatrix [1 3; 2 4]
2×2 SMatrix{2, 2, Int64, 4} with indices SOneTo(2)×SOneTo(2):
1 3
2 4
julia> sm[SOneTo(length(sm))]
4-element SVector{4, Int64} with indices SOneTo(4):
1
2
3
4
julia> view(sm, map(Base.IdentityUnitRange, axes(sm))...) |> axes
(SOneTo(2), SOneTo(2)) |
Member
Author
|
After c53a671 vector indexing may reshape a julia> sm = @SMatrix [1 3; 2 4]
2×2 SMatrix{2, 2, Int64, 4} with indices SOneTo(2)×SOneTo(2):
1 3
2 4
julia> sm[:, SOneTo(1), 1, SOneTo(1)]
2×1×1 SArray{Tuple{2, 1, 1}, Int64, 3, 2} with indices SOneTo(2)×SOneTo(1)×SOneTo(1):
[:, :, 1] =
1
2One side-effect is that the error message for out-of-bounds indexing becomes a bit confusing as we don't perform the bounds checking at the top level: julia> sm[:, SOneTo(1), 1, SOneTo(2)]
ERROR: BoundsError: attempt to access 2×2×1×1 SArray{Tuple{2, 2, 1, 1}, Int64, 4, 4} with indices SOneTo(2)×SOneTo(2)×SOneTo(1)×SOneTo(1) at index [1, 1, 1, 2]However this may be changed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
On master:
After this PR:
This makes it consistent with julia's vector indexing, eg. for
Base.OneTo(JuliaLang/julia#40997)