Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion array_api_tests/test_operators_and_elementwise_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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}"
)
Expand Down