Skip to content

Commit 8393a75

Browse files
Make copy argument of __array__ method keyword-only
1 parent b6e3afe commit 8393a75

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

dpctl/tensor/_usmarray.pyx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,8 +1552,15 @@ cdef class usm_ndarray:
15521552
def __repr__(self):
15531553
return usm_ndarray_repr(self)
15541554

1555-
def __array__(self, dtype=None, copy=None):
1556-
"NumPy array protocol"
1555+
def __array__(self, dtype=None, /, *, copy=None):
1556+
"""NumPy's array protocol method to disallow implicit conversion.
1557+
1558+
Without this definition, `numpy.asarray(usm_ar)` converts
1559+
usm_ndarray instance into NumPy array with data type `object`
1560+
and every element being 0d usm_ndarray.
1561+
1562+
https://github.com/IntelPython/dpctl/pull/1384#issuecomment-1707212972
1563+
"""
15571564
raise TypeError(
15581565
"Implicit conversion to a NumPy array is not allowed. "
15591566
"Use `dpctl.tensor.asnumpy` to copy data from this "

0 commit comments

Comments
 (0)