Skip to content

Commit fc249e1

Browse files
committed
update tests for newly added integr dtypes (int8, int16, uint8-uint64)
1 parent 7e591e2 commit fc249e1

23 files changed

+521
-355
lines changed

.github/workflows/conda-package.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107

108108
strategy:
109109
matrix:
110-
python: ['3.9', '3.10', '3.11', '3.12']
110+
python: ['3.9', '3.10', '3.11']
111111

112112
continue-on-error: true
113113

@@ -193,7 +193,7 @@ jobs:
193193
python -m pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests
194194
195195
test_linux_all_dtypes:
196-
name: Test ['ubuntu-latest', python='${{ matrix.python }}']
196+
name: Test ['ubuntu-latest-all-dtypes', python='${{ matrix.python }}']
197197

198198
needs: build
199199

@@ -289,7 +289,7 @@ jobs:
289289

290290
strategy:
291291
matrix:
292-
python: ['3.9', '3.10', '3.11', '3.12']
292+
python: ['3.9', '3.10', '3.11']
293293

294294
continue-on-error: true
295295

@@ -409,7 +409,7 @@ jobs:
409409
python -m pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests
410410
411411
test_windows_all_dtypes:
412-
name: Test ['windows-2019', python='${{ matrix.python }}']
412+
name: Test ['windows-2019-all-dtypes', python='${{ matrix.python }}']
413413

414414
needs: build
415415

dpnp/dpnp_iface_linearalgebra.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737
3838
"""
3939

40+
# pylint: disable=no-name-in-module
4041
import numpy
4142

4243
import dpnp
4344

45+
from .dpnp_utils import map_dtype_to_device
4446
from .dpnp_utils.dpnp_utils_einsum import dpnp_einsum
4547
from .dpnp_utils.dpnp_utils_linearalgebra import (
4648
dpnp_dot,
@@ -64,6 +66,17 @@
6466
]
6567

6668

69+
# TODO: implement a specific scalar-array kernel
70+
def _call_multiply(a, b, out=None):
71+
"""Call multiply function for special cases of scalar-array dots."""
72+
73+
sc, arr = (a, b) if dpnp.isscalar(a) else (b, a)
74+
sc_dtype = map_dtype_to_device(type(sc), arr.sycl_device)
75+
res_dtype = dpnp.result_type(sc_dtype, arr)
76+
res = dpnp.multiply(a, b, dtype=res_dtype)
77+
return dpnp.get_result_array(res, out, casting="no")
78+
79+
6780
def dot(a, b, out=None):
6881
"""
6982
Dot product of `a` and `b`.
@@ -137,8 +150,7 @@ def dot(a, b, out=None):
137150
raise ValueError("Only C-contiguous array is acceptable.")
138151

139152
if dpnp.isscalar(a) or dpnp.isscalar(b):
140-
# TODO: use specific scalar-vector kernel
141-
return dpnp.multiply(a, b, out=out)
153+
return _call_multiply(a, b, out=out)
142154

143155
a_ndim = a.ndim
144156
b_ndim = b.ndim
@@ -627,8 +639,7 @@ def inner(a, b):
627639
dpnp.check_supported_arrays_type(a, b, scalar_type=True)
628640

629641
if dpnp.isscalar(a) or dpnp.isscalar(b):
630-
# TODO: use specific scalar-vector kernel
631-
return dpnp.multiply(a, b)
642+
return _call_multiply(a, b)
632643

633644
if a.ndim == 0 or b.ndim == 0:
634645
# TODO: use specific scalar-vector kernel
@@ -706,8 +717,7 @@ def kron(a, b):
706717
dpnp.check_supported_arrays_type(a, b, scalar_type=True)
707718

708719
if dpnp.isscalar(a) or dpnp.isscalar(b):
709-
# TODO: use specific scalar-vector kernel
710-
return dpnp.multiply(a, b)
720+
return _call_multiply(a, b)
711721

712722
a_ndim = a.ndim
713723
b_ndim = b.ndim
@@ -1043,8 +1053,7 @@ def tensordot(a, b, axes=2):
10431053
raise ValueError(
10441054
"One of the inputs is scalar, axes should be zero."
10451055
)
1046-
# TODO: use specific scalar-vector kernel
1047-
return dpnp.multiply(a, b)
1056+
return _call_multiply(a, b)
10481057

