Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: fix tuple array indexing #139

Merged
merged 6 commits into from
Apr 2, 2025
Merged

Conversation

lucyleeow
Copy link
Contributor

closes #134

When indexing with tuple containing Arrays, convert to numpy array (self._array) first. Not doing so results in e.g. "Can not convert array on the 'array_api_strict.Device('device1')' device to a Numpy array." error

Parametrized indexing tests for all devices. Also added shape checks in test because while working on this PR, I created a bug that was not picked up by the test in the current format as the bug also affected the loop arrays.

cc @ev-br

Copy link
Member

@ev-br ev-br left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a great start!

Now that we're at it, could you add some more checks:

For a.device == idx.device:

  • a[idx, 1].device == a.device
  • a[idx, ...].device == a.device
  • other legal ways of indexing preserve the device
    .
  • there's an error when indexing and indexed arrays are on different devices.

@ev-br ev-br added this to the 2.4 milestone Apr 1, 2025
@lucyleeow
Copy link
Contributor Author

there's an error when indexing and indexed arrays are on different devices

Good call, different devices were allowed. I've fixed but not 100% on wording of error message, happy to change.

np_key = key._array if isinstance(key, Array) else key
if isinstance(key, Array):
key = (key,)
np_key = key
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new naming key -> np_key, meant that I've had to add this line

Copy link
Member

@ev-br ev-br left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @lucyleeow !

@ev-br ev-br closed this Apr 2, 2025
@ev-br ev-br reopened this Apr 2, 2025
@ev-br ev-br merged commit ea5deb1 into data-apis:main Apr 2, 2025
40 checks passed
@ev-br
Copy link
Member

ev-br commented Apr 2, 2025

CI is green after the rerun, including just-added python 3.13 jobs. Thanks @lucyleeow , keep them coming!

@lucyleeow lucyleeow deleted the fix_tuple_index branch April 2, 2025 10:00
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.

Error with 2D array indexing using non 'CPU_DEVICE' devices
2 participants