Skip to content

asarray partial fix #109

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

Closed
wants to merge 2 commits into from
Closed

Conversation

ivirshup
Copy link
Contributor

Attempt at a fix for asarray.

Opening as a draft in case someone else gets the opportunity to look at this earlier, as some cases still error. I think the test should be useful to anyone else attempting this.

@asmeurer
Copy link
Member

I'm not sure what the right fix here is. The code was correct before the __array__ check was added in 8ee1613, but I'm not completely clear what the purpose of that check was.

Also, this code seems to deal mostly with copy logic, and that logic needs to be refactored, similar to data-apis/array-api-strict#15 (at the very least, copy=False should work in numpy 2.0). This version of the function is going to be more complicated than the one in array-api-strict though because it also has to support things outside of the standard (i.e., any valid input to np.asarray), and also because it's a wrapper function that's reused for numpy, cupy, and dask.

@@ -42,6 +42,17 @@ def test_device(library):
x2 = to_device(x, dev)
assert device(x) == device(x2)

@pytest.mark.parametrize("target_library,func", is_functions.items())
@pytest.mark.parametrize("source_library", is_functions.keys())
def test_asarray(source_library, target_library, func):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this test. We are going to need to add a lot of tests here for asarray, partly because the test suite only handles things within the scope of the standard, and partly because the test suite itself doesn't test as much as it could (data-apis/array-api-tests#241). We can also adopt the tests from data-apis/array-api-strict#15 (once we have fixed the copy behavior, but I expect that will need to just be part of this overall fix since this is part of that logic).

@asmeurer
Copy link
Member

This was included with #110

@asmeurer asmeurer closed this Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants