Skip to content

Add contains() method to check if an index is within array bounds#1593

Open
theoxfaber wants to merge 1 commit into
rust-ndarray:masterfrom
theoxfaber:add-contains-method
Open

Add contains() method to check if an index is within array bounds#1593
theoxfaber wants to merge 1 commit into
rust-ndarray:masterfrom
theoxfaber:add-contains-method

Conversation

@theoxfaber
Copy link
Copy Markdown

Adds a contains() method to ArrayBase to check whether a given index falls within array dimensions without accessing the element.

Closes #1247

let a = arr2(&[[1., 2.], [3., 4.]]);
assert!(a.contains((0, 1)));
assert!(!a.contains((2, 0)));

@akern40
Copy link
Copy Markdown
Collaborator

akern40 commented Jun 6, 2026

Could you please add a test or two on the new method? And rebase off of master as well, to fix potential CI issues

@theoxfaber theoxfaber force-pushed the add-contains-method branch from 0a1522b to 424f759 Compare June 7, 2026 12:52
@theoxfaber
Copy link
Copy Markdown
Author

Rebased on master and added 3 tests (1D, 2D, and empty array). All 194 tests pass locally including the new ones.

@akern40
Copy link
Copy Markdown
Collaborator

akern40 commented Jun 7, 2026

Sorry I see a force push but it looks like it just contains your changes still

@theoxfaber
Copy link
Copy Markdown
Author

yeah rebased on master and added the tests you asked for. thanks for checking.

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.

Array bounds/contains check?

2 participants