Skip to content

Commit fe8fe11

Browse files
committed
update tests
1 parent 5f1b083 commit fe8fe11

18 files changed

+186
-421
lines changed

dpnp/dpnp_iface_libmath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def erf(in_array1):
8181
x1_desc = dpnp.get_dpnp_descriptor(
8282
in_array1, copy_when_strides=False, copy_when_nondefault_queue=False
8383
)
84-
if x1_desc and dpnp.is_cuda_backend(in_array1):
84+
if x1_desc and not dpnp.is_cuda_backend(in_array1):
8585
return dpnp_erf(x1_desc).get_pyobj()
8686

8787
result = create_output_descriptor_py(

dpnp/random/dpnp_random_state.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ def __init__(self, seed=None, device=None, sycl_queue=None):
8282
device=device, sycl_queue=sycl_queue
8383
)
8484

85-
dpnp.not_implemented_for_cuda_backend(self._sycl_queue)
86-
8785
self._sycl_device = self._sycl_queue.sycl_device
8886

8987
is_cpu = self._sycl_device.is_cpu

tests/skipped_tests_cuda.tbl

Lines changed: 133 additions & 379 deletions
Large diffs are not rendered by default.

tests/test_arithmetic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22

33
import numpy
4+
import pytest
45

56
from tests.helper import has_support_aspect64
67
from tests.third_party.cupy import testing
@@ -9,6 +10,7 @@
910
class TestArithmetic(unittest.TestCase):
1011
@testing.for_float_dtypes()
1112
@testing.numpy_cupy_allclose()
13+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
1214
def test_modf_part1(self, xp, dtype):
1315
a = xp.array([-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5], dtype=dtype)
1416
b, _ = xp.modf(a)
@@ -17,6 +19,7 @@ def test_modf_part1(self, xp, dtype):
1719

1820
@testing.for_float_dtypes()
1921
@testing.numpy_cupy_allclose()
22+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
2023
def test_modf_part2(self, xp, dtype):
2124
a = xp.array([-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5], dtype=dtype)
2225
_, c = xp.modf(a)

tests/test_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ class TestTakeAlongAxis:
718718
],
719719
)
720720
def test_argequivalent(self, func, argfunc, kwargs):
721-
a = dpnp.random.random(size=(3, 4, 5))
721+
a = dpnp.asarray(numpy.random.random(size=(3, 4, 5)))
722722

723723
for axis in list(range(a.ndim)) + [None]:
724724
a_func = func(a, axis=axis, **kwargs)

tests/test_logic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,15 @@ def test_elemwise_comparison(op, x1, x2, dtype):
396396
"sh2", [[12], [4, 8], [1, 8, 6]], ids=["(12,)", "(4, 8)", "(1, 8, 6)"]
397397
)
398398
def test_comparison_no_broadcast_with_shapes(op, sh1, sh2):
399-
x1, x2 = dpnp.random.randn(*sh1), dpnp.random.randn(*sh2)
399+
x1_np = numpy.random.randn(*sh1)
400+
x2_np = numpy.random.randn(*sh2)
401+
x1 = dpnp.asarray(x1_np)
402+
x2 = dpnp.asarray(x2_np)
400403

401404
# x1 OP x2
402405
with pytest.raises(ValueError):
403406
getattr(dpnp, op)(x1, x2)
404-
getattr(numpy, op)(x1.asnumpy(), x2.asnumpy())
407+
getattr(numpy, op)(x1_np, x2_np)
405408

406409

