Skip to content

refactor: reuse index normalization in array slicing kernels - #4474

Merged
ianna merged 5 commits into
scikit-hep:mainfrom
ianna:ianna/cxx23-array-index-normalization
Nov 7, 2026
Merged

ianna merged 5 commits into
scikit-hep:mainfrom
ianna:ianna/cxx23-array-index-normalization

Conversation

@ianna

@ianna ianna commented Oct 25, 2026

Copy link
Copy Markdown
Member

Reuse the scalar index-normalization helper from #4471 in awkward_ListArray_getitem_next_array, its advanced-indexing variant, and awkward_RegularArray_getitem_next_array_regularize.

Preserve starts/stops validation and its precedence over index errors, the original attempted index and failing row, advanced-index mappings, empty-index behavior, and partial writes. In particular, RegularArray continues to write the normalized failing index before returning its error. Kernel signatures, canonical reference definitions, CUDA implementations, and package versions are unchanged.

This draft targets main and requires only C++17. It depends on #4471; the current diff includes that PR’s shared helper, scalar-kernel refactor, and tests. After #4471 merges, rebase onto main to leave only this three-kernel extension. No dependency on the experimental C++23 PRs or evaluation workflow remains.

Validation after rebasing:

  • Rebuilt the CPU kernel library with AppleClang 17 and verified -std=c++17 in compiler flags.
  • All 102 focused scalar/array normalization checks passed against the rebuilt library.
  • 1,245 selected generated reference/CPU checks passed.
  • Diff checks passed; the new tests previously passed Ruff checks.
  • GPU execution and other compiler platforms remain unverified locally.

AI assistance: Codex assisted with implementation and validation.

@ianna
ianna marked this pull request as ready for review October 25, 2026 11:01
@ianna
ianna requested a review from ariostas October 25, 2026 11:01
@github-actions github-actions Bot added the type/refactor PR title type: refactor (set automatically) label Oct 25, 2026
@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 (cc05f98).
⚠️ Report is 1 commits behind head on main.

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/PR4474/

@TaiSakuma

Copy link
Copy Markdown
Member

🤖 This comment was written by Claude Code and posted by an automated workflow.


The PR replaces the inline negative-index normalization and bounds check in three CPU kernels (awkward_ListArray_getitem_next_array, awkward_ListArray_getitem_next_array_advanced, awkward_RegularArray_getitem_next_array_regularize) with awkward::kernel::normalize_index from kernel-utils.h. It adds tests/test_4474_array_index_normalization.py, which calls the three kernels directly and slices through ak.Array. The diff is based on a commit before #4471. #4471 is now on main, and its parts of this diff (kernel-utils.h, the two getitem_next_at kernels, tests/test_4471_scalar_index_checks.py) are identical to main.

Public API changes

None.

Changes to existing-test expectations

None.

Checked with no findings

Regressions from main.

Performance measurements

Probe probes/bench_4474.py: jagged[:, [-1, 0, 3, -5]], jagged[rows, adv] and regular[:, [-1, 0, 3, -5]] on 10×10 and 1,000,000×10 int64 arrays. 3 alternating runs per environment, best of 7 repetitions in each run. Ratio main / pr:

Operation n = 10 n = 1,000,000
ListArray [:, idx] 0.94 (0.939–0.947) 1.00 (0.98–1.04)
ListArray [rows, adv] 0.92 (0.917–0.930) 1.01 (0.99–1.04)
RegularArray [:, idx] 0.96 (0.953–0.962) 1.01 (1.00–1.02)

At n = 1,000,000 there is no measurable difference. At n = 10, slices that use no changed kernel ([:, 1:3]) have the same ratio, 0.88–0.94. The small-array difference therefore comes from code outside this PR: the PR head is 5 commits behind main.

Minor details

  • test_structural_error_precedes_index_error asserts error.attempt == 2**63 - 1. The structural failures report kSliceNone, which is also 2**63 - 1, so this assertion would pass even if the original index were not kept.

🤖 Generated with Claude Code

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

This branch was previously deployed

1 inactive deployment
docs — cc05f98c Deployed Nov 7, 2026 by ianna via Remove Branch Preview #119
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