diff --git a/array_api_tests/test_operators_and_elementwise_functions.py b/array_api_tests/test_operators_and_elementwise_functions.py index 1c7d324f..0df00e0e 100644 --- a/array_api_tests/test_operators_and_elementwise_functions.py +++ b/array_api_tests/test_operators_and_elementwise_functions.py @@ -26,6 +26,9 @@ pytestmark = pytest.mark.unvectorized +EPS32 = xp.finfo(xp.float32).eps + + def mock_int_dtype(n: int, dtype: DataType) -> int: """Returns equivalent of `n` that mocks `dtype` behaviour.""" nbits = dh.dtype_nbits[dtype] @@ -1093,7 +1096,13 @@ def refimpl(_x, _min, _max): f"x[{x_idx}]={x_val}, min[{min_idx}]={min_val}, max[{max_idx}]={max_val}" ) else: - assert out_val == expected, ( + if out.dtype == xp.float32: + # conversion to builtin float is prone to roundoff errors + close_enough = math.isclose(out_val, expected, rel_tol=EPS32) + else: + close_enough = out_val == expected + + assert close_enough, ( f"out[{o_idx}]={out[o_idx]} but should be {expected} [clip()]\n" f"x[{x_idx}]={x_val}, min[{min_idx}]={min_val}, max[{max_idx}]={max_val}" )