Skip to content

Commit bca57d5

Browse files
authored
update third party tests for newly added integr dtypes (int8, int16, uint8-uint64) (#2239)
In this PR, third party tests are update to pass with newly added integer dtypes (int8, int16, uint8, uint16, uint32, uint64). This PR is in continuation of #2233.
1 parent ebe4868 commit bca57d5

File tree

19 files changed

+192
-63
lines changed

19 files changed

+192
-63
lines changed

.github/workflows/conda-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ jobs:
529529
env:
530530
DPNP_TEST_ALL_INT_TYPES: 1
531531
run: |
532-
pytest -n auto -ra --pyargs ${{ env.PACKAGE_NAME }}.tests
532+
pytest -ra --pyargs ${{ env.PACKAGE_NAME }}.tests
533533
534534
upload:
535535
name: Upload ['${{ matrix.os }}', python='${{ matrix.python }}']

dpnp/dpnp_algo/dpnp_elementwise_common.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,13 @@ def __init__(
590590
def __call__(self, x, decimals=0, out=None, dtype=None):
591591
if decimals != 0:
592592
x_usm = dpnp.get_usm_ndarray(x)
593-
if dpnp.issubdtype(x_usm.dtype, dpnp.integer) and dtype is None:
594-
dtype = x_usm.dtype
595-
596593
out_usm = None if out is None else dpnp.get_usm_ndarray(out)
597-
x_usm = dpt.round(x_usm * 10**decimals, out=out_usm)
598-
res_usm = dpt.divide(x_usm, 10**decimals, out=out_usm)
594+
595+
if dpnp.issubdtype(x_usm.dtype, dpnp.integer):
596+
res_usm = dpt.round(x_usm, out=out_usm)
597+
else:
598+
x_usm = dpt.round(x_usm * 10**decimals, out=out_usm)
599+
res_usm = dpt.divide(x_usm, 10**decimals, out=out_usm)
599600

600601
if dtype is not None:
601602
res_usm = dpt.astype(res_usm, dtype, copy=False)

dpnp/dpnp_iface_manipulation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,20 @@ def copyto(dst, src, casting="same_kind", where=True):
14691469
f"but got {type(dst)}"
14701470
)
14711471
if not dpnp.is_supported_array_type(src):
1472+
no_dtype_attr = not hasattr(src, "dtype")
14721473
src = dpnp.array(src, sycl_queue=dst.sycl_queue)
1474+
if no_dtype_attr:
1475+
# This case (scalar, list, etc) needs special handling to
1476+
# behave similar to NumPy
1477+
if dpnp.issubdtype(src, dpnp.integer) and dpnp.issubdtype(
1478+
dst, dpnp.unsignedinteger
1479+
):
1480+
if dpnp.any(src < 0):
1481+
raise OverflowError(
1482+
"Cannot copy negative values to an unsigned int array"
1483+
)
1484+
1485+
src = src.astype(dst.dtype)
14731486

14741487
if not dpnp.can_cast(src.dtype, dst.dtype, casting=casting):
14751488
raise TypeError(

dpnp/tests/test_sycl_queue.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ def test_reduce_hypot(device):
810810
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
811811
[5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0],
812812
),
813+
pytest.param("round", [1.234, 2.567], 2),
813814
pytest.param("searchsorted", [11, 12, 13, 14, 15], [-10, 20, 12, 13]),
814815
pytest.param(
815816
"subtract",

dpnp/tests/test_usm_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ def test_1in_1out(func, data, usm_type):
740740
pytest.param("maximum", [0.0, 1.0, 2.0], [3.0, 4.0, 5.0]),
741741
pytest.param("minimum", [0.0, 1.0, 2.0], [3.0, 4.0, 5.0]),
742742
pytest.param("nextafter", [1, 2], [2, 1]),
743+
pytest.param("round", [1.234, 2.567], 2),
743744
pytest.param("searchsorted", [11, 12, 13, 14, 15], [-10, 20, 12, 13]),
744745
pytest.param(
745746
"tensordot",

dpnp/tests/third_party/cupy/core_tests/test_elementwise.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
import pytest
55

66
import dpnp as cupy
7-
from dpnp.tests.helper import has_support_aspect64
7+
from dpnp.tests.helper import (
8+
has_support_aspect64,
9+
is_win_platform,
10+
numpy_version,
11+
)
812
from dpnp.tests.third_party.cupy import testing
913

1014

@@ -94,20 +98,22 @@ class TestElementwiseType(unittest.TestCase):
9498
@testing.for_int_dtypes(no_bool=True)
9599
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
96100
def test_large_int_upper_1(self, xp, dtype):
97-
a = xp.array([0], dtype=numpy.int8)
101+
a = xp.array([0], dtype=xp.int8)
98102
b = xp.iinfo(dtype).max
99103
return a + b
100104

101105
@testing.for_int_dtypes(no_bool=True)
102106
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
103107
def test_large_int_upper_2(self, xp, dtype):
104-
if (
105-
numpy.issubdtype(dtype, numpy.unsignedinteger)
106-
and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0"
107-
):
108-
pytest.skip("numpy promotes dtype differently")
108+
if numpy_version() < "2.0.0":
109+
flag = dtype in [xp.int16, xp.int32, xp.int64, xp.longlong]
110+
if xp.issubdtype(dtype, xp.unsignedinteger) or flag:
111+
pytest.skip("numpy doesn't raise OverflowError")
112+
113+
if dtype in [xp.int8, xp.intc] and is_win_platform():
114+
pytest.skip("numpy promotes dtype differently")
109115

110-
a = xp.array([1], dtype=numpy.int8)
116+
a = xp.array([1], dtype=xp.int8)
111117
b = xp.iinfo(dtype).max - 1
112118
return a + b
113119

@@ -116,7 +122,7 @@ def test_large_int_upper_2(self, xp, dtype):
116122
def test_large_int_upper_3(self, xp, dtype):
117123
if (
118124
numpy.issubdtype(dtype, numpy.unsignedinteger)
119-
and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0"
125+
and numpy_version() < "2.0.0"
120126
):
121127
pytest.skip("numpy promotes dtype differently")
122128
elif (
@@ -134,7 +140,7 @@ def test_large_int_upper_3(self, xp, dtype):
134140
def test_large_int_upper_4(self, xp, dtype):
135141
if (
136142
numpy.issubdtype(dtype, numpy.unsignedinteger)
137-
and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0"
143+
and numpy_version() < "2.0.0"
138144
):
139145
pytest.skip("numpy promotes dtype differently")
140146
elif (
@@ -150,14 +156,28 @@ def test_large_int_upper_4(self, xp, dtype):
150156
@testing.for_int_dtypes(no_bool=True)
151157
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
152158
def test_large_int_lower_1(self, xp, dtype):
153-
a = xp.array([0], dtype=numpy.int8)
159+
if numpy_version() < "2.0.0":
160+
if dtype in [xp.int16, xp.int32, xp.int64, xp.longlong]:
161+
pytest.skip("numpy doesn't raise OverflowError")
162+
163+
if dtype in [xp.int8, xp.intc] and is_win_platform():
164+
pytest.skip("numpy promotes dtype differently")
165+
166+
a = xp.array([0], dtype=xp.int8)
154167
b = xp.iinfo(dtype).min
155168
return a + b
156169

157170
@testing.for_int_dtypes(no_bool=True)
158171
@testing.numpy_cupy_array_equal(accept_error=OverflowError)
159172
def test_large_int_lower_2(self, xp, dtype):
160-
a = xp.array([-1], dtype=numpy.int8)
173+
if numpy_version() < "2.0.0":
174+
if dtype in [xp.int16, xp.int32, xp.int64, xp.longlong]:
175+
pytest.skip("numpy doesn't raise OverflowError")
176+
177+
if dtype in [xp.int8, xp.intc] and is_win_platform():
178+
pytest.skip("numpy promotes dtype differently")
179+
180+
a = xp.array([-1], dtype=xp.int8)
161181
b = xp.iinfo(dtype).min + 1
162182
return a + b
163183

@@ -166,7 +186,7 @@ def test_large_int_lower_2(self, xp, dtype):
166186
def test_large_int_lower_3(self, xp, dtype):
167187
if (
168188
numpy.issubdtype(dtype, numpy.unsignedinteger)
169-
and numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0"
189+
and numpy_version() < "2.0.0"
170190
):
171191
pytest.skip("numpy promotes dtype differently")
172192
elif (

dpnp/tests/third_party/cupy/core_tests/test_ndarray_complex_ops.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55

66
import dpnp as cupy
7-
from dpnp.tests.helper import has_support_aspect64
87
from dpnp.tests.third_party.cupy import testing
98

109

@@ -41,8 +40,10 @@ def test_conjugate_pass(self, xp, dtype):
4140

4241
class TestAngle(unittest.TestCase):
4342

43+
# For dtype=int8, uint8, NumPy returns float16, but dpnp returns float32
44+
# so type_check=False
4445
@testing.for_all_dtypes()
45-
@testing.numpy_cupy_array_almost_equal(type_check=has_support_aspect64())
46+
@testing.numpy_cupy_array_almost_equal(type_check=False)
4647
def test_angle(self, xp, dtype):
4748
x = testing.shaped_arange((2, 3), xp, dtype)
4849
return xp.angle(x)

dpnp/tests/third_party/cupy/core_tests/test_ndarray_copy_and_view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def test_astype_type(self, src_dtype, dst_dtype, order):
338338
b = astype_without_warning(a, dst_dtype, order=order)
339339
a_cpu = testing.shaped_arange((2, 3, 4), numpy, src_dtype)
340340
b_cpu = astype_without_warning(a_cpu, dst_dtype, order=order)
341-
assert b.dtype.type == b_cpu.dtype.type
341+
assert b.dtype == b_cpu.dtype
342342

343343
@testing.for_orders("CAK")
344344
@testing.for_all_dtypes()

dpnp/tests/third_party/cupy/creation_tests/test_ranges.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,13 @@ def test_linspace_mixed_start_stop2(self, xp, dtype_range, dtype_out):
227227
# TODO (ev-br): np 2.0: had to bump the default rtol on Windows
228228
# and numpy 1.26+weak promotion from 0 to 5e-6
229229
if xp.dtype(dtype_range).kind in "u":
230-
start = xp.array([160, 120], dtype=dtype_range)
230+
# to avoid overflow, limit `val` to be smaller
231+
# than xp.iinfo(dtype).max
232+
if dtype_range == xp.uint8 or dtype_out == xp.uint8:
233+
val = 125
234+
else:
235+
val = 160
236+
start = xp.array([val, 120], dtype=dtype_range)
231237
else:
232238
start = xp.array([-120, 120], dtype=dtype_range)
233239
stop = 0

dpnp/tests/third_party/cupy/indexing_tests/test_indexing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ class TestChoose(unittest.TestCase):
204204
@testing.for_all_dtypes()
205205
@testing.numpy_cupy_array_equal()
206206
def test_choose(self, xp, dtype):
207+
# TODO: include additional dtype when dpnp#2201 is merged
208+
dtype_list = [xp.int8, xp.int16]
209+
if dtype in dtype_list or xp.issubdtype(dtype, xp.unsignedinteger):
210+
pytest.skip("dpnp.choose() does not support new integer dtypes.")
207211
a = xp.array([0, 2, 1, 2])
208212
c = testing.shaped_arange((3, 4), xp, dtype)
209213
return a.choose(c)

0 commit comments

Comments
 (0)