|
10 | 10 | from . import _array_module as xp
|
11 | 11 | from . import dtype_helpers as dh
|
12 | 12 |
|
13 |
| -from ndindex import iter_indices |
14 |
| - |
15 |
| -import math |
16 |
| - |
17 | 13 | __all__ = ['all', 'any', 'logical_and', 'logical_or', 'logical_not', 'less',
|
18 | 14 | 'less_equal', 'greater', 'subtract', 'negative', 'floor', 'ceil',
|
19 | 15 | 'where', 'isfinite', 'equal', 'not_equal', 'zero', 'one', 'NaN',
|
@@ -150,43 +146,6 @@ def exactly_equal(x, y):
|
150 | 146 |
|
151 | 147 | return equal(x, y)
|
152 | 148 |
|
153 |
| -def allclose(x, y, rel_tol=0.25, abs_tol=1, return_indices=False): |
154 |
| - """ |
155 |
| - Return True all elements of x and y are within tolerance |
156 |
| -
|
157 |
| - If return_indices=True, returns (False, (i, j)) when the arrays are not |
158 |
| - close, where i and j are the indices into x and y of corresponding |
159 |
| - non-close elements. |
160 |
| - """ |
161 |
| - for i, j in iter_indices(x.shape, y.shape): |
162 |
| - i, j = i.raw, j.raw |
163 |
| - a = x[i] |
164 |
| - b = y[j] |
165 |
| - if not (math.isfinite(a) and math.isfinite(b)): |
166 |
| - # TODO: If a and b are both infinite, require the same type of infinity |
167 |
| - continue |
168 |
| - close = math.isclose(a, b, rel_tol=rel_tol, abs_tol=abs_tol) |
169 |
| - if not close: |
170 |
| - if return_indices: |
171 |
| - return (False, (i, j)) |
172 |
| - return False |
173 |
| - return True |
174 |
| - |
175 |
| -def assert_allclose(x, y, rel_tol=1, abs_tol=0.): |
176 |
| - """ |
177 |
| - Test that x and y are approximately equal to each other. |
178 |
| -
|
179 |
| - Also asserts that x and y have the same shape and dtype. |
180 |
| - """ |
181 |
| - assert x.shape == y.shape, f"The input arrays do not have the same shapes ({x.shape} != {y.shape})" |
182 |
| - |
183 |
| - assert x.dtype == y.dtype, f"The input arrays do not have the same dtype ({x.dtype} != {y.dtype})" |
184 |
| - |
185 |
| - c = allclose(x, y, rel_tol=rel_tol, abs_tol=abs_tol, return_indices=True) |
186 |
| - if c is not True: |
187 |
| - _, (i, j) = c |
188 |
| - raise AssertionError(f"The input arrays are not close with {rel_tol = } and {abs_tol = } at indices {i = } and {j = }") |
189 |
| - |
190 | 149 | def notequal(x, y):
|
191 | 150 | """
|
192 | 151 | Same as not_equal(x, y) except it gives False when both values are nan.
|
|
0 commit comments