Skip to content

Commit a012bba

Browse files
committed
allow trailing 1s in subarray indexing. fixes #3697
1 parent acc5a55 commit a012bba

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

base/subarray.jl

+6-1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ getindex{T}(s::SubArray{T,0,AbstractArray{T,0}}) = s.parent[]
155155
getindex{T}(s::SubArray{T,0}) = s.parent[s.first_index]
156156

157157
getindex{T}(s::SubArray{T,1}, i::Integer) = s.parent[s.first_index + (i-1)*s.strides[1]]
158+
getindex{T}(s::SubArray{T,1}, i::Integer, j::Integer) =
159+
j==1 ? s.parent[s.first_index + (i-1)*s.strides[1]] : throw(BoundsError())
158160
getindex{T}(s::SubArray{T,2}, i::Integer, j::Integer) =
159161
s.parent[s.first_index + (i-1)*s.strides[1] + (j-1)*s.strides[2]]
160162

@@ -180,7 +182,10 @@ end
180182
function getindex(s::SubArray, is::Integer...)
181183
index = s.first_index
182184
for i = 1:length(is)
183-
index += (is[i]-1)*s.strides[i]
185+
isi = is[i]
186+
if isi != 1
187+
index += (is[i]-1)*s.strides[i]
188+
end
184189
end
185190
s.parent[index]
186191
end

0 commit comments

Comments
 (0)