Skip to content

feat(numpy): support negative indices in checked array accessors - #6201

Open
rwgk wants to merge 3 commits into
pybind:masterfrom
rwgk:numpy-normalize-negative-indices
Open

rwgk wants to merge 3 commits into
pybind:masterfrom
rwgk:numpy-normalize-negative-indices

Conversation

@rwgk

@rwgk rwgk commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Alternative to #6187, retaining both of its commits and adding NumPy-style negative indexing for checked array/array_t accessors and negative axes for shape()/strides().

#6187 rejects all negative indices; this wraps valid negative indices (-1 selects the last element or axis) and raises IndexError for indices outside the valid range. Unchecked accessors keep their existing behavior. See the discussion and local cost comparison.

Validation: local default and free-threaded CPython 3.14.4 test suites and prek -a --quiet passed.

Suggested changelog entry:

  • Support NumPy-style negative indices and axes in checked array and array_t accessors.

📚 Documentation preview 📚: https://pybind11--6201.org.readthedocs.build/

sayed0200 and others added 3 commits October 7, 2026 11:43
Use a single unsigned bounds compare, say in the error message that
negative indices are not supported, document the behavior on the
accessors, and cover offset_at/offset_at_t in test_bounds_check.

Assisted-by: ClaudeCode:claude-opus-5-5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants