Skip to content

ENH: Add __array__ to the array_api Array object #20527

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 7, 2021

Conversation

asmeurer
Copy link
Member

@asmeurer asmeurer commented Dec 6, 2021

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 the 09 - Backport-Candidate PRs tagged should be backported label Dec 6, 2021
@charris
Copy link
Member

charris commented Dec 7, 2021

Does asarray work with other implementations? If not, how does DLPack solve the problem?

@charris charris merged commit b5331ea into numpy:main Dec 7, 2021
@charris
Copy link
Member

charris commented Dec 7, 2021

Thanks @asmeurer .

@asmeurer
Copy link
Member Author

asmeurer commented Dec 7, 2021

I only mean the problem of converting between the two NumPy array types. The more general question of how this would work in other implementations is something we are still considering.

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.

3 participants