From 3aab5c49c1580cd8b72cbff79f8e87b64f4d2061 Mon Sep 17 00:00:00 2001 From: timholy Date: Tue, 1 Oct 2013 20:32:32 -0500 Subject: [PATCH] Fix 4412 --- base/subarray.jl | 2 +- test/arrayops.jl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/base/subarray.jl b/base/subarray.jl index 10564662bf28d..2f647a648fbf1 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -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) diff --git a/test/arrayops.jl b/test/arrayops.jl index 9333f33ee01df..bd1bacc311d4a 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -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