Commit 73f7acd
authored
Fix no_offset_view for Slice (#376)
Currently, the implementation of `no_offset_view` for a `Slice` doesn't
actually ensure that there is no offset. This is because
`Base.Slice(UnitRange(a))` has `UnitRange(a)` as its axes, which are
usually offset. This PR changes the behavior to return a `UnitRange(a)`
instead.
Fixes #375
The flip side of the current implementation is that the `Slice`
information is lost, so `IndexStyle` of 2D views might become
`IndexCartesian` once they are routed through `no_offset_view`.
```julia
julia> arr = OffsetArray(reshape(1:15, 3, 5), 2, 3)
3×5 OffsetArray(reshape(::UnitRange{Int64}, 3, 5), 3:5, 4:8) with eltype Int64 with indices 3:5×4:8:
1 4 7 10 13
2 5 8 11 14
3 6 9 12 15
julia> V = view(arr, :, :)
3×5 view(OffsetArray(reshape(::UnitRange{Int64}, 3, 5), 3:5, 4:8), :, :) with eltype Int64 with indices 3:5×4:8:
1 4 7 10 13
2 5 8 11 14
3 6 9 12 15
julia> IndexStyle(V)
IndexLinear()
julia> V_nooff = OffsetArrays.no_offset_view(V)
3×5 view(OffsetArray(reshape(::UnitRange{Int64}, 3, 5), 3:5, 4:8), 3:5, 4:8) with eltype Int64:
1 4 7 10 13
2 5 8 11 14
3 6 9 12 15
julia> IndexStyle(V_nooff)
IndexCartesian()
```
An alternate approach might be to shift the parent to one-based indices,
and use `Base.Slice{Base.OneTo{Int}}` axes, which preserve this
information. This, however, departs from the current approach of
preserving the `parentindices` of the `SubArray`.
Edit: the alternate approach is implemented now.1 parent 497deea commit 73f7acd
2 files changed
+54
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
693 | 693 | | |
694 | 694 | | |
695 | 695 | | |
696 | | - | |
697 | | - | |
698 | | - | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
699 | 741 | | |
700 | 742 | | |
701 | 743 | | |
702 | 744 | | |
703 | 745 | | |
704 | 746 | | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
709 | 750 | | |
710 | 751 | | |
711 | 752 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2367 | 2367 | | |
2368 | 2368 | | |
2369 | 2369 | | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
2370 | 2376 | | |
2371 | 2377 | | |
2372 | 2378 | | |
| |||
0 commit comments