Skip to content

Commit 6cc3ce3

Browse files
committed
Fix inference on getindex
1 parent 78055a6 commit 6cc3ce3

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/OffsetArrays.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,13 @@ Base.fill(x, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
133133
### Low-level utilities ###
134134

135135
# Computing a shifted index (subtracting the offset)
136-
@inline offset(offsets::NTuple{N,Int}, inds::NTuple{N,Int}) where {N} = _offset((), offsets, inds)
137-
_offset(out, ::Tuple{}, ::Tuple{}) = out
138-
@inline _offset(out, offsets, inds) =
139-
_offset((out..., inds[1]-offsets[1]), Base.tail(offsets), Base.tail(inds))
136+
@inline offset(offsets::NTuple{N,Int}, inds::NTuple{N,Int}) where {N} =
137+
(inds[1]-offsets[1], offset(Base.tail(offsets), Base.tail(inds))...)
138+
offset(::Tuple{}, ::Tuple{}) = ()
140139

141140
# Support trailing 1s
142141
@inline offset(offsets::Tuple{Vararg{Int}}, inds::Tuple{Vararg{Int}}) =
143142
(offset(offsets, Base.front(inds))..., inds[end])
144-
offset(offsets::Tuple{}, inds::Tuple{}) = ()
145143
offset(offsets::Tuple{Vararg{Int}}, inds::Tuple{}) = error("inds cannot be shorter than offsets")
146144

147145
indexoffset(r::AbstractRange) = first(r) - 1

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ S = OffsetArray(view(A0, 1:2, 1:2), (-1,2)) # IndexCartesian
4545
@test_throws DimensionMismatch OffsetArray(A0, 0:1, 2:4)
4646

4747
# Scalar indexing
48-
@test A[0,3] == A[0,3,1] == A[1] == S[0,3] == S[0,3,1] == S[1] == 1
48+
@test @inferred(A[0,3]) == @inferred(A[0,3,1]) == @inferred(A[1]) == @inferred(S[0,3]) == @inferred(S[0,3,1]) == @inferred(S[1]) == 1
4949
@test A[1,3] == A[1,3,1] == A[2] == S[1,3] == S[1,3,1] == S[2] == 2
5050
@test A[0,4] == A[0,4,1] == A[3] == S[0,4] == S[0,4,1] == S[3] == 3
5151
@test A[1,4] == A[1,4,1] == A[4] == S[1,4] == S[1,4,1] == S[4] == 4

0 commit comments

Comments
 (0)