Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Diptorup Deb committed Jun 30, 2023
1 parent 3c543d6 commit d7c2405
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
23 changes: 19 additions & 4 deletions numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_empty_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,26 @@ def func(x, queue):
assert c.dtype == a.dtype
assert c.usm_type == a.usm_type
assert c.sycl_device == queue.sycl_device
assert c.sycl_queue == queue
assert c.sycl_queue == a.sycl_queue

if c.sycl_queue != queue:
pytest.xfail(
"Returned queue does not have the same queue as the one passed to the dpnp function."
)
try:
queue = dpctl.SyclQueue()
a1 = dpnp.ones(shape, dtype=dtype, usm_type=usm_type)
c1 = func(a1, queue)
except Exception:
pytest.fail("Calling dpnp.empty_like() inside dpjit failed.")

if len(c1.shape) == 1:
assert c1.shape[0] == a1.shape[0]
else:
assert c1.shape == a1.shape

assert c1.dtype == a1.dtype
assert c1.usm_type == a1.usm_type
assert c1.sycl_device == queue.sycl_device
assert c1.sycl_queue == queue
assert c1.sycl_queue != a1.sycl_queue


def test_dpnp_empty_like_exceptions():
Expand Down
24 changes: 20 additions & 4 deletions numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_ones_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,27 @@ def func(x, queue):
assert c.usm_type == a.usm_type
assert c.sycl_device == queue.sycl_device
assert (c.asnumpy() == 1).all()
assert c.sycl_queue == queue
assert c.sycl_queue == a.sycl_queue

if c.sycl_queue != queue:
pytest.xfail(
"Returned queue does not have the same queue as the one passed to the dpnp function."
)
try:
queue = dpctl.SyclQueue()
a1 = dpnp.zeros(shape, dtype=dtype, usm_type=usm_type)
c1 = func(a1, queue)
except Exception:
pytest.fail("Calling dpnp.ones_like() inside dpjit failed.")

if len(c1.shape) == 1:
assert c1.shape[0] == a1.shape[0]
else:
assert c1.shape == a1.shape

assert c1.dtype == a1.dtype
assert c1.usm_type == a1.usm_type
assert c1.sycl_device == queue.sycl_device
assert (c1.asnumpy() == 1).all()
assert c1.sycl_queue == queue
assert c1.sycl_queue != a1.sycl_queue


def test_dpnp_ones_like_exceptions():
Expand Down
27 changes: 22 additions & 5 deletions numba_dpex/tests/dpjit_tests/dpnp/test_dpnp_zeros_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def func(x):
device
):
pytest.xfail(
"Returned queue does not have the same queue as cached against the device."
"Returned queue does not have the same queue as cached against "
"the device."
)
assert not c.asnumpy().any()

Expand Down Expand Up @@ -116,11 +117,27 @@ def func(x, queue):
assert c.usm_type == a.usm_type
assert c.sycl_device == queue.sycl_device
assert not c.asnumpy().any()
assert c.sycl_queue == queue
assert c.sycl_queue == a.sycl_queue

if c.sycl_queue != queue:
pytest.xfail(
"Returned queue does not have the same queue as the one passed to the dpnp function."
)
try:
queue = dpctl.SyclQueue()
a1 = dpnp.zeros(shape, dtype=dtype, usm_type=usm_type)
c1 = func(a1, queue)
except Exception:
pytest.fail("Calling dpnp.ones_like() inside dpjit failed.")

if len(c1.shape) == 1:
assert c1.shape[0] == a1.shape[0]
else:
assert c1.shape == a1.shape

assert c1.dtype == a1.dtype
assert c1.usm_type == a1.usm_type
assert c1.sycl_device == queue.sycl_device
assert not c.asnumpy().any()
assert c.sycl_queue == queue
assert c1.sycl_queue != a1.sycl_queue


def test_dpnp_zeros_like_exceptions():
Expand Down

0 comments on commit d7c2405

Please sign in to comment.