Skip to content

refactor: share numeric sort and argsort comparators - #4475

Merged
ianna merged 3 commits into
scikit-hep:mainfrom
ianna:ianna/shared-numeric-sort-comparators
Nov 7, 2026
Merged

ianna merged 3 commits into
scikit-hep:mainfrom
ianna:ianna/shared-numeric-sort-comparators

Conversation

@ianna

@ianna ianna commented Oct 25, 2026

Copy link
Copy Markdown
Member

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.

@github-actions github-actions Bot added the type/refactor PR title type: refactor (set automatically) label Oct 25, 2026
@ianna
ianna requested a review from ariostas October 25, 2026 11:22
@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.45%. Comparing base (47193b4) to head (fab6a09).

Additional details and impacted files

@github-actions

Copy link
Copy Markdown
Contributor

The documentation preview is ready to be viewed at https://preview.awkward-array.org/PR4475/

@TaiSakuma

Copy link
Copy Markdown
Member

🤖 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.

Operation Size main / pr
direct awkward_sort / awkward_argsort kernel call small 0.99–1.02
direct awkward_sort / awkward_argsort kernel call large 0.98–1.02
ak.sort / ak.argsort large 0.98–1.02

No measurable difference.

🤖 Generated with Claude Code

@ianna
ianna enabled auto-merge (squash) November 7, 2026 21:13
@ianna
ianna merged commit 98231c8 into scikit-hep:main Nov 7, 2026
45 checks passed

This branch was previously deployed

1 inactive deployment
docs — fab6a091 Deployed Nov 7, 2026 by ianna via Remove Branch Preview #116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/refactor PR title type: refactor (set automatically)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants