-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make broadcast!(f, A) populate A via independent f() calls #19722
Conversation
@@ -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) = (for I in eachindex(X); X[I] = f(); end; X) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any merit to using @inbounds
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and done. Thanks!
Candidate for 0.6? Tentatively adding to the milestone. Best! |
worth testing that this results in independent objects from the output of the function, rather than fill which would share references? |
Good call, and done. Thanks! |
Thanks for reviewing / merging! |
We also need to change |
(It could be argued that this is a bugfix that should be backported to Julia 0.5, since Julia 0.4 used independent |
broadcast!(f, A)
presently yieldsfill!(A, f())
. #12277 discusses makingbroadcast!(f, A)
instead populateA
via independentf()
calls. This pull request realizes that change. Best!