Skip to content

Commit 93535bd

Browse files
authored
Update third party tests with the latest changes (#2312)
The PR proposes to align third party tests with the latest content.
1 parent 426da51 commit 93535bd

File tree

11 files changed

+97
-104
lines changed

11 files changed

+97
-104
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _get_cuda_archs(self):
6464

6565
def _get_options(self):
6666
return (
67-
"-std=c++14",
67+
"-std=c++17",
6868
*cupy._core.core._get_cccl_include_options(),
6969
"-I{}".format(cupy._core.core._get_header_dir_path()),
7070
"-I{}".format(os.path.join(cupy.cuda.get_cuda_path(), "include")),

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

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -397,24 +397,8 @@ def find_nvcc_ver():
397397
return int(major) * 1000 + int(minor) * 10
398398

399399

400-
@testing.parameterize(
401-
# First test NVRTC
402-
{"backend": "nvrtc", "in_memory": False},
403-
# this run will read from in-memory cache
404-
{"backend": "nvrtc", "in_memory": True},
405-
# this run will force recompilation
406-
{"backend": "nvrtc", "in_memory": True, "clean_up": True},
407-
# Below is the same set of NVRTC tests, with Jitify turned on. For tests
408-
# that can already pass, it shouldn't matter whether Jitify is on or not,
409-
# and the only side effect is to add overhead. It doesn't make sense to
410-
# test NVCC + Jitify.
411-
{"backend": "nvrtc", "in_memory": False, "jitify": True},
412-
{"backend": "nvrtc", "in_memory": True, "jitify": True},
413-
{"backend": "nvrtc", "in_memory": True, "clean_up": True, "jitify": True},
414-
# Finally, we test NVCC
415-
{"backend": "nvcc", "in_memory": False},
416-
)
417-
class TestRaw(unittest.TestCase):
400+
# TODO(leofang): Further refactor the test suite to avoid using unittest?
401+
class _TestRawBase:
418402

419403
_nvcc_ver = None
420404
_nvrtc_ver = None
@@ -1176,6 +1160,37 @@ def test_compile_module(self):
11761160
assert cupy.allclose(y, x1 + x2)
11771161

11781162

1163+
@testing.parameterize(
1164+
# First test NVRTC
1165+
{"backend": "nvrtc", "in_memory": False},
1166+
# this run will read from in-memory cache
1167+
{"backend": "nvrtc", "in_memory": True},
1168+
# this run will force recompilation
1169+
{"backend": "nvrtc", "in_memory": True, "clean_up": True},
1170+
# Finally, we test NVCC
1171+
{"backend": "nvcc", "in_memory": False},
1172+
)
1173+
class TestRaw(_TestRawBase, unittest.TestCase):
1174+
pass
1175+
1176+
1177+
# Recent CCCL has made Jitify cold-launch very slow, see the discussion
1178+
# starting https://github.com/cupy/cupy/pull/8899#issuecomment-2613022424.
1179+
# TODO(leofang): Further refactor the test suite?
1180+
@testing.parameterize(
1181+
# Below is the same set of NVRTC tests, with Jitify turned on. For tests
1182+
# that can already pass, it shouldn't matter whether Jitify is on or not,
1183+
# and the only side effect is to add overhead. It doesn't make sense to
1184+
# test NVCC + Jitify.
1185+
{"backend": "nvrtc", "in_memory": False, "jitify": True},
1186+
{"backend": "nvrtc", "in_memory": True, "jitify": True},
1187+
{"backend": "nvrtc", "in_memory": True, "clean_up": True, "jitify": True},
1188+
)
1189+
@testing.slow
1190+
class TestRawWithJitify(_TestRawBase, unittest.TestCase):
1191+
pass
1192+
1193+
11791194
_test_grid_sync = r"""
11801195
#include <cooperative_groups.h>
11811196
@@ -1374,6 +1389,9 @@ def test_raw_picklable(self):
13741389
"""
13751390

13761391

1392+
# Recent CCCL has made Jitify cold-launch very slow, see the discussion
1393+
# starting https://github.com/cupy/cupy/pull/8899#issuecomment-2613022424.
1394+
# TODO(leofang): Further refactor the test suite?
13771395
@testing.parameterize(
13781396
*testing.product(
13791397
{
@@ -1382,6 +1400,7 @@ def test_raw_picklable(self):
13821400
)
13831401
)
13841402
@unittest.skipIf(cupy.cuda.runtime.is_hip, "Jitify does not support ROCm/HIP")
1403+
@testing.slow
13851404
class TestRawJitify(unittest.TestCase):
13861405

13871406
def setUp(self):

dpnp/tests/third_party/cupy/fft_tests/test_fft.py

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ def test_ifftn_orders(self, dtype, enable_nd):
889889
pass
890890

891891

892-
# @testing.with_requires("numpy>=2.0")
892+
@testing.with_requires("numpy>=2.0")
893893
@pytest.mark.usefixtures("skip_forward_backward")
894894
@testing.parameterize(
895895
*testing.product(
@@ -925,17 +925,6 @@ def test_rfft(self, xp, dtype):
925925
def test_irfft(self, xp, dtype):
926926
a = testing.shaped_random(self.shape, xp, dtype)
927927
out = xp.fft.irfft(a, n=self.n, norm=self.norm)
928-
929-
if dtype == xp.float16 and xp is cupy:
930-
# XXX: np2.0: f16 dtypes differ
931-
out = out.astype(np.float16)
932-
elif (
933-
xp is np
934-
and np.lib.NumpyVersion(np.__version__) < "2.0.0"
935-
and dtype == np.float32
936-
):
937-
out = out.astype(np.float32)
938-
939928
return out
940929

941930

@@ -1008,7 +997,7 @@ def test_rfft_error_on_wrong_plan(self, dtype):
1008997
assert "Target array size does not match the plan." in str(ex.value)
1009998

1010999

1011-
# @testing.with_requires("numpy>=2.0")
1000+
@testing.with_requires("numpy>=2.0")
10121001
@pytest.mark.usefixtures("skip_forward_backward")
10131002
@testing.parameterize(
10141003
*(
@@ -1069,13 +1058,6 @@ def test_irfft2(self, xp, dtype, order, enable_nd):
10691058

10701059
if self.s is None and self.axes in [None, (-2, -1)]:
10711060
pytest.skip("Input is not Hermitian Symmetric")
1072-
elif dtype == xp.float16 and xp is cupy:
1073-
pytest.xfail("XXX: np2.0: f16 dtypes differ")
1074-
elif (
1075-
np.lib.NumpyVersion(np.__version__) < "2.0.0"
1076-
and dtype == np.float32
1077-
):
1078-
pytest.skip("dtypes differ")
10791061

10801062
a = testing.shaped_random(self.shape, xp, dtype)
10811063
if order == "F":
@@ -1105,7 +1087,7 @@ def test_irfft2(self, dtype):
11051087
xp.fft.irfft2(a, s=self.s, axes=self.axes, norm=self.norm)
11061088

11071089

1108-
# @testing.with_requires("numpy>=2.0")
1090+
@testing.with_requires("numpy>=2.0")
11091091
@pytest.mark.usefixtures("skip_forward_backward")
11101092
@testing.parameterize(
11111093
*(
@@ -1166,13 +1148,6 @@ def test_irfftn(self, xp, dtype, order, enable_nd):
11661148

11671149
if self.s is None and self.axes in [None, (-2, -1)]:
11681150
pytest.skip("Input is not Hermitian Symmetric")
1169-
elif dtype == xp.float16 and xp is cupy:
1170-
pytest.xfail("XXX: np2.0: f16 dtypes differ")
1171-
elif (
1172-
np.lib.NumpyVersion(np.__version__) < "2.0.0"
1173-
and dtype == np.float32
1174-
):
1175-
pytest.skip("dtypes differ")
11761151

11771152
a = testing.shaped_random(self.shape, xp, dtype)
11781153
if order == "F":
@@ -1243,10 +1218,6 @@ def test_rfftn(self, xp, dtype, enable_nd):
12431218
def test_irfftn(self, xp, dtype, enable_nd):
12441219
assert config.enable_nd_planning == enable_nd
12451220
a = testing.shaped_random(self.shape, xp, dtype)
1246-
1247-
if dtype == xp.float16 and xp is cupy:
1248-
pytest.xfail("XXX: np2.0: f16 dtypes differ")
1249-
12501221
if xp is np:
12511222
return xp.fft.irfftn(a, s=self.s, axes=self.axes, norm=self.norm)
12521223

@@ -1349,7 +1320,7 @@ def test_irfftn(self, dtype):
13491320
xp.fft.irfftn(a, s=self.s, axes=self.axes, norm=self.norm)
13501321

13511322

1352-
# @testing.with_requires("numpy>=2.0")
1323+
@testing.with_requires("numpy>=2.0")
13531324
@pytest.mark.usefixtures("skip_forward_backward")
13541325
@testing.parameterize(
13551326
*testing.product(
@@ -1373,17 +1344,6 @@ class TestHfft:
13731344
def test_hfft(self, xp, dtype):
13741345
a = testing.shaped_random(self.shape, xp, dtype)
13751346
out = xp.fft.hfft(a, n=self.n, norm=self.norm)
1376-
1377-
if dtype == xp.float16 and xp is cupy:
1378-
# XXX: np2.0: f16 dtypes differ
1379-
out = out.astype(np.float16)
1380-
elif (
1381-
xp is np
1382-
and np.lib.NumpyVersion(np.__version__) < "2.0.0"
1383-
and dtype == np.float32
1384-
):
1385-
out = out.astype(np.float32)
1386-
13871347
return out
13881348

13891349
@testing.for_all_dtypes(no_complex=True)
@@ -1396,16 +1356,7 @@ def test_hfft(self, xp, dtype):
13961356
)
13971357
def test_ihfft(self, xp, dtype):
13981358
a = testing.shaped_random(self.shape, xp, dtype)
1399-
out = xp.fft.ihfft(a, n=self.n, norm=self.norm)
1400-
1401-
if (
1402-
xp is np
1403-
and np.lib.NumpyVersion(np.__version__) < "2.0.0"
1404-
and dtype == np.float32
1405-
):
1406-
out = out.astype(np.complex64)
1407-
1408-
return out
1359+
return xp.fft.ihfft(a, n=self.n, norm=self.norm)
14091360

14101361

14111362
# @testing.with_requires("numpy>=2.0")

dpnp/tests/third_party/cupy/lib_tests/test_polynomial.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,6 @@ def test_polyval(self, xp, dtype):
757757
a1 = self._get_input(xp, self.type_l, dtype, size=5)
758758
a2 = self._get_input(xp, self.type_r, dtype, size=5)
759759

760-
if self.type_r == "python_scalar":
761-
pytest.skip("XXX: np2.0: numpy always returns f64")
762-
763760
return xp.polyval(a1, a2)
764761

765762

dpnp/tests/third_party/cupy/manipulation_tests/test_add_remove.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,17 @@ def test_trim_back_zeros(self, xp, dtype):
387387
a = xp.array([1, 0, 2, 3, 0, 5, 0, 0, 0], dtype=dtype)
388388
return xp.trim_zeros(a, trim=self.trim)
389389

390-
@pytest.mark.skip("0-d array is supported")
390+
@testing.with_requires("numpy>=2.2.0")
391391
@testing.for_all_dtypes()
392-
def test_trim_zero_dim(self, dtype):
393-
for xp in (numpy, cupy):
394-
a = testing.shaped_arange((), xp, dtype)
395-
with pytest.raises(TypeError):
396-
xp.trim_zeros(a, trim=self.trim)
392+
@testing.numpy_cupy_array_equal()
393+
def test_trim_zero_dim(self, xp, dtype):
394+
a = testing.shaped_arange((), xp, dtype)
395+
return xp.trim_zeros(a, trim=self.trim)
397396

398-
@pytest.mark.skip("nd array is supported")
397+
# @pytest.mark.xfail(reason='XXX: Not implemented')
398+
@testing.with_requires("numpy>=2.2.0")
399399
@testing.for_all_dtypes()
400-
def test_trim_ndim(self, dtype):
401-
for xp in (numpy, cupy):
402-
a = testing.shaped_arange((2, 3), xp, dtype=dtype)
403-
with pytest.raises(ValueError):
404-
xp.trim_zeros(a, trim=self.trim)
400+
@testing.numpy_cupy_array_equal()
401+
def test_trim_ndim(self, xp, dtype):
402+
a = testing.shaped_arange((2, 3), xp, dtype=dtype)
403+
return xp.trim_zeros(a, trim=self.trim)

dpnp/tests/third_party/cupy/manipulation_tests/test_basic.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ def test_copyto_multigpu_noncontinguous(self, dtype):
199199
testing.assert_array_equal(expected, dst.get())
200200

201201

202-
@pytest.mark.skipif(
203-
numpy.__version__ < "2",
204-
reason="XXX: NP2.0: copyto is in flux in numpy 2.0.0rc2",
205-
)
206202
@testing.parameterize(
207203
*testing.product(
208204
{

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import unittest
22

3-
import pytest
4-
53
import dpnp as cupy
64
from dpnp.tests.third_party.cupy import testing
75

@@ -14,16 +12,10 @@ def test_i0(self, xp, dtype):
1412
a = testing.shaped_random((2, 3), xp, dtype)
1513
return xp.i0(a)
1614

15+
@testing.with_requires("numpy>=2.0")
1716
@testing.for_dtypes(["e", "f", "d", "F", "D"])
1817
@testing.numpy_cupy_allclose(atol=1e-3)
1918
def test_sinc(self, xp, dtype):
20-
21-
if dtype in [cupy.float16, cupy.float32, cupy.complex64]:
22-
pytest.xfail(
23-
reason="XXX: np2.0: numpy 1.26 uses a wrong "
24-
"promotion; numpy 2.0 is OK"
25-
)
26-
2719
a = testing.shaped_random((2, 3), xp, dtype, scale=1)
2820
return xp.sinc(a)
2921

dpnp/tests/third_party/cupy/random_tests/test_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ def test_dtype_shape(self):
914914
if isinstance(self.a, numpy.ndarray):
915915
expected_dtype = "float"
916916
else:
917-
expected_dtype = "int"
917+
expected_dtype = "long"
918918
assert v.dtype == expected_dtype
919919
assert v.shape == expected_shape
920920

dpnp/tests/third_party/cupy/sorting_tests/test_search.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,31 @@ def test_where_two_arrays(self, xp, cond_type, x_type, y_type):
328328
return xp.where(cond, x, y)
329329

330330

331+
@testing.with_requires("numpy>=2.0")
332+
@testing.parameterize(
333+
{"scalar_value": 1},
334+
{"scalar_value": 1.0},
335+
{"scalar_value": 1 + 2j},
336+
)
337+
class TestWhereArrayAndScalar:
338+
339+
@testing.for_all_dtypes()
340+
@testing.numpy_cupy_allclose(type_check=has_support_aspect64())
341+
def test_where_array_scalar(self, xp, dtype):
342+
cond = testing.shaped_random((2, 3, 4), xp, xp.bool_)
343+
x = testing.shaped_random((2, 3, 4), xp, dtype, seed=0)
344+
y = self.scalar_value
345+
return xp.where(cond, x, y)
346+
347+
@testing.for_all_dtypes()
348+
@testing.numpy_cupy_allclose(type_check=has_support_aspect64())
349+
def test_where_scalar_array(self, xp, dtype):
350+
cond = testing.shaped_random((2, 3, 4), xp, xp.bool_)
351+
x = self.scalar_value
352+
y = testing.shaped_random((2, 3, 4), xp, dtype, seed=0)
353+
return xp.where(cond, x, y)
354+
355+
331356
@testing.parameterize(
332357
{"cond_shape": (2, 3, 4)},
333358
{"cond_shape": (4,)},

dpnp/tests/third_party/cupy/statistics_tests/test_histogram.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ def test_histogramdd(self, xp, dtype):
497497
weights = xp.ones((x.shape[0],), dtype=self.weights_dtype)
498498
else:
499499
weights = None
500-
501500
y, bin_edges = xp.histogramdd(
502501
x,
503502
bins=bins,
@@ -549,6 +548,13 @@ def test_histogramdd_invalid_range(self):
549548
with pytest.raises(ValueError):
550549
y, bin_edges = xp.histogramdd(x, range=r)
551550

551+
@pytest.mark.skip("list of bins is allowed")
552+
def test_histogramdd_disallow_arraylike_bins(self):
553+
x = testing.shaped_random((16, 2), cupy, scale=100)
554+
bins = [[0, 10, 20, 50, 90]] * 2 # too many dimensions
555+
with pytest.raises(ValueError):
556+
y, bin_edges = cupy.histogramdd(x, bins=bins)
557+
552558

553559
@testing.parameterize(
554560
*testing.product(
@@ -596,9 +602,10 @@ def test_histogram2d(self, xp, dtype):
596602

597603
class TestHistogram2dErrors(unittest.TestCase):
598604

605+
@pytest.mark.skip("list of bins is allowed")
599606
def test_histogram2d_disallow_arraylike_bins(self):
600607
x = testing.shaped_random((16,), cupy, scale=100)
601608
y = testing.shaped_random((16,), cupy, scale=100)
602609
bins = [0, 10, 20, 50, 90]
603610
with pytest.raises(ValueError):
604-
y, bin_edges = cupy.histogram2d(x, y, bins=bins)
611+
y, _, _ = cupy.histogram2d(x, y, bins=bins)

dpnp/tests/third_party/cupy/statistics_tests/test_order.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ def test_quantile_out_of_range_q(self, dtype, method):
252252
with pytest.raises(ValueError):
253253
xp.quantile(a, q, axis=-1, method=method)
254254

255+
@testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True)
256+
@testing.numpy_cupy_allclose(rtol=1e-6)
257+
def test_quantile_axis_and_keepdims(self, xp, dtype, method):
258+
a = testing.shaped_random((1, 6, 3, 2), xp, dtype)
259+
q = testing.shaped_random((5,), xp, scale=1)
260+
return xp.quantile(a, q, axis=0, keepdims=True, method=method)
261+
255262

256263
class TestOrder:
257264

0 commit comments

Comments
 (0)