You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor: share numeric sort and argsort comparators - #4475
Numeric sort and argsort duplicate their ascending/descending comparison logic, including boolean specializations and NaN handling. Move that logic into one internal NumericOrder<T, Ascending> comparator used by both kernels.
Preserve native-width integer comparisons, NaNs-first ordering in both directions, equivalent signed zeros, and stable/unstable dispatch. Kernel signatures, canonical reference definitions, CUDA implementations, and package versions are unchanged. This PR targets main directly and requires only C++17; it has no dependency on the experimental C++23 work.
Add direct kernel regressions covering all supported numeric types and argsort offset widths, ascending/descending and stable/unstable modes, integer limits, NaNs, infinities, signed zeros, empty segments, and 100 equal values. Unstable checks allow arbitrary ordering among equivalent values.
Validation against the rebuilt CPU kernel library with AppleClang 17 and -std=c++17:
249 Python checks passed, with 2 existing skips.
80 generated reference/CPU checks passed, with 114 skips for kernels without generated cases.
Standalone C++ comparator-property probes passed under UBSan for both directions: irreflexivity, asymmetry, transitivity, and transitivity of equivalence, including floating special values and extreme int64/uint64 values.
Ruff and diff checks passed.
Other compilers and GPU execution remain unverified locally; GPU implementations are unchanged.
AI assistance: Codex assisted with implementation and validation.
🤖 This comment was written by Claude Code and posted by an automated workflow.
The PR moves the ascending and descending comparators that awkward_sort.cpp and awkward_argsort.cpp each defined, along with their bool specializations, into one template, awkward::kernel::NumericOrder<T, Ascending>. The template is in a new header, awkward-cpp/include/awkward/numeric-sort.h, and both CPU kernels now call it. Kernel signatures, kernel-specification.yml, and the CUDA kernels are unchanged. A new test, tests/test_4475_shared_numeric_sort_comparators.py, calls awkward_sort and awkward_argsort directly for 11 numeric dtypes and 4 offset dtypes, in both directions and both stability modes.
Public API changes
None.
Changes to existing-test expectations
None.
Checked with no findings
Regressions from main.
Performance measurements
Each environment ran alternately (main, pr). Each value is the best of 7 repetitions. Large input: 200,000 lists with about 20 items each. Small input: 10 lists with about 5 items each. Dtypes: float64 with 1% NaN, and int64. Both directions and both stability modes.
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
type/refactorPR title type: refactor (set automatically)
2 participants
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.
Numeric sort and argsort duplicate their ascending/descending comparison logic, including boolean specializations and NaN handling. Move that logic into one internal
NumericOrder<T, Ascending>comparator used by both kernels.Preserve native-width integer comparisons, NaNs-first ordering in both directions, equivalent signed zeros, and stable/unstable dispatch. Kernel signatures, canonical reference definitions, CUDA implementations, and package versions are unchanged. This PR targets
maindirectly and requires only C++17; it has no dependency on the experimental C++23 work.Add direct kernel regressions covering all supported numeric types and argsort offset widths, ascending/descending and stable/unstable modes, integer limits, NaNs, infinities, signed zeros, empty segments, and 100 equal values. Unstable checks allow arbitrary ordering among equivalent values.
Validation against the rebuilt CPU kernel library with AppleClang 17 and
-std=c++17:AI assistance: Codex assisted with implementation and validation.