Skip to content

Commit 84024a1

Browse files
johnnychen94mbauman
authored andcommitted
Support repeat at any dimension (#29626)
* 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
1 parent 24f1316 commit 84024a1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

base/abstractarraymath.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ _reperr(s, n, N) = throw(ArgumentError("number of " * s * " repetitions " *
377377

378378
# fill the first inner block
379379
if all(x -> x == 1, inner)
380-
R[axes(A)...] = A
380+
idxs = (axes(A)..., ntuple(n->OneTo(1), ndims(R)-ndims(A))...) # keep dimension consistent
381+
R[idxs...] = A
381382
else
382383
inner_indices = [1:n for n in inner]
383384
for c in CartesianIndices(axes(A))

test/arrayops.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,12 @@ end
699699
@test_throws MethodError repeat(1, 2, 3)
700700
@test repeat([1, 2], 1, 2, 3) == repeat([1, 2], outer = (1, 2, 3))
701701

702+
# issue 29614
703+
@test repeat(ones(2, 2), 1, 1, 1) == ones(2, 2, 1)
704+
@test repeat(ones(2, 2), 2, 2, 2) == ones(4, 4, 2)
705+
@test repeat(ones(2), 2, 2, 2) == ones(4, 2, 2)
706+
@test repeat(ones(2, 2), inner=(1, 1, 1), outer=(2, 2, 2)) == ones(4, 4, 2)
707+
702708
R = repeat([1, 2])
703709
@test R == [1, 2]
704710
R = repeat([1, 2], inner=1)

0 commit comments

Comments
 (0)