From fa56742a6ddc332f998da4e8bdf61534c12e78a6 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 12 Jul 2016 14:48:45 -0700 Subject: [PATCH 1/5] Fix broadcast_shape when Base.OneTo is defined --- src/Compat.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Compat.jl b/src/Compat.jl index a442f7139..9daab3a6b 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1316,4 +1316,9 @@ if !isdefined(Base, :allunique) export allunique end +if isdefined(Base, :OneTo) + broadcast_shape(x...) = Base.to_shape(broadcast_shape(x...)) + export broadcast_shape +end + end # module From fc118838e417899ce5ad01e503e888d1ec75fd3e Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 12 Jul 2016 14:57:54 -0700 Subject: [PATCH 2/5] Added tests --- test/runtests.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 2eebbc7f0..6f38e53da 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1256,3 +1256,8 @@ end let a = rand(10,10) @test view(a, :, 1) == a[:,1] end + +@test broadcast_shape([1 2; 3 4], [1,1]) == (2,2) +@test broadcast_shape([1,2,3], 4) == (3,) +@test broadcast_shape() == () +@test broadcast_shape(4.3) == () From 293dc184142f66e7a5af879df880821e55c78427 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 12 Jul 2016 15:32:56 -0700 Subject: [PATCH 3/5] Note change in README and handle pre-OneTo versions --- README.md | 4 ++++ src/Compat.jl | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 84bf63f17..2ba87afc8 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,10 @@ Currently, the `@compat` macro supports the following syntaxes: * `OS_NAME` is now `Sys.KERNEL`. OS information available as `is_apple`, `is_bsd`, `is_linux`, `is_unix`, and `is_windows`. [16219](https://github.com/JuliaLang/julia/pull/16219) +* `Base.Broadcast.broadcast_shape` now returns a tuple containing a `Base.OneTo` object rather than integers. + Compat provides an unexported `Compat.broadcast_shape` that mimics the behavior from 0.4. + [#17137](https://github.com/JuliaLang/julia/pull/17137) + ## New types * [`Nullable` types](http://julia.readthedocs.org/en/latest/manual/types/?highlight=nullable#nullable-types-representing-missing-values) and their associated operations. diff --git a/src/Compat.jl b/src/Compat.jl index 9daab3a6b..2bd279255 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1317,8 +1317,9 @@ if !isdefined(Base, :allunique) end if isdefined(Base, :OneTo) - broadcast_shape(x...) = Base.to_shape(broadcast_shape(x...)) - export broadcast_shape + broadcast_shape(x...) = Base.to_shape(Base.Broadcast.broadcast_shape(x...)) +else + const broadcast_shape = Base.Broadcast.broadcast_shape end end # module From 62376cef9054c6e852c659df3a58c89b2c8ebadc Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 12 Jul 2016 15:37:53 -0700 Subject: [PATCH 4/5] Qualify broadcast_shape in tests --- test/runtests.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6f38e53da..2cfdb67f8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1257,7 +1257,7 @@ let a = rand(10,10) @test view(a, :, 1) == a[:,1] end -@test broadcast_shape([1 2; 3 4], [1,1]) == (2,2) -@test broadcast_shape([1,2,3], 4) == (3,) -@test broadcast_shape() == () -@test broadcast_shape(4.3) == () +@test Compat.broadcast_shape([1 2; 3 4], [1,1]) == (2,2) +@test Compat.broadcast_shape([1,2,3], 4) == (3,) +@test Compat.broadcast_shape() == () +@test Compat.broadcast_shape(4.3) == () From d648a83d5863d43448a74b4b072894c8a7a83655 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Wed, 13 Jul 2016 10:41:38 -0700 Subject: [PATCH 5/5] Check that both OneTo and to_shape are defined --- src/Compat.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compat.jl b/src/Compat.jl index 2bd279255..84817a243 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1316,7 +1316,7 @@ if !isdefined(Base, :allunique) export allunique end -if isdefined(Base, :OneTo) +if isdefined(Base, :OneTo) && isdefined(Base, :to_shape) broadcast_shape(x...) = Base.to_shape(Base.Broadcast.broadcast_shape(x...)) else const broadcast_shape = Base.Broadcast.broadcast_shape