-
Notifications
You must be signed in to change notification settings - Fork 105
feat: implement array compatibility/interface protocols for virtual array #3839
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
base: main
Are you sure you want to change the base?
feat: implement array compatibility/interface protocols for virtual array #3839
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files
🚀 New features to boost your workflow:
|
|
The documentation preview is ready to be viewed at http://preview.awkward-array.org.s3-website.us-east-1.amazonaws.com/PR3839 |
|
@pfackeldey we've been iterating over numpy arrays this whole time in certain edge cases. If you do |
| return iter(array) | ||
|
|
||
| def __array__(self, *args, **kwargs) -> ArrayLike: | ||
| return self.materialize().__array__(*args, **kwargs) # type: ignore[attr-defined] |
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.
This can also be
def __array__(self, dtype=None, copy=None):
return ak._nplikes.numpy.Numpy.instance().asarray(self.materialize(), dtype=dtype, copy=copy)I think and it would still be compatible with numpy1
This is to fix all the
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()issues we see with the cuda backend with__setitem__and__getitem__between virtual arrays with a cupy nplike and regular cupy arrays. We xfail several tests due to that. This will work with cupy 14 once it comes out and causes no errors otherwise. With cupy 14, the tests we xfail actually pass (tried with cupy installation from v14 pre-release) Once cupy 14 is out, we should remove those xfails too. See cupy/cupy#9089 and cupy/cupy#8352 and #3142 for more info.Also this is to fix a few more cases similar to the cupy issue but with the numpy backend where if you do
y[:] = xandyis a numpy array andxa virtual array, this will use__iter__and iterate over the virtual array like a python object. Adding the interface fixes that.