diff --git a/base/reshapedarray.jl b/base/reshapedarray.jl index 2982c8b3b9b8d..52a8fe755e0ae 100644 --- a/base/reshapedarray.jl +++ b/base/reshapedarray.jl @@ -53,7 +53,8 @@ end function _reshape(p::Tuple{AbstractArray,LinearSlow}, dims::Dims) parent = p[1] strds = front(size_strides(parent)) - mi = map(SignedMultiplicativeInverse, strds) + strds1 = map(s->max(1,s), strds) # for resizing empty arrays + mi = map(SignedMultiplicativeInverse, strds1) ReshapedArray(parent, dims, reverse(mi)) end diff --git a/test/arrayops.jl b/test/arrayops.jl index 870dd74e1ad35..b0992b154fe9c 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -87,6 +87,14 @@ a = reshape(b, (2, 2, 2, 2, 2)) @test a[2,1,2,2,1] == b[14] @test a[2,2,2,2,2] == b[end] +# reshaping linearslow arrays +a = zeros(1, 5) +s = sub(a, :, [2,3,5]) +@test length(reshape(s, length(s))) == 3 +a = zeros(0, 5) # an empty linearslow array +s = sub(a, :, [2,3,5]) +@test length(reshape(s, length(s))) == 0 + a = rand(1, 1, 8, 8, 1) @test @inferred(squeeze(a, 1)) == @inferred(squeeze(a, (1,))) == reshape(a, (1, 8, 8, 1)) @test @inferred(squeeze(a, (1, 5))) == squeeze(a, (5, 1)) == reshape(a, (1, 8, 8))