Skip to content

Commit 90be1ed

Browse files
dpctl.tensor.asarray must check numpy array data-type
```python import numpy as np, dpctl.tensor as dpt dpt.asarray(np.array([1,2,3], dtype=object)) # now raises TypeError ```
1 parent 948bc65 commit 90be1ed

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

dpctl/tensor/_ctors.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _get_dtype(dtype, sycl_obj, ref_type=None):
4444
dtype = ti.default_device_complex_type(sycl_obj)
4545
return np.dtype(dtype)
4646
else:
47-
raise ValueError(f"Reference type {ref_type} not recognized.")
47+
raise TypeError(f"Reference type {ref_type} not recognized.")
4848
else:
4949
return np.dtype(dtype)
5050

@@ -199,6 +199,11 @@ def _asarray_from_numpy_ndarray(
199199
if usm_type is None:
200200
usm_type = "device"
201201
copy_q = normalize_queue_device(sycl_queue=None, device=sycl_queue)
202+
if ary.dtype.char not in "?bBhHiIlLqQefdFD":
203+
raise TypeError(
204+
f"Numpy array of data type {ary.dtype} is not supported. "
205+
"Please convert the input to an array with numeric data type."
206+
)
202207
if dtype is None:
203208
ary_dtype = ary.dtype
204209
dtype = _get_dtype(dtype, copy_q, ref_type=ary_dtype)

0 commit comments

Comments
 (0)