-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
842ef18
commit 0b1f6bd
Showing
2 changed files
with
74 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# SPDX-FileCopyrightText: 2020 - 2023 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""Tests for dpnp.arange() constructor.""" | ||
|
||
import dpctl | ||
import dpnp | ||
import numpy as np | ||
import pytest | ||
from numba import errors | ||
|
||
from numba_dpex import dpjit | ||
from numba_dpex.tests._helper import get_all_dtypes | ||
|
||
dtypes = get_all_dtypes( | ||
no_bool=True, no_float16=True, no_none=False, no_complex=True | ||
) | ||
usm_types = ["device", "shared", "host"] | ||
ranges = [ | ||
[1, None, None], | ||
[1, 10, None], | ||
[1, 10, 1], | ||
pytest.param( | ||
[-1.0, None, None], | ||
marks=pytest.mark.xfail( | ||
reason="numba-dpex can't allocate an empty array" | ||
), | ||
), | ||
pytest.param( | ||
[-1.0, 10, -2], marks=pytest.mark.xfail(reason="infinite loop") | ||
), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("dtype", dtypes) | ||
@pytest.mark.parametrize("range", ranges) | ||
@pytest.mark.parametrize("usm_type", usm_types) | ||
def test_dpnp_arange_start(range, dtype, usm_type): | ||
@dpjit | ||
def func(lb, ub, dx, dt, ut, dv): | ||
x = dpnp.arange(lb, ub, dx, dtype=dt, usm_type=ut, device=dv) | ||
return x | ||
|
||
device = dpctl.SyclDevice().filter_string | ||
try: | ||
c = func(*range, dtype, usm_type, device) | ||
except Exception: | ||
pytest.fail("Calling dpnp.arange() inside dpjit failed.") | ||
|
||
a = dpnp.arange(*range, dtype=dtype, usm_type=usm_type, device=device) | ||
|
||
print(a, c) | ||
|
||
assert a.dtype == c.dtype | ||
assert np.array_equal(a.asnumpy(), c.asnumpy()) | ||
assert c.usm_type == usm_type | ||
assert c.sycl_device.filter_string == device | ||
if c.sycl_queue != dpctl._sycl_queue_manager.get_device_cached_queue( | ||
device | ||
): | ||
pytest.xfail( | ||
"Returned queue does not have the same queue as cached against the device." | ||
) |