Skip to content

Commit

Permalink
make sure repeat does not allow negative inner and outer (#35525)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins committed Apr 23, 2020
1 parent 5a7cda9 commit 20d1362
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,13 @@ _rshps(shp, shp_i, sz, i, ::Tuple{}) =
_reperr(s, n, N) = throw(ArgumentError("number of " * s * " repetitions " *
"($n) cannot be less than number of dimensions of input ($N)"))

_negreperr(n) = throw(ArgumentError("number of $n repetitions" *
"cannot be negative"))

@noinline function _repeat(A::AbstractArray, inner, outer)
any(<(0), inner) && _negreperr("inner")
any(<(0), outer) && _negreperr("outer")

shape, inner_shape = rep_shapes(A, inner, outer)

R = similar(A, shape)
Expand Down
1 change: 1 addition & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ end
3 4], inner=(2,), outer=(2, 2))
@test_throws ArgumentError repeat([1 2;
3 4], inner=(2, 2), outer=(2,))
@test_throws ArgumentError repeat([1, 2], inner=(1, -1), outer=(1, -1))

A = reshape(1:8, 2, 2, 2)
R = repeat(A, inner = (1, 1, 2), outer = (1, 1, 1))
Expand Down

0 comments on commit 20d1362

Please sign in to comment.