10491058
return dpnp_tensordot(a, b, axes=axes)
10501059

@@ -1107,13 +1116,13 @@ def vdot(a, b):
11071116
if b.size != 1:
11081117
raise ValueError("The second array should be of size one.")
11091118
a_conj = numpy.conj(a)
1110-
return dpnp.multiply(a_conj, b)
1119+
return _call_multiply(a_conj, b)
11111120

11121121
if dpnp.isscalar(b):
11131122
if a.size != 1:
11141123
raise ValueError("The first array should be of size one.")
11151124
a_conj = dpnp.conj(a)
1116-
return dpnp.multiply(a_conj, b)
1125+
return _call_multiply(a_conj, b)
11171126

11181127
if a.ndim == 1 and b.ndim == 1:
11191128
return dpnp_dot(a, b, out=None, conjugate=True)

dpnp/dpnp_iface_nanfunctions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ def nanstd(
987987
ddof : {int, float}, optional
988988
Means Delta Degrees of Freedom. The divisor used in calculations
989989
is ``N - ddof``, where ``N`` the number of non-NaN elements.
990-
Default: `0.0`.
990+
Default: ``0.0``.
991991
keepdims : {None, bool}, optional
992992
If ``True``, the reduced axes (dimensions) are included in the result
993993
as singleton dimensions, so that the returned array remains
@@ -1087,7 +1087,7 @@ def nanvar(
10871087
ddof : {int, float}, optional
10881088
Means Delta Degrees of Freedom. The divisor used in calculations
10891089
is ``N - ddof``, where ``N`` represents the number of non-NaN elements.
1090-
Default: `0.0`.
1090+
Default: ``0.0``.
10911091
keepdims : {None, bool}, optional
10921092
If ``True``, the reduced axes (dimensions) are included in the result
10931093
as singleton dimensions, so that the returned array remains

dpnp/fft/dpnp_utils_fft.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@ def _copy_array(x, complex_input):
282282
# r2c FFT, if input is integer or float16 dtype, convert to
283283
# float32 or float64 depending on device capabilities
284284
copy_flag = True
285-
dtype = map_dtype_to_device(dpnp.float64, x.sycl_device)
285+
if dtype in [dpnp.float16]:
286+
dtype = dpnp.float32
287+
else:
288+
dtype = map_dtype_to_device(dpnp.float64, x.sycl_device)
286289

287290
if copy_flag:
288291
x_copy = dpnp.empty_like(x, dtype=dtype, order="C")

dpnp/tests/helper.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,19 @@ def assert_dtype_allclose(
8585
assert dpnp_arr.dtype == numpy_arr.dtype
8686

8787

88-
def get_integer_dtypes():
88+
def get_integer_dtypes(no_unsigned=False):
8989
"""
9090
Build a list of integer types supported by DPNP.
9191
"""
9292

93+
dtypes = [dpnp.int32, dpnp.int64]
94+
9395
if config.all_int_types:
94-
return [
95-
dpnp.int8,
96-
dpnp.int16,
97-
dpnp.int32,
98-
dpnp.int64,
99-
dpnp.uint8,
100-
dpnp.uint16,
101-
dpnp.uint32,
102-
dpnp.uint64,
103-
]
96+
dtypes += [dpnp.int8, dpnp.int16]
97+
if not no_unsigned:
98+
dtypes += [dpnp.uint8, dpnp.uint16, dpnp.uint32, dpnp.uint64]
10499

105-
return [dpnp.int32, dpnp.int64]
100+
return dtypes
106101

107102

108103
def get_complex_dtypes(device=None):
@@ -152,12 +147,14 @@ def get_all_dtypes(
152147
no_float16=True,
153148
no_complex=False,
154149
no_none=False,
155-
device=None,
156150
xfail_dtypes=None,
157151
exclude=None,
152+
no_unsigned=False,
153+
device=None,
158154
):
159155
"""
160-
Build a list of types supported by DPNP based on input flags and device capabilities.
156+
Build a list of types supported by DPNP based on
157+
input flags and device capabilities.
161158
"""
162159

163160
dev = dpctl.select_default_device() if device is None else device
@@ -166,7 +163,7 @@ def get_all_dtypes(
166163
dtypes = [dpnp.bool] if not no_bool else []
167164

168165
# add integer types
169-
dtypes.extend(get_integer_dtypes())
166+
dtypes.extend(get_integer_dtypes(no_unsigned=no_unsigned))
170167

171168
# add floating types
172169
dtypes.extend(get_float_dtypes(no_float16=no_float16, device=dev))
@@ -239,10 +236,13 @@ def generate_random_numpy_array(
239236
seed_value = 42
240237
numpy.random.seed(seed_value)
241238

239+
if numpy.issubdtype(dtype, numpy.unsignedinteger):
240+
low = 0
241+
242242
# dtype=int is needed for 0d arrays
243243
size = numpy.prod(shape, dtype=int)
244244
a = numpy.random.uniform(low, high, size).astype(dtype)
245-
if numpy.issubdtype(a.dtype, numpy.complexfloating):
245+
if numpy.issubdtype(dtype, numpy.complexfloating):
246246
a += 1j * numpy.random.uniform(low, high, size)
247247

248248
a = a.reshape(shape)

dpnp/tests/test_amin_amax.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ def test_amax_amin(func, keepdims, dtype):
1717
[[-2.0, 5.0], [-2, -1.2]],
1818
[[1.0, -2.0], [5.0, -1.1]],
1919
],
20-
dtype=dtype,
2120
)
21+
if numpy.issubdtype(dtype, numpy.unsignedinteger):
22+
a = numpy.abs(a)
23+
a = a.astype(dtype)
2224
ia = dpnp.array(a)
2325

2426
for axis in range(len(a)):
@@ -28,20 +30,20 @@ def test_amax_amin(func, keepdims, dtype):
2830

2931

3032
def _get_min_max_input(type, shape):
31-
size = 1
32-
for i in range(len(shape)):
33-
size *= shape[i]
34-
33+
size = numpy.prod(shape)
3534
a = numpy.arange(size, dtype=type)
36-
a[int(size / 2)] = size * size
37-
a[int(size / 3)] = -(size * size)
35+
a[int(size / 2)] = size + 5
36+
if numpy.issubdtype(type, numpy.unsignedinteger):
37+
a[int(size / 3)] = size
38+
else:
39+
a[int(size / 3)] = -(size + 5)
3840

3941
return a.reshape(shape)
4042

4143

4244
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
4345
@pytest.mark.parametrize(
44-
"shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2,3)", "(4,5,6)"]
46+
"shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2, 3)", "(4, 5, 6)"]
4547
)
4648
def test_amax_diff_shape(dtype, shape):
4749
a = _get_min_max_input(dtype, shape)
@@ -59,7 +61,7 @@ def test_amax_diff_shape(dtype, shape):
5961

6062
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
6163
@pytest.mark.parametrize(
62-
"shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2,3)", "(4,5,6)"]
64+
"shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2, 3)", "(4, 5, 6)"]
6365
)
6466
def test_amin_diff_shape(dtype, shape):
6567
a = _get_min_max_input(dtype, shape)

