Skip to content

Commit 1c17c34

Browse files
Convert object for fill_value using asarray for requested type
This relies on NumPy to raise OverflowError if the object can not be represented by requested data type.
1 parent 845382d commit 1c17c34

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

dpctl/tensor/_ctors.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,11 @@ def _get_arange_length(start, stop, step):
765765

766766

767767
def _to_scalar(obj, sc_ty):
768-
"A way to convert object to NumPy scalar type"
769-
zd_arr = np.asarray(obj).astype(sc_ty, casting="unsafe")
768+
"""A way to convert object to NumPy scalar type.
769+
Raises OverflowError if obj can not be represented
770+
using the requested scalar type.
771+
"""
772+
zd_arr = np.asarray(obj, dtype=sc_ty)
770773
return zd_arr[tuple()]
771774

772775

0 commit comments

Comments
 (0)