Skip to content

Commit f791949

Browse files
committed
fix gh-2121
underlying memory of a boolean array may not be 0 and 1 when a boolean view is made from a non-boolean array, leading to unexpected results when copying element-wise, especially in astype use a special path for boolean inputs to astype to make sure output is 0 and 1
1 parent 6f6fe50 commit f791949

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

dpctl/tensor/_copy_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ def astype(
739739
order=copy_order,
740740
buffer_ctor_kwargs={"queue": usm_ary.sycl_queue},
741741
)
742+
# see #2121
743+
if ary_dtype == dpt.bool:
744+
usm_ary = dpt.not_equal(usm_ary, 0, order=order)
742745
_copy_from_usm_ndarray_to_usm_ndarray(R, usm_ary)
743746
return R
744747

0 commit comments

Comments
 (0)