-
Notifications
You must be signed in to change notification settings - Fork 4
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
Remove __array__ #69
Remove __array__ #69
Conversation
This makes it raise an exception, since it isn't supported by the standard (if we just leave it unimplemented, then np.asarray() returns an object dtype array, which is not good). There is one issue here from the test suite, which is that this breaks the logic in asarray() for converting lists of array_api_strict 0-D arrays. I'm not yet sure what to do about that. Fixes data-apis#67.
In scikit-learn's tests we convert array API arrays to Numpy arrays in order to compare their values to some reference array. How would we do that if we remove |
Testing is a valid use-case. You could use dlpack if you wanted to stay within the standard. Although I'm still not clear if this is a good idea or not. |
Good point. We already have custom code to convert from the various array libraries to Numpy. Using x = xp.asarray([1,2,3], device=...)
np.from_dlpack(x) would maybe simplify that code and remove the need for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I'm still not clear if this is a good idea or not.
I think this is a good idea for array-api-strict
. Libraries that need to do any array conversion should only depend on __dlpack__
.
(Although this PR is breaking tests in this repo)
To clarify a note from the OP: this has stopped working >>> import array_api_strict as xp
>>> xp.asarray([[xp.asarray(1), xp.asarray(2)]])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/aaronmeurer/Documents/array-api-strict/array_api_strict/_creation_functions.py", line 97, in asarray
res = np.array(obj, dtype=_np_dtype, copy=copy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/aaronmeurer/Documents/array-api-strict/array_api_strict/_array_object.py", line 138, in __array__
raise ValueError("Conversion from an array_api_strict array to a NumPy ndarray is not supported")
ValueError: Conversion from an array_api_strict array to a NumPy ndarray is not supported because it was implicitly relying on |
Thinking about dlpack, should we be doing anything with the device emulation in |
I thought dlpack now allows you to move arrays from one device to another? For example to support the common case of "i would like to convert this array from library foo to a numpy array". Is that right? If yes, it could be cool to support this for the "not CPU devices" here. If only because (in scikit-learn) we convert things back to Numpy arrays during tests. |
This makes it raise an exception, since it isn't supported by the standard (if
we just leave it unimplemented, then np.asarray() returns an object dtype
array, which is not good).
There is one issue here from the test suite, which is that this breaks the
logic in asarray() for converting lists of array_api_strict 0-D arrays. I'm
not yet sure what to do about that.
Fixes #67.
This is built on #68, which can and should be merged separately (it isn't controversial).