Skip to content

Commit

Permalink
Remove unused allclose and assert_allclose helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
asmeurer committed Feb 7, 2024
1 parent 6f9db94 commit 5aa9083
Showing 1 changed file with 0 additions and 41 deletions.
41 changes: 0 additions & 41 deletions array_api_tests/array_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
from . import _array_module as xp
from . import dtype_helpers as dh

from ndindex import iter_indices

import math

__all__ = ['all', 'any', 'logical_and', 'logical_or', 'logical_not', 'less',
'less_equal', 'greater', 'subtract', 'negative', 'floor', 'ceil',
'where', 'isfinite', 'equal', 'not_equal', 'zero', 'one', 'NaN',
Expand Down Expand Up @@ -150,43 +146,6 @@ def exactly_equal(x, y):

return equal(x, y)

def allclose(x, y, rel_tol=0.25, abs_tol=1, return_indices=False):
"""
Return True all elements of x and y are within tolerance
If return_indices=True, returns (False, (i, j)) when the arrays are not
close, where i and j are the indices into x and y of corresponding
non-close elements.
"""
for i, j in iter_indices(x.shape, y.shape):
i, j = i.raw, j.raw
a = x[i]
b = y[j]
if not (math.isfinite(a) and math.isfinite(b)):
# TODO: If a and b are both infinite, require the same type of infinity
continue
close = math.isclose(a, b, rel_tol=rel_tol, abs_tol=abs_tol)
if not close:
if return_indices:
return (False, (i, j))
return False
return True

def assert_allclose(x, y, rel_tol=1, abs_tol=0.):
"""
Test that x and y are approximately equal to each other.
Also asserts that x and y have the same shape and dtype.
"""
assert x.shape == y.shape, f"The input arrays do not have the same shapes ({x.shape} != {y.shape})"

assert x.dtype == y.dtype, f"The input arrays do not have the same dtype ({x.dtype} != {y.dtype})"

c = allclose(x, y, rel_tol=rel_tol, abs_tol=abs_tol, return_indices=True)
if c is not True:
_, (i, j) = c
raise AssertionError(f"The input arrays are not close with {rel_tol = } and {abs_tol = } at indices {i = } and {j = }")

def notequal(x, y):
"""
Same as not_equal(x, y) except it gives False when both values are nan.
Expand Down

0 comments on commit 5aa9083

Please sign in to comment.