diff --git a/dpctl/tensor/_copy_utils.py b/dpctl/tensor/_copy_utils.py index c80733f77f..6597febef3 100644 --- a/dpctl/tensor/_copy_utils.py +++ b/dpctl/tensor/_copy_utils.py @@ -739,6 +739,9 @@ def astype( order=copy_order, buffer_ctor_kwargs={"queue": usm_ary.sycl_queue}, ) + # see #2121 + if ary_dtype == dpt.bool: + usm_ary = dpt.not_equal(usm_ary, 0, order=copy_order) _copy_from_usm_ndarray_to_usm_ndarray(R, usm_ary) return R diff --git a/dpctl/tests/test_usm_ndarray_ctor.py b/dpctl/tests/test_usm_ndarray_ctor.py index c6e33b600c..b8e6929dcf 100644 --- a/dpctl/tests/test_usm_ndarray_ctor.py +++ b/dpctl/tests/test_usm_ndarray_ctor.py @@ -1541,6 +1541,16 @@ def test_astype_gh_1926(): assert x is x__ +def test_astype_gh_2121(): + get_queue_or_skip() + + x_np = np.asarray([0, 3, 1, 2, 0, 1], dtype="u1").view("?") + x = dpt.asarray(x_np) + res = dpt.astype(x, dpt.uint8) + expected = dpt.asarray([0, 1, 1, 1, 0, 1], dtype="u1") + assert dpt.all(res == expected) + + def test_copy(): try: X = dpt.usm_ndarray((5, 5), "i4")[2:4, 1:4]