-
-
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
In broadcasted assignment, indexing on LHS is a view but indexing on RHS is not #35171
Comments
Yes, I agree this isn't great. The view on the LHS is required by its mutating semantics, whereas the (I've updated the title to clarify that it's a view, not a fuse.) |
Somehow I had assumed that in broadcasting expressions, indexing automatically created a view. Now that I think more about it, I rather like the idea of using the syntax As an aside, I think there is a close connection between views and fusing, The manual says:
My thinking is that in an expression like |
If you've not seen it, there's the much more comprehensive #30845. I agree the distinction between views and fuses is pedantic, but there's more overhead in the former and there are bigger implications in how we fuse into dot-expressions on the inside of the indexing and the APL semantics. |
Thanks,. I think I saw that discussion at some point but had since forgotten about it. |
I think it's still nice to make indexing lazy automatically. In principle we can fuse filtering and mapping with I think it is helpful to consider the issue here as lazy a = Base.dotviewr(x, i) # like dotview but for RHS
b = Base.broadcasted(f, a)
c = Base.materialize(b) ? |
so how would I do something like @. x[x>1]+=sign(x)*x which feels like a natural thing to want to do with broadcasting, but gives errors about object sizes. Seems to be that the RHS cannot depend on |
This is from https://discourse.julialang.org/t/what-is-the-fastest-way-to-update-a-particular-row-of-a-matrix-using-dot-syntax/36160/15.
The issue is that in an expression like
x[inds] .+= y
, thex[inds]
on the LHS of the assignment is broadcasted, but the impliedx[inds]
on the RHS is not (cf.%2
below):This is both surprising and performance-degrading as it creates an unnecessary allocation. In contrast,
x .+= y
is lowered in such a way that all terms on both LHS and RHS are fused into a single broadcast.It seems like it would be generally desirable to have
[...]
fuse into broadcasting on both sides of an assignment. However, as discussed in #19169 there are multiple possible semantics for broadcasted indexing, so we would have to think carefully about how the lowering was done so as not to make other behaviors inconsistent.See also #35158 for a performance issue prompted by the same discourse topic that prompted this issue.
The text was updated successfully, but these errors were encountered: