Skip to content

Conversation

@ikrommyd
Copy link
Collaborator

@ikrommyd ikrommyd commented Feb 4, 2026

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[:] = x and y is a numpy array and x a virtual array, this will use __iter__ and iterate over the virtual array like a python object. Adding the interface fixes that.

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.63%. Comparing base (e4be9fe) to head (90bf00c).

Files with missing lines Patch % Lines
src/awkward/_nplikes/virtual.py 76.92% 3 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/awkward/_nplikes/virtual.py 91.16% <76.92%> (-0.96%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Feb 4, 2026

The documentation preview is ready to be viewed at http://preview.awkward-array.org.s3-website.us-east-1.amazonaws.com/PR3839

@ikrommyd ikrommyd marked this pull request as ready for review February 4, 2026 07:31
@ikrommyd
Copy link
Collaborator Author

ikrommyd commented Feb 4, 2026

@pfackeldey we've been iterating over numpy arrays this whole time in certain edge cases. If you do y[:] = x and y is a numpy array and x a virtual array, this uses __iter__ and iterates over the virtual array like a python object. Adding the interface makes numpy able to convert the virtual array into a numpy array instead of seeing it as an iterable.

@ikrommyd ikrommyd marked this pull request as draft February 4, 2026 15:44
@ikrommyd ikrommyd changed the title feat: implement array interface protocol for virtual array feat: implement array compatibility/interface protocols for virtual array Feb 4, 2026
return iter(array)

def __array__(self, *args, **kwargs) -> ArrayLike:
return self.materialize().__array__(*args, **kwargs) # type: ignore[attr-defined]
Copy link
Collaborator Author

@ikrommyd ikrommyd Feb 8, 2026

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

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.

1 participant