Skip to content

Commit

Permalink
Merge pull request #4416 from JuliaLang/teh/subarray_strides
Browse files Browse the repository at this point in the history
Fix #4412
  • Loading branch information
JeffBezanson committed Oct 4, 2013
2 parents d5d68e1 + 3aab5c4 commit 8645ecb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function setindex!(s::SubArray, v, I::Union(Real,AbstractArray)...)
setindex!(s.parent, v, newindexes...)
end

stride(s::SubArray, i::Integer) = s.strides[i]
stride(s::SubArray, i::Integer) = i <= length(s.strides) ? s.strides[i] : s.strides[end]*s.dims[end]

convert{T}(::Type{Ptr{T}}, x::SubArray{T}) =
pointer(x.parent) + (x.first_index-1)*sizeof(T)
Expand Down
2 changes: 2 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ sA[2:5:end] = -1
@test all(sA[2:5:end] .== -1)
@test all(A[5:15:120] .== -1)
@test strides(sA) == (1,3,15)
@test stride(sA,3) == 15
@test stride(sA,4) == 120
sA = sub(A, 1:3, 1:5, 5)
@test Base.parentdims(sA) == 1:2
sA[1:3,1:5] = -2
Expand Down

0 comments on commit 8645ecb

Please sign in to comment.