-
-
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
Alternative syntax for map(func, x)
#8450
Comments
+1 |
Or
But maybe I'm the only one who would prefer that? |
👎 If anything, I think Stefan's other suggestion of |
Like @ihnorton, I'm also not super fond of this idea. In particular, I dislike the asymmetry of having both |
Maybe we don't need special syntax. With #1470, we could do something like call(f::Callable,x::AbstractArray) = applicable(f,x) ? apply(f,x) : map(f,x) right? Perhaps this would be too magical though, to get auto-map on any function. |
@quinnj That one line summarizes my greatest fears about allowing call overloading. I won't be able to sleep for days. |
Not yet sure it's syntactically possible, but what about I think |
I would be onboard with |
We'd have to claw back some syntax for that, but if |
How does making |
lol, sorry for the scare @JeffBezanson! Haha, the call overloading is definitely a little scary, every once in a while, I think about the kinds of code obfuscation you can do in julia and with I think |
👎. Saving a couple of characters compared to using higher order functions I don't think is worth the cost in readability. Can you imagine a file with |
It seems likely we'll remove the |
func.(x)
as syntactic sugar for map(func, x)
map(func, x)
Wow, talk about stirring up a bees nest! I changed the name to better reflect the discussion. |
We could also rename 2-argument |
If some syntax is really necessary, how about (@JeffBezanson you're just afraid that someone is going to write CJOS or Moose.jl :) ... if we get that feature, just put it in the |
Currently writing |
Strikes me as more vectorization/implicit-cat hell. What would |
I'm not saying it's the best idea ever or even advocating for it – I'm just pointing out that it doesn't completely clash with the existing usage, which is itself a bit of a hack. If we could make the existing usage part of a more coherent pattern, that would be a win. I'm not sure what |
I feel that |
I think it does completely clash. To do this I think we'd have to give up |
I kind of feel like debating syntax here distracts from the more important change: making |
Obviously making |
Fully agreed. |
I agree with @JeffBezanson that |
Another reason to prefer |
@yuyichao, loop fusion seems like it should be possible if the functions are marked as |
Remember that the key goal here is to eliminate the need for |
Is there any drawback if it does loop fusion too? |
@yuyichao, loop fusion is a much harder problem, and it's not always possible even putting aside non-pure functions (e.g. see @StefanKarpinski's |
Another obstacle is that |
What I mean is that doing loop fusion by proving doing so is valid is hard, so we can let the parser do the transformation as part of the schematics. In the example above, it can be written as. It's also fine if |
I mean doing that in the compiler is hard (maybe not impossible), especially since the compiler needs to look into the complicated implementation of |
Maybe? It's an interesting idea, and doesn't seem impossible to define the |
Totally agree, especially since |
I don't want to derail this, but @yuyichao's suggestion gave me some ideas. The emphasis here is on which functions are vectorized, but that's always seems a bit misplaced to me – the real question is which variables to vectorize over, which completely determines the shape of the result. This is why I've been inclined to mark arguments for vectorization, rather than marking functions for vectorization. Marking arguments also allows for functions which vectorize over one argument but not another. That said, we can have both and this PR serves the immediate purpose of replacing the built-in vectorized functions. |
@StefanKarpinski, when you call So, for example, Do you have an example in mind where this would not be enough? |
I'm glad you like it. =) Just yet another extension that probably doesn't belong to the same round, it might be possible to use |
Yes, the lack of fusion for other operations was my main objection to |
👍 There are two concept huddled together in this discussion which are in fact quite orthogonal: |
@mschauer, |
Orthogonal was not the right word, they are just different enough to coexist. |
The point is, though, that we don't need separate syntaxes for the two cases. |
Once a member of the triumvirate (Stefan, Jeff, Viral) merges #15032 (which I think is merge-ready), I'll close this and file a roadmap issue to outline the remaining proposed changes: fix broadcast type-computation, deprecate |
Hey, I am very happy and grateful about 15032. I would not be dismissive of the discussion though. For example vectors of vectors and similar objects are still very awkward to use in julia but can sprout like weed as results of comprehensions. Good implicit notation not based on encoding iteration into singleton dimensions has the potential to ease this a lot, for example with the flexed out iterators and new generator expressions. |
I think this can be closed now in favor of #16285. |
This was discussed in some detail here. I was having trouble finding it, and thought it deserved its own issue.
The text was updated successfully, but these errors were encountered: