-
-
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
treat .= as syntactic sugar for broadcast! #17510
Conversation
Good to get these in before 0.5 (might as well take advantage of the otherwise unfortunate delays). |
Should be good to go as soon as I add a NEWS item. (I'd prefer to do that right before merging since NEWS items generate so many conflicts.) I'm seeing some apparently unrelated Travis and AppVeyor failures on certain platforms, but it appears that |
const expr_infix_wide = Set{Symbol}([ | ||
:(=), :(+=), :(-=), :(*=), :(/=), :(\=), :(^=), :(&=), :(|=), :(÷=), :(%=), :(>>>=), :(>>=), :(<<=), | ||
:(.=), :(.+=), :(.-=), :(.*=), :(./=), :(.\=), :(.^=), :(.&=), :(.|=), :(.÷=), :(.%=), :(.>>>=), :(.>>=), :(.<<=), | ||
:(&&), :(||), :(<:), :(=>), :($=)]) |
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.
does .$=
not work?
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.
@StefanKarpinski, @tkelman, tests are green. Okay to merge once I add a NEWS item? |
Ok by me. May warrant a @JeffBezanson review due to flisp slinging. |
The flisp changes are pretty trivial (it only looks like a lot of lines because I did a little refactoring of #17300, but most of those lines are just indentation changes and similar). |
Uh oh, I just realized a problem with this PR for backward compatibility. If you have an expression like: x[:] .*= 2 then it already updates I think I need to update the PR so that it detects when the lhs is a |
Okay, I have a PR almost ready to fix the |
* make x[...] .= ... assign in-place (fixes bug in #17510) * doc fix * You're the top! You're the Coliseum. * better var name
* treat .= as syntactic sugar for broadcast! * tests * optimized .= assignment of scalars and vector copies * .= documentation * fix show of .= ops * .-= tests * NEWS for .=
* make x[...] .= ... assign in-place (fixes bug in JuliaLang#17510) * doc fix * You're the top! You're the Coliseum. * better var name
As discussed in #16285, this PR treats
x .= ...
as syntactic sugar forbroadcast!(identity, x, ...)
, and furthermore fuses the broadcast loop with any nested "dot" calls. e.g.x .= sin.(y)
becomesbroadcast!(sin, x, y)
.The tricky parts were all done in #17300, so this PR seems fairly straightforward.
To do:
broadcast!(identity, x, scalar)
to callfill!
andbroadcast!(identity, x, y)
to callcopy!
.This should be a very non-disruptive change, because the
.=
assignment syntax is new.Note that
x .+= y
and so on is now transformed tox .= x .+ y
. However, dot operators likex .+ y
are not yet treated as dot calls(+).(x,y)
(and hence are not yet fused), which will be a more disruptive change.