Skip to content

Commit 5929d6b

Browse files
Improved error handling for usm_ndarray.__setitem__
```python import dpctl.tensor as dpt, numpy as np u, n = dpt.empty(5), np.ones(5, dtype="O") u[...] = n ``` This example used to raise a cascade of exceptions starting with cryptic "RuntimeError: Unrecogized typenum 17 encountered.", where typenum 17 corresponds to type object. After this change, the error message is crisper: ``` ValueError: Input of type <class 'numpy.ndarray'> can not be \ assigned to usm_ndarray because of unsupported data \ type 'object' ```
1 parent df25aa0 commit 5929d6b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

dpctl/tensor/_usmarray.pyx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,13 +1110,19 @@ cdef class usm_ndarray:
11101110
"converted to usm_ndarray"
11111111
)
11121112
else:
1113+
rhs_np = np.asarray(rhs)
1114+
if type_bytesize(rhs_np.dtype.num) < 0:
1115+
raise ValueError(
1116+
f"Input of type {type(rhs)} can not be "
1117+
"assigned to usm_ndarray because of "
1118+
f"unsupported data type '{rhs_np.dtype}'"
1119+
)
11131120
try:
1114-
rhs_np = np.asarray(rhs)
11151121
_copy_from_numpy_into(Xv, rhs_np)
11161122
except Exception:
11171123
raise ValueError(
11181124
f"Input of type {type(rhs)} could not be "
1119-
"converted to usm_ndarray"
1125+
"copied into dpctl.tensor.usm_ndarray"
11201126
)
11211127
return
11221128

0 commit comments

Comments
 (0)