Skip to content

Commit

Permalink
Support repeat at any dimension (#29626)
Browse files Browse the repository at this point in the history
* Support repeat at any dimension

* Use a more friendly way to do getindex

* rollback to original commit

* use `1` instead of `OneTo(1)`

* Change 1 to OneTo(1)

* Change `length` to `ndims`, add test

* Fix a test error

* trigger rebuild
  • Loading branch information
johnnychen94 authored and mbauman committed Oct 23, 2018
1 parent 24f1316 commit 84024a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

2 comments on commit 84024a1

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.