dpnp/tests/test_arraycreation.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ def test_exception_subok(func, args):
182182
"dtype", get_all_dtypes(no_bool=True, no_float16=False)
183183
)
184184
def test_arange(start, stop, step, dtype):
185-
rtol_mult = 2
186-
if dpnp.issubdtype(dtype, dpnp.float16):
187-
# numpy casts to float32 type when computes float16 data
188-
rtol_mult = 4
185+
if numpy.issubdtype(dtype, numpy.unsignedinteger):
186+
start = abs(start)
187+
stop = abs(stop) if stop else None
188+
189+
# numpy casts to float32 type when computes float16 data
190+
rtol_mult = 4 if dpnp.issubdtype(dtype, dpnp.float16) else 2
189191

190192
func = lambda xp: xp.arange(start, stop=stop, step=step, dtype=dtype)
191193

@@ -701,7 +703,7 @@ def test_dpctl_tensor_input(func, args):
701703

702704

703705
@pytest.mark.parametrize("start", [0, -5, 10, -2.5, 9.7])
704-
@pytest.mark.parametrize("stop", [0, 10, -2, 20.5, 1000])
706+
@pytest.mark.parametrize("stop", [0, 10, -2, 20.5, 120])
705707
@pytest.mark.parametrize(
706708
"num",
707709
[1, 5, numpy.array(10), dpnp.array(17), dpt.asarray(100)],
@@ -850,7 +852,7 @@ def test_space_num_error():
850852
@pytest.mark.parametrize("endpoint", [True, False])
851853
def test_geomspace(sign, dtype, num, endpoint):
852854
start = 2 * sign
853-
stop = 256 * sign
855+
stop = 127 * sign
854856

855857
func = lambda xp: xp.geomspace(
856858
start, stop, num, endpoint=endpoint, dtype=dtype

dpnp/tests/test_bitwise.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ def test_bitwise_aliase2(self, lhs, rhs, dtype):
167167

168168
@pytest.mark.parametrize("dtype", get_integer_dtypes())
169169
def test_invert_out(dtype):
170-
np_a = numpy.arange(-5, 5, dtype=dtype)
170+
low = 0 if numpy.issubdtype(dtype, numpy.unsignedinteger) else -5
171+
np_a = numpy.arange(low, 5, dtype=dtype)
171172
dp_a = inp.array(np_a)
172173

173174
expected = numpy.invert(np_a)

dpnp/tests/test_fft.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,10 @@ def test_rfft_1D(self, dtype, n, norm):
816816

817817
result = dpnp.fft.rfft(a, n=n, norm=norm)
818818
expected = numpy.fft.rfft(a_np, n=n, norm=norm)
819-
assert_dtype_allclose(result, expected, check_only_type_kind=True)
819+
factor = 120 if dtype in [dpnp.int8, dpnp.uint8] else 8
820+
assert_dtype_allclose(
821+
result, expected, factor=factor, check_only_type_kind=True
822+
)
820823

821824
@pytest.mark.parametrize("n", [None, 5, 20])
822825
@pytest.mark.parametrize("norm", [None, "backward", "forward", "ortho"])

dpnp/tests/test_histogram.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class TestDigitize:
4444
],
4545
)
4646
def test_digitize(self, x, bins, dtype, right):
47+
if numpy.issubdtype(dtype, numpy.unsignedinteger) and bins[0] == -4:
48+
x = numpy.abs(x)
49+
bins = numpy.array([0, 2, 4, 6, 8])
4750
x = x.astype(dtype)
4851
bins = bins.astype(dtype)
4952
x_dp = dpnp.array(x)
@@ -527,18 +530,26 @@ def test_rand_data(self, dtype):
527530
v = numpy.random.randint(0, upper_bound, size=n, dtype=dtype)
528531
iv = dpnp.array(v)
529532

