Skip to content

Commit 320e5e4

Browse files
committed
Fix full and full_like with fill_value that is a NumPy bool
NumPy bools do not subclass `numbers.Number` and therefore must be handled separately. Python bools do, so no logic is needed.
1 parent 748fde5 commit 320e5e4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

dpctl/tensor/_ctors.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,12 @@ def full(
11111111
sycl_queue=sycl_queue,
11121112
)
11131113
return dpt.copy(dpt.broadcast_to(X, shape), order=order)
1114-
elif not isinstance(fill_value, Number):
1114+
# TODO: verify if `np.True_` and `np.False_` should be instances of
1115+
# Number in NumPy, like other NumPy scalars and like Python bools
1116+
# check for `np.bool_` separately as NumPy<2 has no `np.bool`
1117+
elif not isinstance(fill_value, Number) and not isinstance(
1118+
fill_value, np.bool_
1119+
):
11151120
raise TypeError(
11161121
"`full` array cannot be constructed with value of type "
11171122
f"{type(fill_value)}"
@@ -1486,7 +1491,12 @@ def full_like(
14861491
)
14871492
_manager.add_event_pair(hev, copy_ev)
14881493
return res
1489-
elif not isinstance(fill_value, Number):
1494+
# TODO: verify if `np.True_` and `np.False_` should be instances of
1495+
# Number in NumPy, like other NumPy scalars and like Python bools
1496+
# check for `np.bool_` separately as NumPy<2 has no `np.bool`
1497+
elif not isinstance(fill_value, Number) and not isinstance(
1498+
fill_value, np.bool_
1499+
):
14901500
raise TypeError(
14911501
"`full` array cannot be constructed with value of type "
14921502
f"{type(fill_value)}"

0 commit comments

Comments
 (0)