Skip to content

Commit ab73617

Browse files
authored
Merge pull request #2122 from IntelPython/resolve-gh-2121
Fix for gh-2121
2 parents e2789db + 8e952d1 commit ab73617

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

dpctl/tensor/_copy_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,9 @@ def astype(
742742
order=copy_order,
743743
buffer_ctor_kwargs={"queue": usm_ary.sycl_queue},
744744
)
745+
# see #2121
746+
if ary_dtype == dpt.bool:
747+
usm_ary = dpt.not_equal(usm_ary, 0, order=copy_order)
745748
_copy_from_usm_ndarray_to_usm_ndarray(R, usm_ary)
746749
return R
747750

dpctl/tests/test_usm_ndarray_ctor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,16 @@ def test_astype_gh_1926():
15411541
assert x is x__
15421542

15431543

1544+
def test_astype_gh_2121():
1545+
get_queue_or_skip()
1546+
1547+
x_np = np.asarray([0, 3, 1, 2, 0, 1], dtype="u1").view("?")
1548+
x = dpt.asarray(x_np)
1549+
res = dpt.astype(x, dpt.uint8)
1550+
expected = dpt.asarray([0, 1, 1, 1, 0, 1], dtype="u1")
1551+
assert dpt.all(res == expected)
1552+
1553+
15441554
def test_copy():
15451555
try:
15461556
X = dpt.usm_ndarray((5, 5), "i4")[2:4, 1:4]

0 commit comments

Comments
 (0)