Skip to content

Commit 6e9d830

Browse files
authored
Update third party tests to pass without fp64 aspect (#2284)
Some of third party tests are intended to run towards the latest NumPy, but previously it was run only in public CI on OpenCL CPU device. With the new `stable` workflow available in the internal CI, such scenario is also covered for L0 GPU device. Thus the tests has to consider dtype check of result based on fp64 aspect of the device (some of GPU does not provide it). The PR proposes to update the affected tests and to modify dtype check based on device capabilities where the result is allocating.
1 parent 0e479cc commit 6e9d830

File tree

5 files changed

+52
-21
lines changed

5 files changed

+52
-21
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33

44
import dpnp as cp
5+
from dpnp.tests.helper import has_support_aspect64
56
from dpnp.tests.third_party.cupy import testing
67

78
# TODO: remove once all dtype aliases added
@@ -15,8 +16,6 @@
1516
"uint8(1) + 2",
1617
"array([1], uint8) + int64(1)",
1718
"array([1], uint8) + array(1, int64)",
18-
"array([1.], float32) + float64(1.)",
19-
"array([1.], float32) + array(1., float64)",
2019
"array([1], uint8) + 1",
2120
"array([1], uint8) + 200",
2221
"array([100], uint8) + 200",
@@ -25,7 +24,6 @@
2524
"uint8(100) + 200",
2625
"float32(1) + 3e100",
2726
"array([1.0], float32) + 1e-14 == 1.0",
28-
"array([0.1], float32) == float64(0.1)",
2927
"array(1.0, float32) + 1e-14 == 1.0",
3028
"array([1.], float32) + 3",
3129
"array([1.], float32) + int64(3)",
@@ -42,25 +40,34 @@
4240
"1.0 + array([1, 2, 3], int8)",
4341
"array([1], float32) + 1j",
4442
]
43+
if has_support_aspect64():
44+
examples += [
45+
"array([1.], float32) + float64(1.)",
46+
"array([1.], float32) + array(1., float64)",
47+
"array([0.1], float32) == float64(0.1)",
48+
]
4549

4650

4751
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
4852
@testing.with_requires("numpy>=2.0")
4953
@pytest.mark.parametrize("example", examples)
50-
@testing.numpy_cupy_allclose(atol=1e-15, accept_error=OverflowError)
54+
@testing.numpy_cupy_allclose(
55+
atol=1e-15, accept_error=OverflowError, type_check=has_support_aspect64()
56+
)
5157
def test_nep50_examples(xp, example):
5258
dct = {
5359
"array": xp.array,
5460
"uint8": xp.uint8,
5561
"int64": xp.int64,
5662
"float32": xp.float32,
57-
"float64": xp.float64,
5863
"int16": xp.int16,
5964
"bool_": xp.bool_,
6065
"int32": xp.int32,
6166
"complex64": xp.complex64,
6267
"int8": xp.int8,
6368
}
69+
if has_support_aspect64():
70+
dct["float64"] = xp.float64
6471

6572
if isinstance(example, tuple):
6673
example, mesg = example

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class TestLinalgCrossProduct(unittest.TestCase):
172172

173173
@testing.with_requires("numpy>=2.0")
174174
@testing.for_all_dtypes_combination(["dtype_a", "dtype_b"])
175-
@testing.numpy_cupy_allclose()
175+
@testing.numpy_cupy_allclose(type_check=has_support_aspect64())
176176
def test_cross(self, xp, dtype_a, dtype_b):
177177
if dtype_a == dtype_b == numpy.bool_:
178178
# cross does not support bool-bool inputs.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def test_fabs(self, xp, dtype):
198198

199199
@testing.with_requires("numpy>=2.0")
200200
@testing.for_all_dtypes(no_complex=True)
201-
@testing.numpy_cupy_allclose(atol=1e-5)
201+
@testing.numpy_cupy_allclose(atol=1e-5, type_check=has_support_aspect64())
202202
def test_fabs_negative(self, xp, dtype):
203203
if numpy.issubdtype(dtype, numpy.unsignedinteger):
204204
pytest.skip("trying to set negative value to unsigned integer")

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,51 +1162,75 @@ def test_ediff1d_ed2(self, xp, dtype):
11621162
class TestTrapezoid:
11631163

11641164
@testing.for_all_dtypes()
1165-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1165+
@testing.numpy_cupy_allclose(
1166+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1167+
type_check=has_support_aspect64(),
1168+
)
11661169
def test_trapz_1dim(self, xp, dtype):
11671170
a = testing.shaped_arange((5,), xp, dtype)
11681171
return xp.trapezoid(a)
11691172

11701173
@testing.for_all_dtypes()
1171-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1174+
@testing.numpy_cupy_allclose(
1175+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1176+
type_check=has_support_aspect64(),
1177+
)
11721178
def test_trapz_1dim_with_x(self, xp, dtype):
11731179
a = testing.shaped_arange((5,), xp, dtype)
11741180
x = testing.shaped_arange((5,), xp, dtype)
11751181
return xp.trapezoid(a, x=x)
11761182

11771183
@testing.for_all_dtypes()
1178-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1184+
@testing.numpy_cupy_allclose(
1185+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1186+
type_check=has_support_aspect64(),
1187+
)
11791188
def test_trapz_1dim_with_dx(self, xp, dtype):
11801189
a = testing.shaped_arange((5,), xp, dtype)
11811190
return xp.trapezoid(a, dx=0.1)
11821191

11831192
@testing.for_all_dtypes()
1184-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1193+
@testing.numpy_cupy_allclose(
1194+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1195+
type_check=has_support_aspect64(),
1196+
)
11851197
def test_trapz_2dim_without_axis(self, xp, dtype):
11861198
a = testing.shaped_arange((4, 5), xp, dtype)
11871199
return xp.trapezoid(a)
11881200

11891201
@testing.for_all_dtypes()
1190-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1202+
@testing.numpy_cupy_allclose(
1203+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1204+
type_check=has_support_aspect64(),
1205+
)
11911206
def test_trapz_2dim_with_axis(self, xp, dtype):
11921207
a = testing.shaped_arange((4, 5), xp, dtype)
11931208
return xp.trapezoid(a, axis=-2)
11941209

11951210
@testing.for_all_dtypes()
1196-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1211+
@testing.numpy_cupy_allclose(
1212+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1213+
type_check=has_support_aspect64(),
1214+
)
11971215
def test_trapz_2dim_with_x_and_axis(self, xp, dtype):
11981216
a = testing.shaped_arange((4, 5), xp, dtype)
11991217
x = testing.shaped_arange((5,), xp, dtype)
12001218
return xp.trapezoid(a, x=x, axis=1)
12011219

12021220
@testing.for_all_dtypes()
1203-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1221+
@testing.numpy_cupy_allclose(
1222+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1223+
type_check=has_support_aspect64(),
1224+
)
12041225
def test_trapz_2dim_with_dx_and_axis(self, xp, dtype):
12051226
a = testing.shaped_arange((4, 5), xp, dtype)
12061227
return xp.trapezoid(a, dx=0.1, axis=1)
12071228

12081229
@testing.for_all_dtypes()
1209-
@testing.numpy_cupy_allclose(rtol={numpy.float16: 1e-1, "default": 1e-7})
1230+
@testing.numpy_cupy_allclose(
1231+
rtol={numpy.float16: 1e-1, "default": 1e-7},
1232+
type_check=has_support_aspect64(),
1233+
)
12101234
def test_trapz_1dim_with_x_and_dx(self, xp, dtype):
12111235
a = testing.shaped_arange((5,), xp, dtype)
12121236
x = testing.shaped_arange((5,), xp, dtype)

dpnp/tests/third_party/cupy/testing/_loops.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,12 @@ def numpy_cupy_allclose(
583583
# When `type_check` is `False`, cupy result and numpy result may have
584584
# different dtypes so we can not determine the dtype to use from the
585585
# tolerance associations.
586-
if not type_check:
587-
if isinstance(rtol, dict) or isinstance(atol, dict):
588-
raise TypeError(
589-
"When `type_check` is `False`, `rtol` and `atol` "
590-
"must be supplied as float."
591-
)
586+
# if not type_check:
587+
# if isinstance(rtol, dict) or isinstance(atol, dict):
588+
# raise TypeError(
589+
# "When `type_check` is `False`, `rtol` and `atol` "
590+
# "must be supplied as float."
591+
# )
592592

593593
def check_func(c, n):
594594
rtol1, atol1 = _resolve_tolerance(type_check, c, rtol, atol)

0 commit comments

Comments
 (0)