-
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
0e7f98f
commit 28d7234
Showing
3 changed files
with
143 additions
and
4 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
91 changes: 91 additions & 0 deletions
91
numba_dpex/tests/dpjit_tests/test_dpjit_complex_arg_types.py
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,91 @@ | ||
# SPDX-FileCopyrightText: 2020 - 2023 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import dpnp | ||
import numba as nb | ||
import numpy | ||
import pytest | ||
|
||
import numba_dpex as dpex | ||
|
||
N = 1024 | ||
|
||
|
||
@dpex.dpjit | ||
def prange_arg(a, b, c): | ||
for i in nb.prange(a.shape[0]): | ||
b[i] = a[i] * c | ||
|
||
|
||
@dpex.dpjit | ||
def prange_array(a, b, c): | ||
for i in nb.prange(a.shape[0]): | ||
b[i] = a[i] * c[i] | ||
|
||
|
||
list_of_dtypes = [ | ||
dpnp.complex64, | ||
dpnp.complex128, | ||
] | ||
|
||
list_of_usm_types = ["shared", "device", "host"] | ||
|
||
|
||
@pytest.fixture(params=list_of_dtypes) | ||
def input_arrays(request): | ||
a = dpnp.ones(N, dtype=request.param) | ||
c = dpnp.zeros(N, dtype=request.param) | ||
b = dpnp.empty_like(a) | ||
return a, b, c | ||
|
||
|
||
def test_dpjit_scalar_arg_types(input_arrays): | ||
"""Tests passing float and complex type dpnp arrays to a dpjit prange function. | ||
Args: | ||
input_arrays (dpnp.ndarray): Array arguments to be passed to a kernel. | ||
""" | ||
s = 2 | ||
a, b, _ = input_arrays | ||
|
||
prange_arg(a, b, s) | ||
|
||
nb = dpnp.asnumpy(b) | ||
nexpected = numpy.full_like(nb, fill_value=2) | ||
|
||
assert numpy.allclose(nb, nexpected) | ||
|
||
|
||
def test_dpjit_arg_complex_scalar(input_arrays): | ||
"""Tests passing complex type scalar and dpnp arrays to a dpjit prange function. | ||
Args: | ||
input_arrays (dpnp.ndarray): Array arguments to be passed to a kernel. | ||
""" | ||
s = 2 + 1j | ||
a, b, _ = input_arrays | ||
|
||
prange_arg(a, b, s) | ||
|
||
nb = dpnp.asnumpy(b) | ||
nexpected = numpy.full_like(nb, fill_value=2 + 1j) | ||
|
||
assert numpy.allclose(nb, nexpected) | ||
|
||
|
||
def test_dpjit_arg_complex_array(input_arrays): | ||
"""Tests passing complex type dpnp arrays to a dpjit prange function. | ||
Args: | ||
input_arrays (dpnp.ndarray): Array arguments to be passed to a kernel. | ||
""" | ||
|
||
a, b, c = input_arrays | ||
|
||
prange_array(a, b, c) | ||
|
||
nb = dpnp.asnumpy(b) | ||
nexpected = numpy.full_like(nb, fill_value=0 + 0j) | ||
|
||
assert numpy.allclose(nb, nexpected) |