Skip to content

Commit

Permalink
fix performance regression in broadcasting in some cases (#33079)
Browse files Browse the repository at this point in the history
(cherry picked from commit 56fdb19)
  • Loading branch information
KristofferC committed Aug 26, 2019
1 parent 8e66361 commit 27a12c8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -798,13 +798,13 @@ Like [`broadcast`](@ref), except in the case of a 0-dimensional result where it
Broadcast automatically unwraps zero-dimensional results to be just the element itself,
but in some cases it is necessary to always return a container — even in the 0-dimensional case.
"""
function broadcast_preserving_zero_d(f, As...)
@inline function broadcast_preserving_zero_d(f, As...)
bc = broadcasted(f, As...)
r = materialize(bc)
return length(axes(bc)) == 0 ? fill!(similar(bc, typeof(r)), r) : r
end
broadcast_preserving_zero_d(f) = fill(f())
broadcast_preserving_zero_d(f, as::Number...) = fill(f(as...))
@inline broadcast_preserving_zero_d(f) = fill(f())
@inline broadcast_preserving_zero_d(f, as::Number...) = fill(f(as...))

"""
Broadcast.materialize(bc)
Expand Down

0 comments on commit 27a12c8

Please sign in to comment.