Skip to content

Raise IndexError for out-of-range or negative sub_matrix indexes - #27

Open
CarlKCarlK wants to merge 1 commit into
mainfrom
sub-matrix-index-check
Open

CarlKCarlK wants to merge 1 commit into
mainfrom
sub-matrix-index-check

Conversation

@CarlKCarlK

Copy link
Copy Markdown
Contributor

Closes #26.

sub_matrix now checks row and column indexes before calling the Rust helper and raises IndexError naming the first bad index. Before, an out-of-range index (or a negative one in an ndarray, which wrapped to a huge uintp) made the Rust helper panic with PanicException, a BaseException that except Exception does not catch.

Behavior change: a negative index in a Python list used to raise OverflowError; it now raises IndexError like every other bad index. Valid indexes behave exactly as before.

Validation

  • New test test_sub_matrix_bad_index (2-D and 3-D, lists and arrays, rows and columns); it fails without the fix.
  • tests/test.py (legacy suite): 742 OK.
  • ruff check clean.

PR #25 (CuPy support) adds the same _checked_index helper for its CuPy path; whichever PR merges second keeps one copy.

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.

sub_matrix panics on an out-of-range or negative index

1 participant