Skip to content

Commit

Permalink
Restrict vector indexing of views to 1-based ranges (#53249)
Browse files Browse the repository at this point in the history
This will be an offset array in general, so we need to restrict the
method to 1-based ranges. This restores the behavior on `v"1.10"`.

The method was added in #45371
  • Loading branch information
jishnub authored Feb 12, 2024
1 parent d6396f1 commit 0a89164
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ function getindex(V::FastContiguousSubArray, i::Int)
end
# parents of FastContiguousSubArrays may support fast indexing with AbstractUnitRanges,
# so we may just forward the indexing to the parent
function getindex(V::FastContiguousSubArray, i::AbstractUnitRange{Int})
# This may only be done for non-offset ranges, as the result would otherwise have offset axes
const OneBasedRanges = Union{OneTo{Int}, UnitRange{Int}, Slice{OneTo{Int}}, IdentityUnitRange{OneTo{Int}}}
function getindex(V::FastContiguousSubArray, i::OneBasedRanges)
@inline
@boundscheck checkbounds(V, i)
@inbounds r = V.parent[V.offset1 .+ i]
Expand Down
5 changes: 5 additions & 0 deletions test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -864,3 +864,8 @@ end
# this is fixed in #40038, so the evaluation of its CartesianIndices should work
@test CartesianIndices(A) == CartesianIndices(B)
end

@testset "indexing views (#53249)" begin
v = view([1,2,3,4], :)
@test v[Base.IdentityUnitRange(2:3)] == OffsetArray(2:3, 2:3)
end

0 comments on commit 0a89164

Please sign in to comment.