Replace int with SupportsIndex in indexing methods hints#766
Replace int with SupportsIndex in indexing methods hints#766
int with SupportsIndex in indexing methods hints#766Conversation
753697f to
8ccd67d
Compare
8ccd67d to
3c9c047
Compare
|
Thanks @honno. Adding a quick clarifying example: >>> import numpy as np
>>> import torch
>>>
>>> x = np.arange(1, 4)
>>> y = torch.arange(1, 4)
>>>
>>> class Ix:
... def __index__(self):
... return 1
...
>>> x[Ix()]
2
>>> y[Ix()]
tensor(2) |
0c9c42d to
18910c0
Compare
Might fix rendering/warning issue
|
@honno would you be able to open a PR with a test for this to |
|
|
||
|
|
||
| .. note:: | ||
| ``key`` can only be an array if it is valid for boolean array indexing, or supports ``__index__()``. |
There was a problem hiding this comment.
Presumably somewhere else we say it should support __index__ if and only if it is a 0-D integer array. Maybe it would be clearer to just say that directly here.
There was a problem hiding this comment.
Yep that'd help, let me know on the wording from my latest commit.
Good shout, I opened data-apis/array-api-tests#247 to check this all out. From the looks of it:
|
Let me know what you find out. We do run it on CI with some skips and xfails, and also the max-examples is set to 5. I haven't looked at the Dask xfails too closely, and obviously if we can remove any of those that would be great. CC @lithomas1 |
|
@honno Were you able to triage the Dask issues with the test suite? |
|
Got Dask working1—the latest release at least doesn't support indexables for both get and set items right now ( Footnotes
|
|
By the way, for implementers, the generally correct behavior is to |
|
@honno Is there anything more that we need to do with this PR? |
PR I think I'm happy with, just be mindful that last I checked in March it was only NumPy and PyTorch that supported "indexables", whereas JAX/CuPy/Dask didn't, so they'd need updating to support this. Example of what I mean by an indexable: class AwkwardIndexable:
def __init__(self, value: int):
self._value = value
def __int__(self):
raise TypeError("__int__() should not be called")
def __index__(self):
return self._value |
Resolves #383