Skip to content
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 3x broadcasting #19537

Closed
oscardssmith opened this issue Dec 8, 2016 · 16 comments
Closed

Make 3x broadcasting #19537

oscardssmith opened this issue Dec 8, 2016 · 16 comments

Comments

@oscardssmith
Copy link
Member

One of the really nice things about julia is the way you can write expressions in ways that look like regular math (eg x=3y+5z). This currently gets turned into x=3*y+5*z. This is great when y and z are scalar, but when they are array's, it would make more sense for this to be translated to x=3.*y+5.*z. This would allow everything to be fused, and in general look nicer.

@yuyichao
Copy link
Contributor

yuyichao commented Dec 8, 2016

This isn't legal.

@yuyichao yuyichao closed this as completed Dec 8, 2016
@oscardssmith
Copy link
Member Author

what does that mean?

@yuyichao
Copy link
Contributor

yuyichao commented Dec 8, 2016

And we pick the dot syntax exactly because we don't want to and cannot do this. (Not at parser level and hard in optimization)

@oscardssmith
Copy link
Member Author

what other way is there to interpret number*array?

@yuyichao
Copy link
Contributor

yuyichao commented Dec 8, 2016

You don't know that it's number * array.

@oscardssmith
Copy link
Member Author

There are a lot of times when you do. I am only asking for an optimization when the number is a literal in the code and the variable is in a function and has type info known.

@yuyichao
Copy link
Contributor

yuyichao commented Dec 8, 2016

You never know this at syntax level which is when the "translation" (lowering) happens. Therefore, it's a very hard optimization in inference that doesn't worth doing anymore.

@yuyichao
Copy link
Contributor

yuyichao commented Dec 8, 2016

And I said it's not worth doing since it's harder to implement, less reliable (effectively bring back the issue of having a set of blessed vectorized functions and not being able to extend the set) and we (will soon) have a more reliable alternative and doing this will encourage people to write code in the wrong way.

@Sacha0
Copy link
Member

Sacha0 commented Dec 8, 2016

For the context of @oscardssmith's question, please see #13603 (comment) where @stevengj states

For the specific case of numeric literal juxtaposition ala 3x, it would be possible to parse that as 3 .* x rather than 3 * x. I actually experimented with that in #17623 but reverted it to be conservative. It is still something that we can consider, but I would make it separate from #17623.

@oscardssmith
Copy link
Member Author

oscardssmith commented Dec 8, 2016

does something bad happen if we broadcast multiplication onto scalars? If not, it seems to me that we could just say 3x=broadcast(*,3,x) (no matter what x is), which would fix the problem.

@yuyichao
Copy link
Contributor

yuyichao commented Dec 8, 2016

It always works like that and it has nothing to do with fusion.

@stevengj
Copy link
Member

stevengj commented Dec 8, 2016

@yuyichao, the basic question here is whether 3x is parsed as 3*x (the current behavior, non-fusing) or 3 .* x (possible behavior, would be fusing after #17623). See the patch and discussion at 3638e93

@oscardssmith
Copy link
Member Author

Also new broadcast methods for sparse et al. Should remove most of the objections raised then.

@yuyichao
Copy link
Contributor

yuyichao commented Dec 8, 2016

... OK. sure. I'm not really sure if it's a good idea (it is indeed a distinct syntax but it's less explicit that the user actually want broadcasting/fusion) but that should be possible to implement.

The mentioning of "array vs scalar" at all in the original post was very confusing....

@yuyichao yuyichao reopened this Dec 8, 2016
@stevengj
Copy link
Member

I think we opted not to do this. The @. macro means that you can write @. 3x+5y and it will change it to 3 .* x .+ 5 .* y for you.

@oscardssmith
Copy link
Member Author

I agree that this makes little sense, especially in light of the decision to make linear algebra the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants