-
-
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
Make use of mapslices consistent throughout Julia #3893
Comments
You don't have to memorize the subset now; nothing stops you from applying We can promote the |
Yes, that's certainly true. But we've previously made many decisions to ensure that there aren't two dialects of Julia that provide two mechanisms for doing the same thing. I suspect I'll be outvoted on this one very quickly, but wanted to raise the issue for discussion. |
I think using a DIM keyword consistently would be cleanest. E.G., min(a,dim=2). |
@johnmyleswhite I appreciate the pursuit of consistency over function definitions. This is of course a very important aspect in language design. However, I think what we should do here is to add the support of computation along specified dimension to other functions over time, instead of removing this capability from Something like That being said, I think we may consider how to improve the consistency of the interface over these functions. (e.g. using |
I would be very happy with either the consistent use of a As Dahua points out, the major challenge (besides time) is making sure that the resulting interface is still high performance. |
I agree with @lindahua that I'd rather add this interface to the stats functions that don't have it rather than remove it from the ones that do. I use these in almost every data analysis script I write, and I find the compact syntax very convenient. We do need a more friendly syntax for |
Should we have perhaps have a |
I'm very much in favor of The performance difference just doesn't strike me as great enough to embrace such an inconsistency. But I also get that Julia has a strong Matlab background, and not having |
While it would be a fairly radical change, despite my Matlab background in principle I think this may be the right thing to do. But not now. The performance of |
Although Julia normally tries to have one way to do things, the cost/benefit ratio of keeping the Matlab-like syntax available (even if we promote This is independent of whether we can eliminate the performance penalty of |
Philosophically I totally agree with john, but on the practical side tim's and steve's comments nail it. |
I think we should only keep the dim argument for In addition to |
When you say special names, you mean that I actually like |
I mean that
We can make |
@JeffBezanson The problem is that |
I saw #17266 in NEWS and it made me wonder whether the performance of |
As much as it's been improved, we're still not there: julia> @time mapslices(maximum, A, 2);
0.001857 seconds (4.56 k allocations: 105.172 KB)
julia> @time maximum(A, 2);
0.000269 seconds (11 allocations: 4.422 KB) BenchmarkTools indicates a 6x difference. It's about a 3:5 ratio of time spent copying data into a temp array and in computing |
Looking at Another more extreme example: julia> @time maximum(a, 2);
0.014243 seconds (14 allocations: 7.630 MB)
julia> @time mapslices(maximum, a, 2);
2.958281 seconds (10.00 M allocations: 205.989 MB, 12.02% gc time) |
That's definitely true, though still a bit surprising that it matters so much given that the One thing that's really backwards is the fact that we accept |
@timholy That's exactly what I experimented with for a bit but there is a write to |
Sure, in the "preamble" just stuff |
I'm not sure I understand enough to be able to help. But with the new Julia closures scheme, it should be possible to make specialized methods of
we should be able to fix it?
in that case, we can just use specialized code for critical functions, which should be all already written P.S. if 2 is the case, then the same code specialization strategy could work for a lot of other functional programming functions, like P.P.S. we already have the fancy new dot syntax for broadcast. I wonder if there isn't the possibility for a similar fancy syntax for mapslices. Something like:
P.P.P.S. filter could also by worked into the syntax:
All that would be required is adding keyword versions of broadcast and broadcast! |
How about this for a deal: I'll take the time to write up (in the next couple of days) a blog post on tricks I've learned for writing high performance manipulations of multidimensional indices using tuple magic, and someone else agrees to use the information in that post to make It would actually be less work for me to just fix |
I tried poking around a bit yesterday but I had trouble wrapping my head around all the new unconventional index stuff so I wasn't sure what I did was safe or not and when I needed to special case to |
It should already be safe for unconventional indices, because I updated it already. (See tests here that prove it's working.) It's just down to stuffing things in the right slots now. |
I know it is safe now but I wasn't sure if my modifications were safe :). But yeah, you are right, can just check with the test. Was also a bit curious about the |
OneTo: Maybe needs a docstring, even though it's not exported? |
Wait do you mean changing a positional argument to a keyword argument with a new name in tens of functions? That doesn't make sense to me at all.... To maintain compatibility, it might make sense to have a positional dims argument for all of these functions deprecate to calling the function on a |
For better or worse, a lot of people use functions like |
I wouldn't mind having the keyword arguments for consistency in addition to the positional ones for convenience. But that whole idea could be tabled until the keyword penalty is fixed. |
if positional dims arguments were removed, then it would be easy to make predicate methods for |
We could keep the positional argument forms until we have fast keyword
arguments.
…On Thu, Aug 3, 2017 at 12:48 PM Steven G. Johnson ***@***.***> wrote:
For better or worse, a lot of people use functions like sum with tiny
arrays (also SVectors), and the keyword overhead worries me. I honestly
don't see what problem is being solved here: when you have a function with
only 2-3 arguments, positional arguments seem unobjectionable to me.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3893 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABnRaSmuDW5hWHMTkqeYkKHF1umKOwOtks5sUiQGgaJpZM4A3NpN>
.
|
IIRC, part of the reason |
This is the position I take. Maybe a renaming, like |
There might be an argument for eliminating separate functions just for reductions of existing functions. |
That argument would fail pretty badly once it got to |
I propose moving this to 2.0. It doesn't look like we'll have time to redo the mapping-over-slices infrastructure. |
Is there a reason this can't be in before 2.0, if it gets implemented? |
I have a working prototype which is ready to go, but requires several pending PRs related to type stable tuple operations. |
However, my prototype is breaking: it has a julienne iterator which can be mapped over (and a combine function for combining the resulting pieces). It is sometimes an order of magnitude faster than the current implementation of mapslices. |
It's not clear to me what is breaking here. We're not talking about changing meanings, just adding features or removing specific methods.
Are there any other possible actions here that are breaking? The only one I can see is:
|
There also is the issue that I still haven't beaten the performance of mapreducedims. I got around this in my version by a special optimization for reducing functions (sum, product, etc.) as well as a function optimization generalization (where you could pass Reduce(+) instead of sum to hook into mapreducedims. If this kind of behavior could also lead to mapreducedims being an unexported optimization rather than an export. |
Now that I've had a bit of time to look over it, I really like the JuliennedArrays.jl approach. There is probably some bikeshedding to be done regarding naming and the tuple syntax, but overall it feels like the right direction.
👍 |
Anything that's done in time and that has enough support can be in 1.0, and if non-breaking 1.x. The milestone is only needed if this is considered essential for 1.0. |
I think adding a composable way to express reductions with something like |
the danger of not addressing the consistency of the mapslices interface now is that the why is there a rush to tag 1.0? i would much rather wait another minor release cycle or two (ie 0.7) for issues like this to get fixed, than to have to wait for a presumably much longer major release (ie 2.0). |
I think we should aim to get a more efficient As for "why the rush?" that's pretty clear: many people are looking forward to not having their code break with each release. It's particularly a major disincentive for industrial adoption, but it's a drain even on us academics. If we wait too long, the world will move on to other technologies that may be less perfect but more predictable. It's time for 1.0. |
@bjarthur Could you expound a little bit on what you don't like about the
No ambiguities, and it gives obvious hooks for concrete types to specialize on. Does that satisfy your desire here? Or are you looking for bigger changes? |
@timholy i'll respectively disagree with your motivations for rushing. i personally enjoy the improvements in each new release. the pace and scope of such improvements is greater because breaking changes are permitted. we've got @mbauman my desire to deprecate |
Tada https://github.com/bramtayl/JuliennedArrays.jl is published. Sometimes an order of magnitude faster than mapslices and much more flexible. |
I think the the introduction of |
Stdlib: Pkg URL: https://github.com/JuliaLang/Pkg.jl.git Stdlib branch: master Julia branch: master Old commit: ed7a8dca8 New commit: 4e43058c2 Julia version: 1.12.0-DEV Pkg version: 1.12.0 Bump invoked by: @IanButterworth Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaLang/Pkg.jl@ed7a8dc...4e43058 ``` $ git log --oneline ed7a8dca8..4e43058c2 4e43058c2 Merge pull request #3887 from carlobaldassi/validate_versions bc7c3207d abort querying more pacakge for hint auto complete (#3913) a4016aed2 precompile repl switch (#3910) a48c9c645 Fixed glitch in the manual (#3912) d875aa213 Add timeout and new tests for resolver aeb55f7f0 run artifact selection code with minimal compilation (#3899) 0180a0105 avoid doing some checks if the package will not be showed in status output (#3897) c6c7ed502 improve precompilation for `st` in the Pkg REPL (#3893) bffd0633c Add version validation during Graph simplification c2ad07003 Fix padding in resolve's log journal printing 3eb86d29f Revert #2267, with better log message acdbb727e Small extra check in Graph's check_consistency 1d446c224 Fix small bug in Graph constructor 3efc3cbff Fix show method for VersionSpecs ``` Co-authored-by: Dilum Aluthge <[email protected]>
I'd like to propose the radical, breaking change of removing all forms of implicit mapslices calls from Julia. I think they make the language much less consistent and create a situation in which one's expectations are routinely violated about the interface for functions. As an example, the list below shows some functions that effectively implement implicit calls to
mapslices
:In contrast, the following similar functions do not support the
foo(A, dim)
interface at all:I understand that this change would break a great deal of Matlab compatibility and make the language a little more verbose. But I think the gains in consistency would more than make up for that loss by making the language much less confusing. Removing this shorthand would mean that you wouldn't have to memorize which functions belong to a privileged subset that perform implicit mapslices.
As one example of the memorization required to use the
foo(A, dim
) interface, you need to memorize that empty tuples passed tomin
are required to trickmin
into creating slices. I'd much rather know thatmapsplices
works the same way for all functions in the language.The text was updated successfully, but these errors were encountered: