Skip to content

Commit babbb9c

Browse files
committed
Don't test the abs of the smallest negative integer for a given dtype
1 parent 4dae97d commit babbb9c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

array_api_tests/test_elementwise_functions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
array_any, int_to_dtype, bool as bool_dtype,
3434
assert_integral, less_equal, isintegral, isfinite,
3535
ndindex, promote_dtypes, is_integer_dtype,
36-
is_float_dtype, not_equal, float64, asarray)
36+
is_float_dtype, not_equal, float64, asarray,
37+
dtype_ranges, full)
3738
# We might as well use this implementation rather than requiring
3839
# mod.broadcast_shapes(). See test_equal() and others.
3940
from .test_broadcasting import broadcast_shapes
@@ -67,6 +68,12 @@ def sanity_check(x1, x2):
6768

6869
@given(numeric_scalars)
6970
def test_abs(x):
71+
if is_integer_dtype(x.dtype):
72+
minval = dtype_ranges[x.dtype][0]
73+
if minval < 0:
74+
# abs of the smallest representable negative integer is not defined
75+
mask = not_equal(x, full(x.shape, minval, dtype=x.dtype))
76+
x = x[mask]
7077
a = _array_module.abs(x)
7178
assert array_all(logical_not(negative_mathematical_sign(a))), "abs(x) did not have positive sign"
7279
less_zero = negative_mathematical_sign(x)

0 commit comments

Comments
 (0)