407410
@pytest.mark.parametrize(

tests/test_random.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def check_seed(self, dist_name, params):
4545
assert_allclose(a1, a2, rtol=1e-07, atol=0)
4646

4747

48+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
4849
@pytest.mark.parametrize(
4950
"func",
5051
[dpnp.random.chisquare, dpnp.random.rand, dpnp.random.randn],
@@ -61,6 +62,7 @@ def test_input_size(func):
6162
assert output_shape == res.shape
6263

6364

65+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
6466
@pytest.mark.parametrize(
6567
"func",
6668
[
@@ -82,6 +84,7 @@ def test_input_shape(func):
8284
assert shape == res.shape
8385

8486

87+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
8588
@pytest.mark.parametrize(
8689
"func",
8790
[
@@ -104,6 +107,7 @@ def test_check_output(func):
104107
assert dpnp.all(res < 1)
105108

106109

110+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
107111
@pytest.mark.parametrize(
108112
"func",
109113
[
@@ -130,6 +134,7 @@ def test_seed(func):
130134
assert_allclose(a1, a2, rtol=1e-07, atol=0)
131135

132136

137+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
133138
def test_randn_normal_distribution():
134139
"""
135140
Check the moments of the normal distribution sample obtained
@@ -667,6 +672,7 @@ def test_seed(self):
667672

668673

669674
@pytest.mark.skipif(not has_support_aspect64(), reason="Failed on Iris Xe")
675+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
670676
class TestDistributionsNormal(TestDistribution):
671677
def test_extreme_value(self):
672678
loc = 5
@@ -827,11 +833,13 @@ def test_seed(self):
827833
self.check_seed("rayleigh", {"scale": scale})
828834

829835

836+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
830837
class TestDistributionsStandardCauchy(TestDistribution):
831838
def test_seed(self):
832839
self.check_seed("standard_cauchy", {})
833840

834841

842+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
835843
class TestDistributionsStandardExponential(TestDistribution):
836844
def test_moments(self):
837845
shape = 0.8
@@ -867,6 +875,7 @@ def test_seed(self):
867875
self.check_seed("standard_gamma", {"shape": 0.0})
868876

869877

878+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
870879
class TestDistributionsStandardNormal(TestDistribution):
871880
def test_moments(self):
872881
expected_mean = 0.0
@@ -944,6 +953,7 @@ def test_seed(self):
944953

945954

946955
@pytest.mark.skipif(not has_support_aspect64(), reason="Failed on Iris Xe")
956+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
947957
class TestDistributionsUniform(TestDistribution):
948958
def test_extreme_value(self):
949959
low = 1.0
@@ -1070,6 +1080,7 @@ def test_seed(self):
10701080
self.check_seed("zipf", {"a": a})
10711081

10721082

1083+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
10731084
class TestPermutationsTestShuffle:
10741085
@pytest.mark.parametrize(
10751086
"dtype",

tests/test_sort.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ def test_complex(self, dtype):
366366
assert result.dtype == expected.dtype
367367

368368

369+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
369370
@pytest.mark.parametrize("kth", [0, 1], ids=["0", "1"])
370371
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
371372
@pytest.mark.parametrize(

tests/test_statistics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
)
1919

2020

21+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
2122
@pytest.mark.parametrize(
2223
"dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
2324
)

tests/test_sycl_queue.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ def test_out_2in_1out(func, data1, data2, device):
11901190
assert_sycl_queue_equal(result.sycl_queue, x2.sycl_queue)
11911191

11921192

1193+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
11931194
@pytest.mark.parametrize(
11941195
"device",
11951196
valid_devices,

tests/third_party/cupy/core_tests/test_dlpack.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,18 @@
1111

1212
def _gen_array(dtype, alloc_q=None):
1313
if cupy.issubdtype(dtype, numpy.unsignedinteger):
14-
array = cupy.random.randint(
15-
0, 10, size=(2, 3), sycl_queue=alloc_q
16-
).astype(dtype)
14+
array = numpy.random.randint(0, 10, size=(2, 3))
1715
elif cupy.issubdtype(dtype, cupy.integer):
18-
array = cupy.random.randint(
19-
-10, 10, size=(2, 3), sycl_queue=alloc_q
20-
).astype(dtype)
16+
array = numpy.random.randint(-10, 10, size=(2, 3))
2117
elif cupy.issubdtype(dtype, cupy.floating):
22-
array = cupy.random.rand(2, 3, sycl_queue=alloc_q).astype(dtype)
18+
array = numpy.random.rand(2, 3)
2319
elif cupy.issubdtype(dtype, cupy.complexfloating):
24-
array = cupy.random.random((2, 3), sycl_queue=alloc_q).astype(dtype)
20+
array = numpy.random.random((2, 3))
2521
elif dtype == cupy.bool_:
26-
array = cupy.random.randint(
27-
0, 2, size=(2, 3), sycl_queue=alloc_q
28-
).astype(cupy.bool_)
22+
array = numpy.random.randint(0, 2, size=(2, 3))
2923
else:
3024
assert False, f"unrecognized dtype: {dtype}"
31-
return array
25+
return cupy.asarray(array, sycl_queue=alloc_q).astype(dtype)
3226

3327

3428
class TestDLPackConversion(unittest.TestCase):

tests/third_party/cupy/indexing_tests/test_indexing.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def test_extract_empty_1dim(self, xp):
205205
return xp.extract(b, a)
206206

207207

208+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
208209
class TestChoose(unittest.TestCase):
209210
@testing.for_all_dtypes()
210211
@testing.numpy_cupy_array_equal()
@@ -213,39 +214,34 @@ def test_choose(self, xp, dtype):
213214
c = testing.shaped_arange((3, 4), xp, dtype)
214215
return a.choose(c)
215216

216-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
217217
@testing.for_all_dtypes()
218218
@testing.numpy_cupy_array_equal()
219219
def test_choose_broadcast(self, xp, dtype):
220220
a = xp.array([[1, 0, 1], [0, 1, 0], [1, 0, 1]])
221221
c = xp.array([-10, 10]).astype(dtype)
222222
return a.choose(c)
223223

224-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
225224
@testing.for_all_dtypes()
226225
@testing.numpy_cupy_array_equal()
227226
def test_choose_broadcast2(self, xp, dtype):
228227
a = xp.array([0, 1])
229228
c = testing.shaped_arange((3, 5, 2), xp, dtype)
230229
return a.choose(c)
231230

232-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
233231
@testing.for_all_dtypes()
234232
@testing.numpy_cupy_array_equal()
235233
def test_choose_wrap(self, xp, dtype):
236234
a = xp.array([0, 3, -1, 5])
237235
c = testing.shaped_arange((3, 4), xp, dtype)
238236
return a.choose(c, mode="wrap")
239237

240-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
241238
@testing.for_all_dtypes()
242239
@testing.numpy_cupy_array_equal()
243240
def test_choose_clip(self, xp, dtype):
244241
a = xp.array([0, 3, -1, 5])
245242
c = testing.shaped_arange((3, 4), xp, dtype)
246243
return a.choose(c, mode="clip")
247244

248-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
249245
@testing.with_requires("numpy>=1.19")
250246
def test_unknown_clip(self):
251247
for xp in (numpy, cupy):
@@ -254,14 +250,12 @@ def test_unknown_clip(self):
254250
with pytest.raises(ValueError):
255251
a.choose(c, mode="unknown")
256252

257-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
258253
def test_raise(self):
259254
a = cupy.array([2])
260255
c = cupy.array([[0, 1]])
261256
with self.assertRaises(ValueError):
262257
a.choose(c)
263258

264-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
265259
@testing.for_all_dtypes()
266260
def test_choose_broadcast_fail(self, dtype):
267261
for xp in (numpy, cupy):

tests/third_party/cupy/linalg_tests/test_solve.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ def test_solve(self):
6161

6262
def check_shape(self, a_shape, b_shape, error_types):
6363
for xp, error_type in error_types.items():
64-
a = xp.random.rand(*a_shape)
65-
b = xp.random.rand(*b_shape)
64+
if xp is cupy and cupy.is_cuda_backend():
65+
a = xp.asarray(numpy.random.rand(*a_shape))
66+
b = xp.asarray(numpy.random.rand(*b_shape))
67+
else:
68+
a = xp.random.rand(*a_shape)
69+
b = xp.random.rand(*b_shape)
6670
with pytest.raises(error_type):
6771
xp.linalg.solve(a, b)
6872

@@ -137,7 +141,7 @@ def check_x(self, a_shape, dtype):
137141
testing.assert_array_equal(a_gpu_copy, a_gpu)
138142

139143
def check_shape(self, a_shape):
140-
a = cupy.random.rand(*a_shape)
144+
a = cupy.asarray(numpy.random.rand(*a_shape))
141145
with self.assertRaises(cupy.linalg.LinAlgError):
142146
cupy.linalg.inv(a)
143147

@@ -254,8 +258,8 @@ def check_lstsq_solution(
254258
return results
255259

256260
def check_invalid_shapes(self, a_shape, b_shape):
257-
a = cupy.random.rand(*a_shape)
258-
b = cupy.random.rand(*b_shape)
261+
a = cupy.asarray(numpy.random.rand(*a_shape))
262+
b = cupy.asarray(numpy.random.rand(*b_shape))
259263
with pytest.raises(cupy.linalg.LinAlgError):
260264
cupy.linalg.lstsq(a, b, rcond=None)
261265

@@ -330,12 +334,12 @@ def check_x(self, a_shape, ind, dtype):
330334
testing.assert_array_equal(a_gpu_copy, a_gpu)
331335

332336
def check_shape(self, a_shape, ind):
333-
a = cupy.random.rand(*a_shape)
337+
a = cupy.asarray(numpy.random.rand(*a_shape))
334338
with self.assertRaises(cupy.linalg.LinAlgError):
335339
cupy.linalg.tensorinv(a, ind=ind)
336340

337341
def check_ind(self, a_shape, ind):
338-
a = cupy.random.rand(*a_shape)
342+
a = cupy.asarray(numpy.random.rand(*a_shape))
339343
with self.assertRaises(ValueError):
340344
cupy.linalg.tensorinv(a, ind=ind)
341345

tests/third_party/cupy/math_tests/test_arithmetic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ def test_casting_dtype_unsafe_ignore_warnings(
685685
class TestArithmeticModf:
686686
@testing.for_float_dtypes()
687687
@testing.numpy_cupy_allclose()
688+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
688689
def test_modf(self, xp, dtype):
689690
a = xp.array([-2.5, -1.5, -0.5, 0, 0.5, 1.5, 2.5], dtype=dtype)
690691
b, c = xp.modf(a)

tests/third_party/cupy/random_tests/test_distributions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ def test_rayleigh_for_negative_scale(self, scale_dtype):
599599
)
600600
)
601601
class TestDistributionsStandardCauchy(RandomDistributionsTestCase):
602+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
602603
def test_standard_cauchy(self):
603604
self.check_distribution("standard_cauchy", {})
604605

@@ -611,6 +612,7 @@ def test_standard_cauchy(self):
611612
)
612613
)
613614
class TestDistributionsStandardExponential(RandomDistributionsTestCase):
615+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
614616
def test_standard_exponential(self):
615617
self.check_distribution("standard_exponential", {})
616618

@@ -639,6 +641,7 @@ def test_standard_gamma(self, shape_dtype):
639641
)
640642
)
641643
class TestDistributionsStandardNormal(RandomDistributionsTestCase):
644+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
642645
def test_standard_normal(self):
643646
self.check_distribution("standard_normal", {})
644647

tests/third_party/cupy/random_tests/test_sample.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from tests.third_party.cupy.testing import _condition, _hypothesis
1111

1212

13+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
1314
class TestRandint(unittest.TestCase):
1415
def test_lo_hi_reversed(self):
1516
with self.assertRaises(ValueError):
@@ -52,7 +53,7 @@ def test_bound_1(self):
5253
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
5354
@_condition.repeat(3, 10)
5455
def test_bound_2(self):
55-
vals = [random.randint(0, 2) for _ in range(20)]
56+
vals = [random.randint(0, 2, ()) for _ in range(20)]
5657
for val in vals:
5758
self.assertEqual(val.shape, ())
5859
self.assertEqual(min(_.min() for _ in vals), 0)
@@ -106,6 +107,7 @@ def test_goodness_of_fit_2(self):
106107
self.assertTrue(_hypothesis.chi_square_test(counts, expected))
107108

108109

110+
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
109111
class TestRandintDtype(unittest.TestCase):
110112
# numpy.int8, numpy.uint8, numpy.int16, numpy.uint16, numpy.int32])
111113
@testing.for_dtypes([numpy.int32])
@@ -131,11 +133,11 @@ def test_dtype2(self, dtype):
131133
self.assertLessEqual(max(x), iinfo.max)
132134

133135
# Lower bound check
134-
with self.assertRaises(OverflowError):
136+
with self.assertRaises((OverflowError, ValueError)):
135137
random.randint(iinfo.min - 1, iinfo.min + 10, size, dtype)
136138

137139
# Upper bound check
138-
with self.assertRaises(OverflowError):
140+
with self.assertRaises((OverflowError, ValueError)):
139141
random.randint(iinfo.max - 10, iinfo.max + 2, size, dtype)
140142

141143

0 commit comments

Comments
 (0)