Skip to content

Commit c2a976b

Browse files
committed
new-helper-func
1 parent f74b5a8 commit c2a976b

File tree

9 files changed

+80
-143
lines changed

9 files changed

+80
-143
lines changed

dpnp/tests/helper.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ def get_all_dtypes(
198198
no_float16=True,
199199
no_complex=False,
200200
no_none=False,
201-
xfail_dtypes=None,
202-
exclude=None,
203201
no_unsigned=False,
204202
device=None,
205203
):
@@ -227,17 +225,6 @@ def get_all_dtypes(
227225
if not no_none:
228226
dtypes.append(None)
229227

230-
def mark_xfail(dtype):
231-
if xfail_dtypes is not None and dtype in xfail_dtypes:
232-
return pytest.param(dtype, marks=pytest.mark.xfail)
233-
return dtype
234-
235-
def not_excluded(dtype):
236-
if exclude is None:
237-
return True
238-
return dtype not in exclude
239-
240-
dtypes = [mark_xfail(dtype) for dtype in dtypes if not_excluded(dtype)]
241228
return dtypes
242229

243230

@@ -312,6 +299,36 @@ def get_integer_dtypes(all_int_types=False, no_unsigned=False):
312299
return dtypes
313300

314301

302+
def get_integer_float_dtypes(
303+
all_int_types=False,
304+
no_unsigned=False,
305+
no_float16=True,
306+
device=None,
307+
xfail_dtypes=None,
308+
exclude=None,
309+
):
310+
"""
311+
Build a list of integer and float types supported by DPNP.
312+
"""
313+
dtypes = get_integer_dtypes(
314+
all_int_types=all_int_types, no_unsigned=no_unsigned
315+
)
316+
dtypes += get_float_dtypes(no_float16=no_float16, device=device)
317+
318+
def mark_xfail(dtype):
319+
if xfail_dtypes is not None and dtype in xfail_dtypes:
320+
return pytest.param(dtype, marks=pytest.mark.xfail)
321+
return dtype
322+
323+
def not_excluded(dtype):
324+
if exclude is None:
325+
return True
326+
return dtype not in exclude
327+
328+
dtypes = [mark_xfail(dtype) for dtype in dtypes if not_excluded(dtype)]
329+
return dtypes
330+
331+
315332
def has_support_aspect16(device=None):
316333
"""
317334
Return True if the device supports 16-bit precision floating point operations,

dpnp/tests/test_binary_ufuncs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
get_float_complex_dtypes,
2121
get_float_dtypes,
2222
get_integer_dtypes,
23+
get_integer_float_dtypes,
2324
has_support_aspect16,
2425
numpy_version,
2526
)
@@ -141,7 +142,7 @@ def test_invalid_out(self, xp, out):
141142
@pytest.mark.parametrize("func", ["fmax", "fmin", "maximum", "minimum"])
142143
class TestBoundFuncs:
143144
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
144-
def test_out(self, func, dtype):
145+
def test_basic(self, func, dtype):
145146
a = generate_random_numpy_array(10, dtype)
146147
b = generate_random_numpy_array(10, dtype)
147148
expected = getattr(numpy, func)(a, b)
@@ -278,7 +279,7 @@ def test_invalid_out(self, xp, out):
278279

279280
@pytest.mark.parametrize("func", ["floor_divide", "remainder"])
280281
class TestFloorDivideRemainder:
281-
ALL_DTYPES = get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
282+
ALL_DTYPES = get_integer_float_dtypes()
282283

283284
def do_inplace_op(self, base, other, func):
284285
if func == "floor_divide":

dpnp/tests/test_histogram.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525

2626

2727
class TestDigitize:
28-
@pytest.mark.parametrize(
29-
"dtype", get_all_dtypes(no_bool=True, no_complex=True)
30-
)
28+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
3129
@pytest.mark.parametrize("right", [True, False])
3230
@pytest.mark.parametrize(
3331
"x, bins",
@@ -73,12 +71,8 @@ def test_digitize_inf(self, dtype, right):
7371
expected = numpy.digitize(x, bins, right=right)
7472
assert_dtype_allclose(result, expected)
7573

76-
@pytest.mark.parametrize(
77-
"dtype_x", get_all_dtypes(no_bool=True, no_complex=True)
78-
)
79-
@pytest.mark.parametrize(
80-
"dtype_bins", get_all_dtypes(no_bool=True, no_complex=True)
81-
)
74+
@pytest.mark.parametrize("dtype_x", get_integer_float_dtypes())
75+
@pytest.mark.parametrize("dtype_bins", get_integer_float_dtypes())
8276
@pytest.mark.parametrize("right", [True, False])
8377
def test_digitize_diff_types(self, dtype_x, dtype_bins, right):
8478
x = numpy.array([1, 2, 3, 4, 5], dtype=dtype_x)
@@ -90,9 +84,7 @@ def test_digitize_diff_types(self, dtype_x, dtype_bins, right):
9084
expected = numpy.digitize(x, bins, right=right)
9185
assert_dtype_allclose(result, expected)
9286

93-
@pytest.mark.parametrize(
94-
"dtype", get_all_dtypes(no_bool=True, no_complex=True)
95-
)
87+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
9688
@pytest.mark.parametrize(
9789
"x, bins",
9890
[

dpnp/tests/test_linalg.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,9 +1409,7 @@ def test_einsum_tensor(self):
14091409
result = dpnp.einsum("ijij->", tensor_dp)
14101410
assert_dtype_allclose(result, expected)
14111411

1412-
@pytest.mark.parametrize(
1413-
"dtype", get_all_dtypes(no_bool=True, no_complex=True, no_none=True)
1414-
)
1412+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
14151413
def test_different_paths(self, dtype):
14161414
# Simple test, designed to exercise most specialized code paths,
14171415
# note the +0.5 for floats. This makes sure we use a float value

dpnp/tests/test_logic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def check_raises(func_name, exception, *args, **kwargs):
8383
check_raises(func, TypeError, [0, 1, 2, 3])
8484

8585

86-
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
86+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
8787
def test_allclose(dtype):
8888
a = numpy.random.rand(10)
8989
b = a + numpy.random.rand(10) * 1e-8
@@ -508,7 +508,7 @@ def test_infinity_sign_errors(func):
508508
getattr(dpnp, func)(x, out=out)
509509

510510

511-
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
511+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
512512
@pytest.mark.parametrize(
513513
"rtol", [1e-05, dpnp.array(1e-05), dpnp.full(10, 1e-05)]
514514
)
@@ -549,7 +549,7 @@ def test_array_equiv(a, b):
549549
assert_equal(result, expected)
550550

551551

552-
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
552+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
553553
def test_array_equiv_dtype(dtype):
554554
a = numpy.array([1, 2], dtype=dtype)
555555
b = numpy.array([1, 2], dtype=dtype)
@@ -575,7 +575,7 @@ def test_array_equiv_scalar(a):
575575
assert_equal(result, expected)
576576

577577

578-
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
578+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
579579
@pytest.mark.parametrize("equal_nan", [True, False])
580580
def test_array_equal_dtype(dtype, equal_nan):
581581
a = numpy.array([1, 2], dtype=dtype)

dpnp/tests/test_manipulation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
get_float_complex_dtypes,
2121
get_float_dtypes,
2222
get_integer_dtypes,
23+
get_integer_float_dtypes,
2324
has_support_aspect64,
2425
numpy_version,
2526
)
@@ -325,9 +326,7 @@ class TestCopyTo:
325326
]
326327
testdata += [
327328
([1, -1, 0], dtype)
328-
for dtype in get_all_dtypes(
329-
no_none=True, no_bool=True, no_complex=True, no_unsigned=True
330-
)
329+
for dtype in get_integer_float_dtypes(no_unsigned=True)
331330
]
332331
testdata += [([0.1, 0.0, -0.1], dtype) for dtype in get_float_dtypes()]
333332
testdata += [([1j, -1j, 1 - 2j], dtype) for dtype in get_complex_dtypes()]

dpnp/tests/test_mathematical.py

Lines changed: 19 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
get_float_complex_dtypes,
3030
get_float_dtypes,
3131
get_integer_dtypes,
32+
get_integer_float_dtypes,
3233
has_support_aspect16,
3334
has_support_aspect64,
3435
numpy_version,
@@ -50,9 +51,7 @@ def test_angle_bool(self, deg):
5051
# determined by Type Promotion Rules.
5152
assert_dtype_allclose(result, expected, check_only_type_kind=True)
5253

53-
@pytest.mark.parametrize(
54-
"dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
55-
)
54+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
5655
def test_angle(self, dtype, deg):
5756
ia = dpnp.arange(10, dtype=dtype)
5857
a = ia.asnumpy()
@@ -134,9 +133,7 @@ def test_mode(self):
134133

135134

136135
class TestClip:
137-
@pytest.mark.parametrize(
138-
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
139-
)
136+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
140137
@pytest.mark.parametrize("order", ["C", "F", "A", "K", None])
141138
def test_clip(self, dtype, order):
142139
ia = dpnp.asarray([[1, 2, 8], [1, 6, 4], [9, 5, 1]], dtype=dtype)
@@ -148,9 +145,7 @@ def test_clip(self, dtype, order):
148145
assert expected.flags.c_contiguous == result.flags.c_contiguous
149146
assert expected.flags.f_contiguous == result.flags.f_contiguous
150147

151-
@pytest.mark.parametrize(
152-
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
153-
)
148+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
154149
def test_clip_arrays(self, dtype):
155150
ia = dpnp.asarray([1, 2, 8, 1, 6, 4, 1], dtype=dtype)
156151
a = dpnp.asnumpy(ia)
@@ -162,9 +157,7 @@ def test_clip_arrays(self, dtype):
162157
expected = numpy.clip(a, min_v.asnumpy(), max_v.asnumpy())
163158
assert_allclose(result, expected)
164159

165-
@pytest.mark.parametrize(
166-
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
167-
)
160+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
168161
@pytest.mark.parametrize("in_dp", [dpnp, dpt])
169162
@pytest.mark.parametrize("out_dp", [dpnp, dpt])
170163
def test_clip_out(self, dtype, in_dp, out_dp):
@@ -302,9 +295,7 @@ def test_axis_tuple(self):
302295
a = dpnp.ones((3, 4))
303296
assert_raises(TypeError, dpnp.cumlogsumexp, a, axis=(0, 1))
304297

305-
@pytest.mark.parametrize(
306-
"in_dt", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
307-
)
298+
@pytest.mark.parametrize("in_dt", get_integer_float_dtypes())
308299
@pytest.mark.parametrize("dt", get_all_dtypes(no_bool=True))
309300
def test_dtype(self, in_dt, dt):
310301
a = dpnp.ones(100, dtype=in_dt)
@@ -1119,9 +1110,7 @@ def test_0d(self):
11191110
na = a.asnumpy()
11201111
assert_dtype_allclose(dpnp.i0(a), numpy.i0(na))
11211112

1122-
@pytest.mark.parametrize(
1123-
"dt", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
1124-
)
1113+
@pytest.mark.parametrize("dt", get_integer_float_dtypes())
11251114
def test_1d(self, dt):
11261115
a = numpy.array(
11271116
[0.49842636, 0.6969809, 0.22011976, 0.0155549, 10.0], dtype=dt
@@ -1225,30 +1214,24 @@ def test_add(self, dtype, lhs, rhs):
12251214
def test_arctan2(self, dtype, lhs, rhs):
12261215
self._test_mathematical("arctan2", dtype, lhs, rhs)
12271216

1228-
@pytest.mark.parametrize(
1229-
"dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
1230-
)
1217+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
12311218
def test_copysign(self, dtype, lhs, rhs):
12321219
self._test_mathematical("copysign", dtype, lhs, rhs)
12331220

12341221
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
12351222
def test_divide(self, dtype, lhs, rhs):
12361223
self._test_mathematical("divide", dtype, lhs, rhs)
12371224

1238-
@pytest.mark.parametrize(
1239-
"dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
1240-
)
1225+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
12411226
def test_fmax(self, dtype, lhs, rhs):
12421227
self._test_mathematical("fmax", dtype, lhs, rhs, check_type=False)
12431228

1244-
@pytest.mark.parametrize(
1245-
"dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
1246-
)
1229+
@pytest.mark.parametrize("dtype", get_all_dtypes(no_none=True))
12471230
def test_fmin(self, dtype, lhs, rhs):
12481231
self._test_mathematical("fmin", dtype, lhs, rhs, check_type=False)
12491232

12501233
@pytest.mark.parametrize(
1251-
"dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
1234+
"dtype", get_all_dtypes(no_none=True, no_complex=True)
12521235
)
12531236
def test_fmod(self, dtype, lhs, rhs):
12541237
if rhs == 0.3 and not has_support_aspect64():
@@ -1276,9 +1259,7 @@ def test_floor_divide(self, dtype, lhs, rhs):
12761259
"floor_divide", dtype, lhs, rhs, check_type=False
12771260
)
12781261

1279-
@pytest.mark.parametrize(
1280-
"dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
1281-
)
1262+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
12821263
def test_hypot(self, dtype, lhs, rhs):
12831264
self._test_mathematical("hypot", dtype, lhs, rhs)
12841265

@@ -1838,12 +1819,7 @@ def test_rand(self, dt):
18381819
expected = numpy.unwrap(a)
18391820
assert_dtype_allclose(result, expected)
18401821

1841-
@pytest.mark.parametrize(
1842-
"dt",
1843-
get_all_dtypes(
1844-
no_none=True, no_bool=True, no_complex=True, no_unsigned=True
1845-
),
1846-
)
1822+
@pytest.mark.parametrize("dt", get_integer_float_dtypes(no_unsigned=True))
18471823
def test_period(self, dt):
18481824
a = numpy.array([1, 1 + 108], dtype=dt)
18491825
ia = dpnp.array(a)
@@ -1853,12 +1829,7 @@ def test_period(self, dt):
18531829
expected = numpy.unwrap(a, period=107)
18541830
assert_array_equal(result, expected)
18551831

1856-
@pytest.mark.parametrize(
1857-
"dt",
1858-
get_all_dtypes(
1859-
no_none=True, no_bool=True, no_complex=True, no_unsigned=True
1860-
),
1861-
)
1832+
@pytest.mark.parametrize("dt", get_integer_float_dtypes(no_unsigned=True))
18621833
def test_rand_period(self, dt):
18631834
a = generate_random_numpy_array(10, dt, low=-100, high=100)
18641835
ia = dpnp.array(a)
@@ -2309,9 +2280,7 @@ def test_error(self, func):
23092280

23102281

23112282
class TestHypot:
2312-
@pytest.mark.parametrize(
2313-
"dtype", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
2314-
)
2283+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
23152284
def test_hypot(self, dtype):
23162285
a = generate_random_numpy_array(10, dtype, low=0)
23172286
b = generate_random_numpy_array(10, dtype, low=0)
@@ -2376,9 +2345,7 @@ def test_basic(self, dtype, axis, keepdims):
23762345

23772346
assert_dtype_allclose(res, exp)
23782347

2379-
@pytest.mark.parametrize(
2380-
"in_dt", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
2381-
)
2348+
@pytest.mark.parametrize("in_dt", get_integer_float_dtypes())
23822349
@pytest.mark.parametrize("dt", get_all_dtypes(no_bool=True))
23832350
def test_dtype(self, in_dt, dt):
23842351
a = dpnp.ones(100, dtype=in_dt)
@@ -2436,9 +2403,7 @@ def test_basic(self, dtype, axis, keepdims):
24362403

24372404
assert_dtype_allclose(res, exp)
24382405

2439-
@pytest.mark.parametrize(
2440-
"in_dt", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
2441-
)
2406+
@pytest.mark.parametrize("in_dtype", get_integer_float_dtypes())
24422407
@pytest.mark.parametrize("dt", get_all_dtypes(no_bool=True))
24432408
def test_dtype(self, in_dt, dt):
24442409
a = dpnp.ones(99, dtype=in_dt)
@@ -2467,9 +2432,7 @@ def test_out(self, in_dt, out_dt):
24672432
assert_allclose(result, exp, rtol=1e-06)
24682433

24692434

2470-
@pytest.mark.parametrize(
2471-
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
2472-
)
2435+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
24732436
def test_inplace_remainder(dtype):
24742437
size = 21
24752438
a = numpy.arange(size, dtype=dtype)
@@ -2481,9 +2444,7 @@ def test_inplace_remainder(dtype):
24812444
assert_allclose(ia, a)
24822445

24832446

2484-
@pytest.mark.parametrize(
2485-
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
2486-
)
2447+
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
24872448
def test_inplace_floor_divide(dtype):
24882449
size = 21
24892450
a = numpy.arange(size, dtype=dtype)

0 commit comments

Comments
 (0)