-
-
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
allow standalone dotted operators #35706
Conversation
Does this still fuse nested dot operations with other dot calls? |
No, this doesn't do any fusing with other dot calls, but I am not sure we really want that, since this would make broadcast fusing less transparent and make it not just a syntactic guarantee anymore. Since it just ends up calling |
This way `.*` will behave as a scalar when broadcasting, for example.
No, I mean if you do e.g. |
Yes, those cases should not be affected at all, since broadcast fusion happens before this expansion. That's also why |
Also needs a NEWS item under "language changes". My understanding is that the only cases that this affects were previously syntax errors, so that this is a backwards-compatible change? |
|
Technically, this change could be breaking, if a package assigned to |
It should also be fairly easy to make this backwards-compatible in |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan |
One thing that's still a bit unfortunate is that just typing |
Seems like it should be changed in the |
This works!?!
I believe this should now work. Please don't ask me how! 😆 It would be good if you or someone else could give this a more thorough review, since I was literally just poking at stuff until it worked. |
I'm in favor of this, but I find it pretty unsettling for a symbol to lower to a non-trivial expression. A small example is something like the In hindsight, we should have parsed |
I am afraid, I can't quite follow. Should this whole transformation occur in the parser first? What I like about doing this during lowering is that it's (almost) entirely non breaking. But I agree that parsing as |
If we change the parsing, the main thing that can break is macros --- a macro looking for Or, we could potentially keep compatibility by converting |
I do like this idea, but ASTs can come from sources other than macro arguments so I'm not sure it would work well enough for compatibility. Kind of hard to say without testing. |
f::F | ||
end | ||
|
||
@inline (op::BroadcastFunction)(x...) = op.f.(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.
Might as well pass along kwargs here, too, yeah?
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.
Makes sense! Didn't think of that.
At some point I'll try implementing my comment above --- keep parsing the same for called operators, parse as |
That would be great! I tried implementing your suggestion myself, but didn't get very far with it. |
Replaced by #37583 I assume? |
Oh, sure! Just forgot to close this. |
This lowers dotted operators to
Base.BroadcastOp(op)
, which allows for passing them as closures to functions. One example where this can be really helpful is for array-of-array type data structures, where you want to map a broadcasted function, so you can just domap(.+, [[1,2], [3,4]], [5, 6])
. This came up in #35150, wherehadamard
was proposed, because mapping broadcasted multiplication is currently quite cumbersome to write. Does this implementation make sense?close #34156