-
Notifications
You must be signed in to change notification settings - Fork 38
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
Broadcasting functions with side effects #29
Comments
This has been discussed in JuliaLang issues (I don't remember which ones). I believe the consensus is that the behaviour of broadcasting is "defined" by the I propose that the |
So the recommended solution is to use |
Okay. I take your point, but I really can't see how anyone would consider this behaviour intuitive. It's just completely different to what anyone expects to happen when you When I use a For example were I a new user, not well-versed in the implementation-details of broadcast, what possible reason could I have for expecting anything other than this behaviour? |
At the risk of labouring the point, using LinearAlgebra, Distributions, FillArrays
rand.(Normal.(Diagonal(Ones(10)))) produces a dense matrix as expected, and it would surprise me greatly if anyone would advocate for instead producing some structured output with one value on the diagonal and another everywhere else. |
Sorry, didn't mean to close the issue there. |
Your Diagonal example is misleading as the resulting matrix is not diagonal, but perhaps you are right. Is it possible to tell if a function is pure at compile time? Otherwise we can just have a list of pure functions like +, exp, etc. that we override broadcasted for |
I have no idea I'm afraid :(
Sounds reasonable to me. |
The current behaviour is consistent with sparse arrays in StdLib and so will remain unless StdLib changes: julia> A = sparse(I, 3,3); (_ -> randn()).(A)
3×3 SparseMatrixCSC{Float64,Int64} with 9 stored entries:
[1, 1] = 0.679325
[2, 1] = 1.54721
[3, 1] = 1.54721
[1, 2] = 1.54721
[2, 2] = -0.963752
[3, 2] = 1.54721
[1, 3] = 1.54721
[2, 3] = 1.54721
[3, 3] = -0.52672 |
yields something along the lines of
Unless I'm missing something obvious, it looks to me like the broadcasting implementation is making overly strong assumptions regarding the purity of whatever function is being broadcasted.
The text was updated successfully, but these errors were encountered: