Skip to content

Commit 84d9c61

Browse files
authored
Merge 22c04a5 into 2bea896
2 parents 2bea896 + 22c04a5 commit 84d9c61

File tree

17 files changed

+196
-29
lines changed

17 files changed

+196
-29
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,10 @@ def __call__(self, x, decimals=0, out=None, dtype=None):
594594
dtype = x_usm.dtype
595595

596596
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)
597+
# the output of x_usm multiplied by 10^decimals should be
598+
# float to avoid overflow for integer dtypes
599+
x_usm = dpt.multiply(x_usm, float(10**decimals))
600+
x_usm = dpt.round(x_usm, out=out_usm)
598601
res_usm = dpt.divide(x_usm, 10**decimals, out=out_usm)
599602

600603
if dtype is not None:

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+
src_orig = src
14721473
src = dpnp.array(src, sycl_queue=dst.sycl_queue)
1474+
if not hasattr(src_orig, "dtype"):
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/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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ def test_conjugate_pass(self, xp, dtype):
4141

4242
class TestAngle(unittest.TestCase):
4343

44+
# For dtype=int8, uint8, NumPy returns float16, but dpnp returns float32
45+
# so type_check=False
4446
@testing.for_all_dtypes()
45-
@testing.numpy_cupy_array_almost_equal(type_check=has_support_aspect64())
47+
@testing.numpy_cupy_array_almost_equal(type_check=False)
4648
def test_angle(self, xp, dtype):
4749
x = testing.shaped_arange((2, 3), xp, dtype)
4850
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ 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+
if dtype_range == xp.uint8 or dtype_out == xp.uint8:
231+
val = 125
232+
else:
233+
val = 160
234+
start = xp.array([val, 120], dtype=dtype_range)
231235
else:
232236
start = xp.array([-120, 120], dtype=dtype_range)
233237
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)

dpnp/tests/third_party/cupy/linalg_tests/test_einsum.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ class TestEinSumBinaryOperation:
471471
type_check=has_support_aspect64(), contiguous_check=False
472472
)
473473
def test_einsum_binary(self, xp, dtype_a, dtype_b):
474+
if all(dtype in [xp.int8, xp.uint8] for dtype in [dtype_a, dtype_b]):
475+
pytest.skip("avoid overflow")
474476
a = testing.shaped_arange(self.shape_a, xp, dtype_a)
475477
b = testing.shaped_arange(self.shape_b, xp, dtype_b)
476478
# casting should be added for dpnp to allow cast int64 to float32
@@ -555,13 +557,20 @@ def test_scalar_2(self, xp, dtype):
555557
)
556558
)
557559
class TestEinSumTernaryOperation:
560+
558561
@testing.for_all_dtypes_combination(
559562
["dtype_a", "dtype_b", "dtype_c"], no_bool=False, no_float16=False
560563
)
561564
@testing.numpy_cupy_allclose(
562565
type_check=has_support_aspect64(), contiguous_check=False
563566
)
564567
def test_einsum_ternary(self, xp, dtype_a, dtype_b, dtype_c):
568+
flag = all(
569+
dtype in [xp.int8, xp.uint8]
570+
for dtype in [dtype_a, dtype_b, dtype_c]
571+
)
572+
if self.subscripts == "ij,jk,kl" and flag:
573+
pytest.skip("avoid overflow")
565574
a = testing.shaped_arange(self.shape_a, xp, dtype_a)
566575
b = testing.shaped_arange(self.shape_b, xp, dtype_b)
567576
c = testing.shaped_arange(self.shape_c, xp, dtype_c)

dpnp/tests/third_party/cupy/linalg_tests/test_product.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,21 @@
4040
)
4141
class TestDot(unittest.TestCase):
4242

43+
# Avoid overflow
44+
skip_dtypes = {
45+
(numpy.int8, numpy.int8),
46+
(numpy.int8, numpy.uint8),
47+
(numpy.uint8, numpy.uint8),
48+
}
49+
4350
@testing.for_all_dtypes_combination(["dtype_a", "dtype_b"])
4451
@testing.numpy_cupy_allclose(type_check=has_support_aspect64())
4552
def test_dot(self, xp, dtype_a, dtype_b):
53+
if (dtype_a, dtype_b) in self.skip_dtypes or (
54+
dtype_b,
55+
dtype_a,
56+
) in self.skip_dtypes:
57+
pytest.skip("avoid overflow")
4658
shape_a, shape_b = self.shape
4759
if self.trans_a:
4860
a = testing.shaped_arange(shape_a[::-1], xp, dtype_a).T
@@ -241,13 +253,17 @@ def test_dot_vec3(self, xp, dtype):
241253
@testing.for_all_dtypes()
242254
@testing.numpy_cupy_allclose()
243255
def test_transposed_dot(self, xp, dtype):
256+
if dtype in [numpy.int8, numpy.uint8]:
257+
pytest.skip("avoid overflow")
244258
a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2)
245259
b = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(0, 2, 1)
246260
return xp.dot(a, b)
247261

248262
@testing.for_all_dtypes()
249263
@testing.numpy_cupy_allclose()
250264
def test_transposed_dot_with_out(self, xp, dtype):
265+
if dtype in [numpy.int8, numpy.uint8]:
266+
pytest.skip("avoid overflow")
251267
a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2)
252268
b = testing.shaped_arange((4, 2, 3), xp, dtype).transpose(2, 0, 1)
253269
c = xp.ndarray((3, 2, 3, 2), dtype=dtype)
@@ -323,13 +339,17 @@ def test_reversed_inner(self, xp, dtype):
323339
@testing.for_all_dtypes()
324340
@testing.numpy_cupy_allclose()
325341
def test_multidim_inner(self, xp, dtype):
342+
if dtype in [numpy.int8, numpy.uint8]:
343+
pytest.skip("avoid overflow")
326344
a = testing.shaped_arange((2, 3, 4), xp, dtype)
327345
b = testing.shaped_arange((3, 2, 4), xp, dtype)
328346
return xp.inner(a, b)
329347

330348
@testing.for_all_dtypes()
331349
@testing.numpy_cupy_allclose()
332350
def test_transposed_higher_order_inner(self, xp, dtype):
351+
if dtype in [numpy.int8, numpy.uint8]:
352+
pytest.skip("avoid overflow")
333353
a = testing.shaped_arange((2, 4, 3), xp, dtype).transpose(2, 0, 1)
334354
b = testing.shaped_arange((4, 2, 3), xp, dtype).transpose(1, 2, 0)
335355
return xp.inner(a, b)
@@ -358,13 +378,17 @@ def test_multidim_outer(self, xp, dtype):
358378
@testing.for_all_dtypes()
359379
@testing.numpy_cupy_allclose()
360380
def test_tensordot(self, xp, dtype):
381+
if dtype in [numpy.int8, numpy.uint8]:
382+
pytest.skip("avoid overflow")
361383
a = testing.shaped_arange((2, 3, 4), xp, dtype)
362384
b = testing.shaped_arange((3, 4, 5), xp, dtype)
363385
return xp.tensordot(a, b)
364386

365387
@testing.for_all_dtypes()
366388
@testing.numpy_cupy_allclose()
367389
def test_transposed_tensordot(self, xp, dtype):
390+
if dtype in [numpy.int8, numpy.uint8]:
391+
pytest.skip("avoid overflow")
368392
a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2)
369393
b = testing.shaped_arange((4, 3, 2), xp, dtype).transpose(2, 0, 1)
370394
return xp.tensordot(a, b)
@@ -519,12 +543,16 @@ def test_matrix_power_1(self, xp, dtype):
519543
@testing.for_all_dtypes()
520544
@testing.numpy_cupy_allclose()
521545
def test_matrix_power_2(self, xp, dtype):
546+
if dtype in [numpy.int8, numpy.uint8]:
547+
pytest.skip("avoid overflow")
522548
a = testing.shaped_arange((3, 3), xp, dtype)
523549
return xp.linalg.matrix_power(a, 2)
524550

525551
@testing.for_all_dtypes()
526552
@testing.numpy_cupy_allclose()
527553
def test_matrix_power_3(self, xp, dtype):
554+
if dtype in [numpy.int8, numpy.uint8]:
555+
pytest.skip("avoid overflow")
528556
a = testing.shaped_arange((3, 3), xp, dtype)
529557
return xp.linalg.matrix_power(a, 3)
530558

dpnp/tests/third_party/cupy/logic_tests/test_comparison.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ class TestIsclose(unittest.TestCase):
245245
@testing.for_all_dtypes(no_complex=True)
246246
@testing.numpy_cupy_array_equal()
247247
def test_is_close_finite(self, xp, dtype):
248+
if dtype in [xp.int8, xp.uint8]:
249+
pytest.skip("avoid overflow")
248250
# In numpy<1.10 this test fails when dtype is bool
249251
a = xp.array([0.9e-5, 1.1e-5, 1000 + 1e-4, 1000 - 1e-4]).astype(dtype)
250252
b = xp.array([0, 0, 1000, 1000]).astype(dtype)

