Skip to content

Commit

Permalink
fix JuliaLang#39379, use first∘LinearIndices instead of 1 (JuliaLang#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mbauman authored and ElOceanografo committed May 4, 2021
1 parent 13d9e79 commit 1fb1727
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ function _getindex(::IndexLinear, A::AbstractArray, I::Vararg{Int,M}) where M
end
_to_linear_index(A::AbstractArray, i::Integer) = i
_to_linear_index(A::AbstractVector, i::Integer, I::Integer...) = i
_to_linear_index(A::AbstractArray) = 1
_to_linear_index(A::AbstractArray) = first(LinearIndices(A))
_to_linear_index(A::AbstractArray, I::Integer...) = (@_inline_meta; _sub2ind(A, I...))

## IndexCartesian Scalar indexing: Canonical method is full dimensionality of Ints
Expand Down
9 changes: 9 additions & 0 deletions test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,15 @@ end
@test axes(S) == (OffsetArrays.IdOffsetRange(0:1), Base.OneTo(2), OffsetArrays.IdOffsetRange(2:5))
end

@testset "Zero-index indexing" begin
@test OffsetArray([6], 2:2)[] == 6
@test OffsetArray(fill(6, 1, 1), 2:2, 3:3)[] == 6
@test OffsetArray(fill(6))[] == 6
@test_throws BoundsError OffsetArray([6,7], 2:3)[]
@test_throws BoundsError OffsetArray([6 7], 2:2, 2:3)[]
@test_throws BoundsError OffsetArray([], 2:1)[]
end

@testset "IdentityUnitRange indexing" begin
a = OffsetVector(3:4, 2:3)
ax = IdentityUnitRange(2:3)
Expand Down

0 comments on commit 1fb1727

Please sign in to comment.