array-api-compat icon indicating copy to clipboard operation
array-api-compat copied to clipboard

ENH: torch: allow negative indices in `take` and `take_along_axis`

Open ev-br opened this issue 1 month ago • 3 comments

fixes https://github.com/data-apis/array-api-compat/issues/360

A matching test update: https://github.com/data-apis/array-api-tests/pull/397

ev-br avatar Nov 22 '25 15:11 ev-br

How can we see that torch passes the test with this change

Locally one incantation is (run from the source tree of the array_api_tests clone):

ARRAY_API_TESTS_SKIP_DTYPES=uint16,uint32,uint64 ARRAY_API_TESTS_MODULE=array_api_compat.torch pytest array_api_tests/test_indexing_functions.py::test_take_along_axis -v --max-examples=10_000 -s

On CI, we'll need to land the array-api-tests fix first, and rerun the CI here to pick up the updated master branch of array-api-tests.

ev-br avatar Nov 23 '25 09:11 ev-br

Oh, OK. Well the test change looked good, so I'll see when it runs here.

mdhaber avatar Nov 23 '25 14:11 mdhaber

Now that https://github.com/pytorch/pytorch/issues/146211 is fixed in pytorch, we'll be able to undo the workaround of this PR for take_along_axis--- when the minimum supported torch version includes the fix. What is the support window for torch and other backends is not very well defined though, this probably something to discuss at a consortium meeting.

Also, we still need the workaround for take: need Tensor.index_select to support negative indices, which it does not.

ev-br avatar Nov 25 '25 15:11 ev-br

https://github.com/data-apis/array-api-tests/pull/397#issuecomment-3602935540 : tests aiming to probe this pass locally, let's see if CI agrees.

EDIT: and it does. Merging.

ev-br avatar Dec 02 '25 16:12 ev-br