-
-
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
WIP/RFC: Conversion/elimination of sort related functions (cf. #1850, #1539) #2066
Conversation
* Remove insertionsort, quicksort, mergesort, timsort in favor of sort(InsertionSort,...), sort(QuickSort,...), etc. * Removed underscores from search related function names: * sort_by -> sortby * search_sorted_* -> searchsorted* * issorted_{by,r} -> issorted{by,r} * etc.
+1 for these names |
Re: the |
I am ok with this - and would like to merge it. @kmsquire Can you rebase? |
This is a big change, let's not get antsy and jump the gun here. I have a few comments – I've been thinking about this. |
Ok, so some thoughts. I'm certainly on board with the renaming part of this. The To me the wins would come from the multiplication of sorting algorithms by generic functions that can be parameterized by those algorithms. For example, the following generic functions can be parameterized by sorting algorithms in this branch: sort,
sort!,
sortby,
sortby!,
sortr,
sortr!,
sortperm,
sortperm!,
sortpermr,
sortpermr!,
sortpermby,
sortpermby! Previously, The two questions for me are:
I'm not sure if we really need all these combinations, but it seems kind of good to be able to compute, e.g. sort permutations, using different sorting algorithms easily. Sometimes you need that kind of control. I'm not sure if we can express this in a simpler way, e.g. using higher order functions. One thought I've had is taking this even further: expressing sortby and sortr types of things using sorting types. Something like this: sort!(By, v)
sort!(Reverse, v)
sort!(By{QuickSort}, v)
sort!(Reverse{MergeSort}, v) This would allow us to pare down the number of sorting functions to just these four: sort,
sort!,
sortperm,
sortperm!, while adding only two more objects – Another thought on reverse sorting is that we might not need a function for it – instead, you can just sort and then reverse, as long as we have a very fast, optimized |
I forgot TimSort, which blows these numbers up even more. |
@StefanKarpinski The suggestion is compact, but definitely a bit weird. Rather than get rid of the How about |
Refactor of sorting, taking #2066 to its logical conclusion.
Refactor of sorting, taking #2066 to its logical conclusion.
Included in/superceded by f4b378b (Thanks Stefan!) |
This patch was prompted by the discussion in #1850, though it goes a bit beyond that:
insertionsort
,quicksort
,mergesort
,timsort
sort_by
->sortby
issorted_{by,r}
->issorted{by,r}
select_{by,r}
->select{by,r}
search_sorted_*
->searchsorted*
There is one general and a couple of specific issues I need feedback on:
What do people think of the
sort(SortName, v)
syntax? My opinion is that it's clearer to write and use, but I could go either way.@in_place_matrix_op
is a macro which creates versions of a function which operate along a dimension of a matrix. In this patch it is simplified to inline code generation. However,shuffle
incombinatorics.jl
also used this macro, and I'm not sure best how to proceed.at @toivoh's suggestion in rename: sort_by => sortby ? #1850, the function signature for specialized sorts is based on
However, since various forms of this function (
sort
,sortby
,sortr
, etc.) are produced using code generation, I had to jump through some hoops in order to properly prepend the type to the function arguments (see, e.g., https://github.com/JuliaLang/julia/pull/2066/files#L3R85). Is there a better way to do this?There might be a very slight performance hit (up to a few percent), though the machine I tested this on was under load, so it's not clear.
Any other general comments/suggestions welcome.