From 956dff31fa03dce2ce7637caf7058080d5f3c664 Mon Sep 17 00:00:00 2001 From: JohnnyChen Date: Sat, 13 Oct 2018 19:33:38 +0800 Subject: [PATCH 1/8] Support repeat at any dimension --- base/abstractarraymath.jl | 3 ++- test/arrayops.jl | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 9e6cd7af7ca23..53d9abb31f359 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -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), length(shape) - length(inner))...) # keep dimension consistent + R[idxs...] = A else inner_indices = [1:n for n in inner] for c in CartesianIndices(axes(A)) diff --git a/test/arrayops.jl b/test/arrayops.jl index b15bcc3779fde..b23a984f2fa20 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -699,6 +699,11 @@ 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) + R = repeat([1, 2]) @test R == [1, 2] R = repeat([1, 2], inner=1) From 5ee3cb627228cf52df70733c2c2ad794e1c4a2da Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 17 Oct 2018 03:38:57 +0800 Subject: [PATCH 2/8] Use a more friendly way to do getindex --- base/abstractarraymath.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 53d9abb31f359..b71ece9dc42a2 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -377,8 +377,7 @@ _reperr(s, n, N) = throw(ArgumentError("number of " * s * " repetitions " * # fill the first inner block if all(x -> x == 1, inner) - idxs = (axes(A)..., ntuple(n->OneTo(1), length(shape) - length(inner))...) # keep dimension consistent - R[idxs...] = A + R[axes(A)...,:] = A else inner_indices = [1:n for n in inner] for c in CartesianIndices(axes(A)) From 10b9b9d64faab9600cf22b3755f93a15e8d5558b Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 17 Oct 2018 04:13:33 +0800 Subject: [PATCH 3/8] rollback to original commit --- base/abstractarraymath.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index b71ece9dc42a2..609d292fe0505 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -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), length(shape) - length(inner))...) + R[idxs...] = A else inner_indices = [1:n for n in inner] for c in CartesianIndices(axes(A)) From 77a7621582068a0563575ce52ca5441bcb2b80ea Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 17 Oct 2018 04:35:55 +0800 Subject: [PATCH 4/8] use `1` instead of `OneTo(1)` --- base/abstractarraymath.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 609d292fe0505..c5d3aa1aa72ac 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -377,7 +377,7 @@ _reperr(s, n, N) = throw(ArgumentError("number of " * s * " repetitions " * # fill the first inner block if all(x -> x == 1, inner) - idxs = (axes(A)..., ntuple(n->OneTo(1), length(shape) - length(inner))...) + idxs = (axes(A)..., ntuple(n->1, length(shape) - length(inner))...) # keep dimension consistent R[idxs...] = A else inner_indices = [1:n for n in inner] From c889a1aba26fd99604e58fc938b2975957e3a92e Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 17 Oct 2018 11:05:55 +0800 Subject: [PATCH 5/8] Change 1 to OneTo(1) --- base/abstractarraymath.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index c5d3aa1aa72ac..53d9abb31f359 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -377,7 +377,7 @@ _reperr(s, n, N) = throw(ArgumentError("number of " * s * " repetitions " * # fill the first inner block if all(x -> x == 1, inner) - idxs = (axes(A)..., ntuple(n->1, length(shape) - length(inner))...) # keep dimension consistent + idxs = (axes(A)..., ntuple(n->OneTo(1), length(shape) - length(inner))...) # keep dimension consistent R[idxs...] = A else inner_indices = [1:n for n in inner] From 7e8c9c79359af8742a15890e2234f22c96833ee3 Mon Sep 17 00:00:00 2001 From: JohnnyChen Date: Thu, 18 Oct 2018 13:18:47 +0800 Subject: [PATCH 6/8] Change `length` to `ndims`, add test --- base/abstractarraymath.jl | 2 +- test/arrayops.jl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/base/abstractarraymath.jl b/base/abstractarraymath.jl index 53d9abb31f359..e5ca36f71ac0a 100644 --- a/base/abstractarraymath.jl +++ b/base/abstractarraymath.jl @@ -377,7 +377,7 @@ _reperr(s, n, N) = throw(ArgumentError("number of " * s * " repetitions " * # fill the first inner block if all(x -> x == 1, inner) - idxs = (axes(A)..., ntuple(n->OneTo(1), length(shape) - length(inner))...) # keep dimension consistent + 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] diff --git a/test/arrayops.jl b/test/arrayops.jl index b23a984f2fa20..e396cf1281461 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -703,6 +703,7 @@ end @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,2,2) R = repeat([1, 2]) @test R == [1, 2] From b4c3b17f6f9ac8f4c463d3b6ea466dd40bc6f297 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Thu, 18 Oct 2018 20:20:48 +0800 Subject: [PATCH 7/8] Fix a test error --- test/arrayops.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/arrayops.jl b/test/arrayops.jl index e396cf1281461..4809e060f3451 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -703,7 +703,7 @@ end @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,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] From dadf4f5eb0c35065ca8077c5bae33da7e733a55e Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Thu, 18 Oct 2018 23:34:30 +0800 Subject: [PATCH 8/8] trigger rebuild --- test/arrayops.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/arrayops.jl b/test/arrayops.jl index 4809e060f3451..9ccccb9817fa1 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -700,10 +700,10 @@ end @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) + @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]