Skip to content

Commit

Permalink
Fix ambiguity in indexing with zero-dimensional sub arrays (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty authored Sep 2, 2021
1 parent 0e567f7 commit 792229a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cardinality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ getindex(A::Array, i1::InfiniteCardinal{0}, I::Integer...) = throw(BoundsError(A
Base._unsafe_getindex(::IndexStyle, A::AbstractArray, I::InfiniteCardinal{0}) = error("Overload getindex(::$(typeof(A)), ::InfiniteCardinal{0})")

# Avoid too-strict restrictions in SubArray
function getindex(V::SubArray{T,N}, I::Vararg{InfiniteCardinal{0},N}) where {T,N}
@boundscheck checkbounds(V, I...)
@inbounds r = V.parent[Base.reindex(V.indices, I)...]
function getindex(V::SubArray{T,N}, i1::InfiniteCardinal{0}, I::Integer...) where {T,N}
@boundscheck checkbounds(V, i1, I...)
@inbounds r = V.parent[Base.reindex(V.indices, tuple(i1, I...))...]
r
end
2 changes: 2 additions & 0 deletions test/test_cardinality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,7 @@ using Infinities, Base64, Base.Checked, Test
@test_throws BoundsError randn(3)[ℵ₀]
@test_throws ErrorException Base._unsafe_getindex(IndexCartesian(),permutedims(1:3)',ℵ₀)
@test_throws BoundsError view(randn(3),1:2)[ℵ₀]
# check ambiguity is not introduced
@test view(collect(1:5),2)[] == 2
end
end

0 comments on commit 792229a

Please sign in to comment.