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

Regression: indexing by np.int64 indices #144

Closed
crusaderky opened this issue Apr 2, 2025 · 2 comments · Fixed by #146
Closed

Regression: indexing by np.int64 indices #144

crusaderky opened this issue Apr 2, 2025 · 2 comments · Fixed by #146
Milestone

Comments

@crusaderky
Copy link
Contributor

The Array API states:

An integer index must be an object satisfying operator.index (e.g., int).

Therefore, this is legal, because operator.index(np.int64(0)) works:

>>> import array_api_strict as xp
>>> import numpy as np
>>> a = xp.asarray([10, 20])
>>> a[np.int64(0)]
10

#139 broke it and caused a regression in scipy:

FAILED scipy/cluster/tests/test_vq.py::TestKMean::test_kmeans2_init[array_api_strict] - ValueError: Array indexing is only allowed when array to be indexed and all indexing arrays are on the same device.
FAILED scipy/cluster/tests/test_vq.py::TestKMean::test_kmeans2_kpp_low_dim[array_api_strict] - ValueError: Array indexing is only allowed when array to be indexed and all indexing arrays are on the same device.
FAILED scipy/cluster/tests/test_vq.py::TestKMean::test_kmeans2_kpp_high_dim[array_api_strict] - ValueError: Array indexing is only allowed when array to be indexed and all indexing arrays are on the same device.
FAILED scipy/cluster/tests/test_vq.py::TestKMean::test_kmeans_and_kmeans2_random_seed[array_api_strict] - ValueError: Array indexing is only allowed when array to be indexed and all indexing arrays are on the same device.

CC @lucyleeow

@ev-br
Copy link
Member

ev-br commented Apr 2, 2025

The MRE seems to work for me locally, is the error somewhere else?

(array-api) br@gonzales:~/repos/array-api-strict$ git slog |grep  ea5deb1 
ea5deb1 BUG: fix tuple array indexing
(array-api) br@gonzales:~/repos/array-api-strict$ pip uninstall array-api-strict
Found existing installation: array_api_strict 2.3.2.dev10+gd13ab1b
Uninstalling array_api_strict-2.3.2.dev10+gd13ab1b:
  Would remove:
    /home/br/miniforge3/envs/array-api/lib/python3.12/site-packages/__editable__.array_api_strict-2.3.2.dev10+gd13ab1b.pth
    /home/br/miniforge3/envs/array-api/lib/python3.12/site-packages/__editable___array_api_strict_2_3_2_dev10_gd13ab1b_finder.py
    /home/br/miniforge3/envs/array-api/lib/python3.12/site-packages/array_api_strict-2.3.2.dev10+gd13ab1b.dist-info/*
Proceed (Y/n)? y
  Successfully uninstalled array_api_strict-2.3.2.dev10+gd13ab1b
(array-api) br@gonzales:~/repos/array-api-strict$ pip install -e .
Obtaining file:///home/br/repos/array-api-strict
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in /home/br/miniforge3/envs/array-api/lib/python3.12/site-packages (from array_api_strict==2.3.2.dev10+gd13ab1b) (2.2.4)
Building wheels for collected packages: array_api_strict
  Building editable for array_api_strict (pyproject.toml) ... done
  Created wheel for array_api_strict: filename=array_api_strict-2.3.2.dev10+gd13ab1b-0.editable-py3-none-any.whl size=5483 sha256=46f7ca5418d07264e9d3b27e320d1b3f0d835db9861176cf54a30b5cbb357768
  Stored in directory: /tmp/pip-ephem-wheel-cache-d5vi4raq/wheels/4e/17/ac/e6163bc1f03b324024d273193e2a65d8b9f08267d8c679b750
Successfully built array_api_strict
Installing collected packages: array_api_strict
Successfully installed array_api_strict-2.3.2.dev10+gd13ab1b
(array-api) br@gonzales:~/repos/array-api-strict$ ipython
Python 3.12.0 | packaged by conda-forge | (main, Oct  3 2023, 08:43:22) [GCC 12.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 9.0.2 -- An enhanced Interactive Python. Type '?' for help.
Tip: `?` alone on a line will brings up IPython's help

In [1]: >>> import array_api_strict as xp
   ...: >>> import numpy as np
   ...: >>> a = xp.asarray([10, 20])
   ...: >>> a[np.int64(0)]
Out[1]: Array(10, dtype=array_api_strict.int64)

@crusaderky
Copy link
Contributor Author

Ah. It only happens with tuple indices.

>>> a[(np.int64(0), )]

ValueError: Array indexing is only allowed when array to be indexed and all indexing arrays are on the same device.

@ev-br ev-br closed this as completed in #146 Apr 3, 2025
@ev-br ev-br added this to the 2.4 milestone Apr 3, 2025
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 a pull request may close this issue.

2 participants