From 866cd4d343d12dabf74b366ee91f0eaa2e3af977 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 19 Apr 2016 10:47:30 -0500 Subject: [PATCH] fix reshaping empty linearslow arrays --- base/reshapedarray.jl | 3 ++- test/arrayops.jl | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/base/reshapedarray.jl b/base/reshapedarray.jl index 2982c8b3b9b8d8..52a8fe755e0ae8 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 870dd74e1ad350..b0992b154fe9c0 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))