Skip to content

Commit

Permalink
Fix repeat for zero repetitions
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloferz committed Feb 19, 2017
1 parent 36569d6 commit 208ef68
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ _reperr(s, n, N) = throw(ArgumentError("number of " * s * " repetitions " *
shape, inner_shape = rep_shapes(A, inner, outer)

R = similar(A, shape)
if any(iszero, shape)
return R
end

# fill the first inner block
if all(x -> x == 1, inner)
Expand Down Expand Up @@ -420,8 +423,7 @@ _reperr(s, n, N) = throw(ArgumentError("number of " * s * " repetitions " *
dest_indices[i] += inner_shape[i]
R[dest_indices...] = B
end
src_indices[i] = 1:dest_indices[i][end]
copy!(dest_indices, src_indices)
src_indices[i] = dest_indices[i] = 1:shape[i]
end

return R
Expand Down
7 changes: 7 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,13 @@ end
R = repeat(1:2, inner=(3,), outer=(2,))
@test R == [1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2]

@test size(repeat([1], inner=(0,))) == (0,)
@test size(repeat([1], outer=(0,))) == (0,)
@test size(repeat([1 1], inner=(0, 1))) == (0, 2)
@test size(repeat([1 1], outer=(1, 0))) == (1, 0)
@test size(repeat([1 1], inner=(2, 0), outer=(2, 1))) == (4, 0)
@test size(repeat([1 1], inner=(2, 0), outer=(0, 1))) == (0, 0)

A = rand(4,4)
for s in Any[A[1:2:4, 1:2:4], view(A, 1:2:4, 1:2:4)]
c = cumsum(s, 1)
Expand Down

0 comments on commit 208ef68

Please sign in to comment.