Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support repeat at any dimension #29626

Merged
merged 8 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion base/abstractarraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ _reperr(s, n, N) = throw(ArgumentError("number of " * s * " repetitions " *

# fill the first inner block
if all(x -> x == 1, inner)
R[axes(A)...] = A
idxs = (axes(A)..., ntuple(n->OneTo(1), ndims(R)-ndims(A))...) # keep dimension consistent
R[idxs...] = A
else
inner_indices = [1:n for n in inner]
for c in CartesianIndices(axes(A))
Expand Down
6 changes: 6 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,12 @@ end
@test_throws MethodError repeat(1, 2, 3)
@test repeat([1, 2], 1, 2, 3) == repeat([1, 2], outer = (1, 2, 3))

# issue 29614
@test repeat(ones(2, 2), 1, 1, 1) == ones(2, 2, 1)
@test repeat(ones(2, 2), 2, 2, 2) == ones(4, 4, 2)
@test repeat(ones(2), 2, 2, 2) == ones(4, 2, 2)
@test repeat(ones(2, 2), inner=(1, 1, 1), outer=(2, 2, 2)) == ones(4, 4, 2)

R = repeat([1, 2])
@test R == [1, 2]
R = repeat([1, 2], inner=1)
Expand Down