Repository navigation
Fix argsort's sorted-input check for a runtime descending flag - #246
Open
Dhruvdesai793 wants to merge 1 commit into
Open
Dhruvdesai793 wants to merge 1 commit into
Dhruvdesai793 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix argsort's sorted-input check for a runtime
descendingflagThe current code passes a runtime-selected comparator pointer to
std::is_sorted, which can mean an indirect call for each comparison. The patch selects between two complete scans. Each scan has a fixed comparator that the compiler can inline.Benchmarks
I built the original and patched headers on my Ryzen AI 7 350 with GCC 16.2.1,
-std=c++17 -O3 -march=haswell. An initial single run timed 100 calls on one million already-sorted values with runtimedescending:I also compared literal
falsewith runtimefalse, using reversedint32_tas a control. This benchmark checks the result, averages 20 calls per run, and alternates build order over three runs. The ranges are:The sorted-input gain was consistent. I couldn't reproduce the constant-versus-runtime gap from #240 here. These are static API timings, not NumPy timings; the reversed control was close, but slightly slower with the patch.
Benchmark source: