Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: Add __array__ to the array_api Array object #20578

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

Merged
merged 2 commits into from
Dec 13, 2021

Conversation

charris
Copy link
Member

@charris charris commented Dec 13, 2021

Backport of #20527.

This is NOT part of the array API spec (so it should not be relied on for
portable code). However, without this, np.asarray(np.array_api.Array) produces
an object array instead of doing the conversion to a NumPy array as expected.
This would work once np.asarray() implements dlpack support, but until then,
it seems reasonable to make the conversion work.

Note that the reverse, calling np.array_api.asarray(np.array), already works
because np.array_api.asarray() is just a wrapper for np.asarray().

This is *NOT* part of the array API spec (so it should not be relied on for
portable code). However, without this, np.asarray(np.array_api.Array) produces
an object array instead of doing the conversion to a NumPy array as expected.
This would work once np.asarray() implements dlpack support, but until then,
it seems reasonable to make the conversion work.

Note that the reverse, calling np.array_api.asarray(np.array), already works
because np.array_api.asarray() is just a wrapper for np.asarray().
@charris charris added this to the 1.22.0 release milestone Dec 13, 2021
@charris charris changed the title Backport 20527 ENH: Add __array__ to the array_api Array object Dec 13, 2021
@charris charris merged commit 9c68986 into numpy:maintenance/1.22.x Dec 13, 2021
@charris charris deleted the backport-20527 branch December 13, 2021 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants