Skip to content

Commit

Permalink
fix reshaping empty linearslow arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Apr 19, 2016
1 parent 8a5598d commit 866cd4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/reshapedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 866cd4d

Please sign in to comment.