Skip to content

Commit

Permalink
Make broadcast!(f, A) populate A via independent f() calls rather tha…
Browse files Browse the repository at this point in the history
…n fill!(A, f()).
  • Loading branch information
Sacha0 committed Dec 30, 2016
1 parent 242de06 commit 20c75d8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Symbol(x...) = Symbol(string(x...))
# specific array types etc.
# --Here, just define fallback routines for broadcasting with no arguments
broadcast(f) = f()
broadcast!(f, X::AbstractArray) = fill!(X, f())
broadcast!(f, X::AbstractArray) = (@inbounds for I in eachindex(X); X[I] = f(); end; X)

# array structures
include("array.jl")
Expand Down
3 changes: 3 additions & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,6 @@ end
@test (+).(Ref(1), Ref(2)) == fill(3)
@test (+).([[0,2], [1,3]], [1,-1]) == [[1,3], [0,2]]
@test (+).([[0,2], [1,3]], Ref{Vector{Int}}([1,-1])) == [[1,1], [2,2]]

# Check that broadcast!(f, A) populates A via independent calls to f (#12277, #19722).
@test let z = 1; A = broadcast!(() -> z += 1, zeros(2)); A[1] != A[2]; end

0 comments on commit 20c75d8

Please sign in to comment.