Skip to content

Commit

Permalink
allow trailing 1s in subarray indexing. fixes #3697
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 12, 2013
1 parent acc5a55 commit a012bba
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ getindex{T}(s::SubArray{T,0,AbstractArray{T,0}}) = s.parent[]
getindex{T}(s::SubArray{T,0}) = s.parent[s.first_index]

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

Expand All @@ -180,7 +182,10 @@ end
function getindex(s::SubArray, is::Integer...)
index = s.first_index
for i = 1:length(is)
index += (is[i]-1)*s.strides[i]
isi = is[i]
if isi != 1
index += (is[i]-1)*s.strides[i]
end
end
s.parent[index]
end
Expand Down

0 comments on commit a012bba

Please sign in to comment.