Skip to content

Commit 0a44ab4

Browse files
Added tests for contiguous specialization of ndarray-to-usm-ndarray kernel
Used unitrace to verify that the contiguous kernel is exercised in both direct call to asarray (for C-contiguous numpy array) with type casting, and when assigning to usm-ndarray from numpy of different data type when both arrays are dense, but strides may be negative.
1 parent 1869f06 commit 0a44ab4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

dpctl/tests/test_usm_ndarray_ctor.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,3 +2583,40 @@ def test_full_like_order_K_same_input_output_queues():
25832583

25842584
r = dpt.full_like(x, fill_v, order="K")
25852585
assert r.sycl_queue == x.sycl_queue
2586+
2587+
2588+
def test_asarray_from_numpy_contig():
2589+
get_queue_or_skip()
2590+
2591+
i_dt = np.int64
2592+
Xnp = np.arange(32, dtype=i_dt)
2593+
2594+
fp_dt = dpt.float32
2595+
# Use contig copy kernel
2596+
Xdpt = dpt.asarray(Xnp, dtype=fp_dt)
2597+
2598+
assert dpt.all(Xdpt == dpt.arange(32, dtype=fp_dt))
2599+
2600+
2601+
def test_setitem_from_numpy_contig():
2602+
get_queue_or_skip()
2603+
2604+
i_dt = np.int64
2605+
fp_dt = dpt.float32
2606+
2607+
Xnp = np.flip(np.arange(32, dtype=i_dt))
2608+
Xdpt = dpt.flip(dpt.empty(Xnp.shape, dtype=fp_dt))
2609+
# Use contig copy kernel, after stride simplification
2610+
Xdpt[:] = Xnp
2611+
2612+
expected = dpt.arange(31, stop=-1, step=-1, dtype=fp_dt)
2613+
assert dpt.all(Xdpt == expected)
2614+
2615+
Xnp = np.fliplr(np.reshape(np.arange(-10, 10, dtype=i_dt), (4, 5)))
2616+
Xdpt = dpt.flip(dpt.empty(Xnp.shape, dtype=fp_dt), axis=-1)
2617+
2618+
# after stride simplification, contig kernel is used
2619+
Xdpt[:] = Xnp
2620+
2621+
expected = dpt.reshape(dpt.arange(-10, 10, dtype=fp_dt), (4, 5))
2622+
assert dpt.all(dpt.flip(Xdpt, axis=-1) == expected)

0 commit comments

Comments
 (0)