spartialsortperm!!: partial sort perm function for sorting "top"-k of n with k<=n
#3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add a function
spartialsortperm!!that sorts the larges/smallestkelements of ann-array withk<=n. It's idea is to use a functionsselect!!to do quickselect to find thekth element and then calls the existingSimultaneousSortperm.jlfunctionality to obtain the sorted vector and corresponding permutation.I had a rough go at the
spartialsortperm!andspartialsortpermvariants but have commented them out since they are failing the tests.One thing to note: for the testsets, I only require
by.(v[p[1:k]])==by.(vref[pref[1:k]])wherevandpare the result ofspartialsortperm!!andvrefandprefare the result ofBase'ssortperm!, since there may be multiple "optimal" permutations. I noticed that your tests didn't do this before and am curious why you never encountered multiple "optimal" permutations forby=x->x÷100? Even after doing the second pass of sorting by index (unlessBase.jlalso does this?)Related to: #1 (comment)