dpnp/tests/third_party/cupy/math_tests/test_matmul.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,24 @@
6060
)
6161
class TestMatmul(unittest.TestCase):
6262

63+
# Avoid overflow
64+
skip_dtypes = {
65+
(numpy.int8, numpy.int8),
66+
(numpy.int8, numpy.uint8),
67+
(numpy.uint8, numpy.uint8),
68+
}
69+
6370
@testing.for_all_dtypes(name="dtype1")
6471
@testing.for_all_dtypes(name="dtype2")
6572
@testing.numpy_cupy_allclose(
6673
rtol=1e-3, atol=1e-3, type_check=has_support_aspect64()
6774
) # required for uint8
6875
def test_operator_matmul(self, xp, dtype1, dtype2):
76+
if (dtype1, dtype2) in self.skip_dtypes or (
77+
dtype2,
78+
dtype1,
79+
) in self.skip_dtypes:
80+
pytest.skip("avoid overflow")
6981
x1 = testing.shaped_arange(self.shape_pair[0], xp, dtype1)
7082
x2 = testing.shaped_arange(self.shape_pair[1], xp, dtype2)
7183
return operator.matmul(x1, x2)
@@ -76,6 +88,11 @@ def test_operator_matmul(self, xp, dtype1, dtype2):
7688
rtol=1e-3, atol=1e-3, type_check=has_support_aspect64()
7789
) # required for uint8
7890
def test_cupy_matmul(self, xp, dtype1, dtype2):
91+
if (dtype1, dtype2) in self.skip_dtypes or (
92+
dtype2,
93+
dtype1,
94+
) in self.skip_dtypes:
95+
pytest.skip("avoid overflow")
7996
x1 = testing.shaped_arange(self.shape_pair[0], xp, dtype1)
8097
x2 = testing.shaped_arange(self.shape_pair[1], xp, dtype2)
8198
return xp.matmul(x1, x2)
@@ -97,12 +114,25 @@ def test_cupy_matmul(self, xp, dtype1, dtype2):
97114
)
98115
class TestMatmulOut(unittest.TestCase):
99116

117+
# Avoid overflow
118+
skip_dtypes = {
119+
(numpy.int8, numpy.int8),
120+
(numpy.int8, numpy.uint8),
121+
(numpy.uint8, numpy.uint8),
122+
}
123+
100124
@testing.for_all_dtypes(name="dtype1")
101125
@testing.for_all_dtypes(name="dtype2")
102126
@testing.numpy_cupy_allclose(
103127
rtol=1e-3, atol=1e-3, accept_error=TypeError # required for uint8
104128
)
105129
def test_cupy_matmul_noncontiguous(self, xp, dtype1, dtype2):
130+
if (dtype1, dtype2) in self.skip_dtypes or (
131+
dtype2,
132+
dtype1,
133+
) in self.skip_dtypes:
134+
pytest.skip("avoid overflow")
135+
106136
x1 = testing.shaped_arange(self.shape_pair[0], xp, dtype1)
107137
x2 = testing.shaped_arange(self.shape_pair[1], xp, dtype2)
108138
out = xp.zeros(self.shape_pair[2], dtype=dtype1)[::-1]
@@ -143,6 +173,8 @@ class TestMatmulStrides:
143173
@testing.for_all_dtypes()
144174
@testing.numpy_cupy_allclose(rtol=1e-3, atol=1e-3) # required for uint8
145175
def test_relaxed_c_contiguous_input(self, xp, dtype):
176+
if dtype in [numpy.int8, numpy.uint8]:
177+
pytest.skip("avoid overflow")
146178
x1 = testing.shaped_arange((2, 2, 3), xp, dtype)[:, None, :, :]
147179
x2 = testing.shaped_arange((2, 1, 3, 1), xp, dtype)
148180
return x1 @ x2
@@ -171,6 +203,7 @@ class TestMatmulLarge(unittest.TestCase):
171203

172204
# Avoid overflow
173205
skip_dtypes = {
206+
(numpy.int8, numpy.int8),
174207
(numpy.int8, numpy.uint8),
175208
(numpy.int8, numpy.int16),
176209
(numpy.int8, numpy.float16),

0 commit comments

Comments
 (0)