Skip to content
19 changes: 18 additions & 1 deletion src/awkward/_nplikes/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def __deepcopy__(self, memo) -> VirtualNDArray:
return new_virtual

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
return self.nplike.apply_ufunc(ufunc, method, inputs, kwargs)
return self._nplike.apply_ufunc(ufunc, method, inputs, kwargs)

def __repr__(self):
dtype = repr(self._dtype)
Expand Down Expand Up @@ -405,6 +405,23 @@ def __iter__(self):
array = self.materialize()
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


def __cupy_get_ndarray__(self) -> ArrayLike:
return ak._nplikes.cupy.Cupy.instance().asarray(self.materialize())

def __jax_array__(self) -> ArrayLike:
return ak._nplikes.jax.Jax.instance().asarray(self.materialize())

@property
def __array_interface__(self) -> dict[str, Any]:
return self.materialize().__array_interface__ # type: ignore[attr-defined]

@property
def __cuda_array_interface__(self) -> dict[str, Any]:
return self.materialize().__cuda_array_interface__ # type: ignore[attr-defined]

def __dlpack_device__(self) -> tuple[int, int]:
return self.materialize().__dlpack_device__() # type: ignore[attr-defined]

Expand Down
Loading