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 a442f7139..84817a243 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1316,4 +1316,10 @@ if !isdefined(Base, :allunique) export allunique end +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 +end + end # module diff --git a/test/runtests.jl b/test/runtests.jl index 2eebbc7f0..2cfdb67f8 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 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) == ()