Skip to content

Commit 714230f

Browse files
committed
Improve some var names, appropiately use func_name
1 parent 36b94f8 commit 714230f

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

array_api_tests/test_elementwise_functions.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_abs(func_name, func, strat, data):
175175
)
176176
x = x[mask]
177177
out = func(x)
178-
ph.assert_shape("abs", out.shape, x.shape)
178+
ph.assert_shape(func_name, out.shape, x.shape)
179179
assert ah.all(
180180
ah.logical_not(ah.negative_mathematical_sign(out))
181181
), f"out elements not all positively signed [{func_name}()]\n{out=}"
@@ -376,11 +376,12 @@ def test_bitwise_and(
376376
s_left = int(_left[idx])
377377
s_right = int(_right[idx])
378378
s_res = int(res[idx])
379-
vals_and = s_left & s_right
380-
vals_and = ah.int_to_dtype(
381-
vals_and, dh.dtype_nbits[res.dtype], dh.dtype_signed[res.dtype]
379+
s_and = ah.int_to_dtype(
380+
s_left & s_right,
381+
dh.dtype_nbits[res.dtype],
382+
dh.dtype_signed[res.dtype],
382383
)
383-
assert vals_and == s_res
384+
assert s_and == s_res
384385

385386

386387
@pytest.mark.parametrize(
@@ -410,9 +411,7 @@ def test_bitwise_left_shift(
410411
if not right_is_scalar:
411412
# TODO: generate indices without broadcasting arrays (see test_equal comment)
412413
shape = broadcast_shapes(left.shape, right.shape)
413-
ph.assert_shape(
414-
"bitwise_left_shift", res.shape, shape, repr_name=f"{res_name}.shape"
415-
)
414+
ph.assert_shape(func_name, res.shape, shape, repr_name=f"{res_name}.shape")
416415
_left = xp.broadcast_to(left, shape)
417416
_right = xp.broadcast_to(right, shape)
418417

@@ -421,12 +420,13 @@ def test_bitwise_left_shift(
421420
s_left = int(_left[idx])
422421
s_right = int(_right[idx])
423422
s_res = int(res[idx])
424-
# We avoid shifting very large ints
425-
vals_shift = s_left << s_right if s_right < dh.dtype_nbits[res.dtype] else 0
426-
vals_shift = ah.int_to_dtype(
427-
vals_shift, dh.dtype_nbits[res.dtype], dh.dtype_signed[res.dtype]
423+
s_shift = ah.int_to_dtype(
424+
# We avoid shifting very large ints
425+
s_left << s_right if s_right < dh.dtype_nbits[res.dtype] else 0,
426+
dh.dtype_nbits[res.dtype],
427+
dh.dtype_signed[res.dtype],
428428
)
429-
assert vals_shift == s_res
429+
assert s_shift == s_res
430430

431431

432432
@pytest.mark.parametrize(
@@ -438,7 +438,7 @@ def test_bitwise_invert(func_name, func, strat, data):
438438

439439
out = func(x)
440440

441-
ph.assert_shape("bitwise_invert", out.shape, x.shape)
441+
ph.assert_shape(func_name, out.shape, x.shape)
442442
# Compare against the Python ~ operator.
443443
if out.dtype == xp.bool:
444444
for idx in ah.ndindex(out.shape):
@@ -449,11 +449,10 @@ def test_bitwise_invert(func_name, func, strat, data):
449449
for idx in ah.ndindex(out.shape):
450450
s_x = int(x[idx])
451451
s_out = int(out[idx])
452-
s_x_invert = ~s_x
453-
s_x_invert = ah.int_to_dtype(
454-
s_x_invert, dh.dtype_nbits[out.dtype], dh.dtype_signed[out.dtype]
452+
s_invert = ah.int_to_dtype(
453+
~s_x, dh.dtype_nbits[out.dtype], dh.dtype_signed[out.dtype]
455454
)
456-
assert s_x_invert == s_out
455+
assert s_invert == s_out
457456

458457

459458
@pytest.mark.parametrize(
@@ -479,7 +478,7 @@ def test_bitwise_or(
479478
if not right_is_scalar:
480479
# TODO: generate indices without broadcasting arrays (see test_equal comment)
481480
shape = broadcast_shapes(left.shape, right.shape)
482-
ph.assert_shape("bitwise_or", res.shape, shape, repr_name=f"{res_name}.shape")
481+
ph.assert_shape(func_name, res.shape, shape, repr_name=f"{res_name}.shape")
483482
_left = xp.broadcast_to(left, shape)
484483
_right = xp.broadcast_to(right, shape)
485484

@@ -495,11 +494,12 @@ def test_bitwise_or(
495494
s_left = int(_left[idx])
496495
s_right = int(_right[idx])
497496
s_res = int(res[idx])
498-
vals_or = s_left | s_right
499-
vals_or = ah.int_to_dtype(
500-
vals_or, dh.dtype_nbits[res.dtype], dh.dtype_signed[res.dtype]
497+
s_or = ah.int_to_dtype(
498+
s_left | s_right,
499+
dh.dtype_nbits[res.dtype],
500+
dh.dtype_signed[res.dtype],
501501
)
502-
assert vals_or == s_res
502+
assert s_or == s_res
503503

504504

505505
@pytest.mark.parametrize(
@@ -540,11 +540,10 @@ def test_bitwise_right_shift(
540540
s_left = int(_left[idx])
541541
s_right = int(_right[idx])
542542
s_res = int(res[idx])
543-
vals_shift = s_left >> s_right
544-
vals_shift = ah.int_to_dtype(
545-
vals_shift, dh.dtype_nbits[res.dtype], dh.dtype_signed[res.dtype]
543+
s_shift = ah.int_to_dtype(
544+
s_left >> s_right, dh.dtype_nbits[res.dtype], dh.dtype_signed[res.dtype]
546545
)
547-
assert vals_shift == s_res
546+
assert s_shift == s_res
548547

549548

550549
@pytest.mark.parametrize(
@@ -570,7 +569,7 @@ def test_bitwise_xor(
570569
if not right_is_scalar:
571570
# TODO: generate indices without broadcasting arrays (see test_equal comment)
572571
shape = broadcast_shapes(left.shape, right.shape)
573-
ph.assert_shape("bitwise_xor", res.shape, shape, repr_name=f"{res_name}.shape")
572+
ph.assert_shape(func_name, res.shape, shape, repr_name=f"{res_name}.shape")
574573
_left = xp.broadcast_to(left, shape)
575574
_right = xp.broadcast_to(right, shape)
576575

@@ -586,11 +585,12 @@ def test_bitwise_xor(
586585
s_left = int(_left[idx])
587586
s_right = int(_right[idx])
588587
s_res = int(res[idx])
589-
vals_xor = s_left ^ s_right
590-
vals_xor = ah.int_to_dtype(
591-
vals_xor, dh.dtype_nbits[res.dtype], dh.dtype_signed[res.dtype]
588+
s_xor = ah.int_to_dtype(
589+
s_left ^ s_right,
590+
dh.dtype_nbits[res.dtype],
591+
dh.dtype_signed[res.dtype],
592592
)
593-
assert vals_xor == s_res
593+
assert s_xor == s_res
594594

595595

596596
@given(xps.arrays(dtype=xps.numeric_dtypes(), shape=hh.shapes()))
@@ -1205,7 +1205,7 @@ def test_not_equal(
12051205
# TODO: generate indices without broadcasting arrays (see test_equal comment)
12061206

12071207
shape = broadcast_shapes(left.shape, right.shape)
1208-
ph.assert_shape("not_equal", out.shape, shape)
1208+
ph.assert_shape(func_name, out.shape, shape)
12091209
_left = xp.broadcast_to(left, shape)
12101210
_right = xp.broadcast_to(right, shape)
12111211

0 commit comments

Comments
 (0)