diff --git a/pyopencl/array.py b/pyopencl/array.py index 97dc28dc4..df733a1cc 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -330,6 +330,7 @@ class Array: .. automethod :: get .. automethod :: get_async .. automethod :: copy + .. automethod :: __array__ .. automethod :: __str__ .. automethod :: __repr__ @@ -806,6 +807,21 @@ def copy(self, queue=_copy_queue): return result + def __array__(self, dtype=None): + """Return a numpy array copy of the array. + + Equivalent to :meth:`get` with no arguments. If `dtype` is given, two + copies of the input array will be made: one for the conversion, and + another for the cast. + + :arg dtype: a valid NumPy dtype, such as ``np.float64`` or + ``'float32'``. + + .. versionadded:: ... + """ + out = self.get().astype(dtype) + return out + def __str__(self): if self.queue is None: return (f"