530-
expected_hist = numpy.bincount(v)
531-
result_hist = dpnp.bincount(iv)
532-
assert_array_equal(result_hist, expected_hist)
533+
if numpy.issubdtype(dtype, numpy.uint64):
534+
assert_raises(TypeError, numpy.bincount, v)
535+
assert_raises(ValueError, dpnp.bincount, iv)
536+
else:
537+
expected_hist = numpy.bincount(v)
538+
result_hist = dpnp.bincount(iv)
539+
assert_array_equal(result_hist, expected_hist)
533540

534541
@pytest.mark.parametrize("dtype", get_integer_dtypes())
535542
def test_arange_data(self, dtype):
536543
v = numpy.arange(100).astype(dtype)
537544
iv = dpnp.array(v)
538545

539-
expected_hist = numpy.bincount(v)
540-
result_hist = dpnp.bincount(iv)
541-
assert_array_equal(result_hist, expected_hist)
546+
if numpy.issubdtype(dtype, numpy.uint64):
547+
assert_raises(TypeError, numpy.bincount, v)
548+
assert_raises(ValueError, dpnp.bincount, iv)
549+
else:
550+
expected_hist = numpy.bincount(v)
551+
result_hist = dpnp.bincount(iv)
552+
assert_array_equal(result_hist, expected_hist)
542553

543554
@pytest.mark.parametrize("xp", [numpy, dpnp])
544555
def test_negative_values(self, xp):

0 commit comments

Comments
 (0)