Skip to content

Commit 6596e98

Browse files
committed
Remove allclose
1 parent 6266067 commit 6596e98

File tree

5 files changed

+4
-70
lines changed

5 files changed

+4
-70
lines changed

docs/api-reference.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
:nosignatures:
77
:toctree: generated
88
9-
allclose
109
at
1110
atleast_nd
1211
cov

src/array_api_extra/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Extra array functions built on top of the array API standard."""
22

3-
from ._delegation import allclose, isclose, pad
3+
from ._delegation import isclose, pad
44
from ._lib._at import at
55
from ._lib._funcs import (
66
atleast_nd,
@@ -18,7 +18,6 @@
1818
# pylint: disable=duplicate-code
1919
__all__ = [
2020
"__version__",
21-
"allclose",
2221
"at",
2322
"atleast_nd",
2423
"cov",

src/array_api_extra/_delegation.py

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ._lib._utils._compat import array_namespace
99
from ._lib._utils._typing import Array
1010

11-
__all__ = ["allclose", "isclose", "pad"]
11+
__all__ = ["isclose", "pad"]
1212

1313

1414
def _delegate(xp: ModuleType, *backends: Backend) -> bool:
@@ -30,54 +30,6 @@ def _delegate(xp: ModuleType, *backends: Backend) -> bool:
3030
return any(backend.is_namespace(xp) for backend in backends)
3131

3232

33-
def allclose(
34-
a: Array,
35-
b: Array,
36-
*,
37-
rtol: float = 1e-05,
38-
atol: float = 1e-08,
39-
equal_nan: bool = False,
40-
xp: ModuleType | None = None,
41-
) -> Array:
42-
"""
43-
Return True if two arrays are element-wise equal within a tolerance.
44-
45-
This is a simple convenience reduction around `isclose`.
46-
47-
Parameters
48-
----------
49-
a, b : Array
50-
Input arrays to compare.
51-
rtol : array_like, optional
52-
The relative tolerance parameter.
53-
atol : array_like, optional
54-
The absolute tolerance parameter.
55-
equal_nan : bool, optional
56-
Whether to compare NaN's as equal. If True, NaN's in `a` will be considered
57-
equal to NaN's in `b` in the output array.
58-
xp : array_namespace, optional
59-
The standard-compatible namespace for `a` and `b`. Default: infer.
60-
61-
Returns
62-
-------
63-
Array
64-
A 0-dimensional boolean array, containing `True` if all `a` is elementwise close
65-
to `b` and `False` otherwise.
66-
67-
See Also
68-
--------
69-
isclose
70-
math.isclose
71-
72-
Notes
73-
-----
74-
If `xp` is a lazy backend (e.g. Dask, JAX), you may not be able to test the result
75-
contents with ``bool(allclose(a, b))`` or ``if allclose(a, b): ...``.
76-
"""
77-
xp = array_namespace(a, b) if xp is None else xp
78-
return xp.all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan, xp=xp))
79-
80-
8133
def isclose(
8234
a: Array,
8335
b: Array,
@@ -125,7 +77,6 @@ def isclose(
12577
12678
See Also
12779
--------
128-
allclose
12980
math.isclose
13081
13182
Notes

src/array_api_extra/_lib/_testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ def xp_assert_close(
121121
See Also
122122
--------
123123
xp_assert_equal
124-
allclose
124+
isclose
125125
numpy.testing.assert_allclose
126126
127127
Notes
128128
-----
129-
The default `atol` and `rtol` differ from `xpx.allclose`.
129+
The default `atol` and `rtol` differ from `xp.all(xpx.allclose(a, b))`.
130130
"""
131131
xp = _check_ns_shape_dtype(actual, desired)
132132

tests/test_funcs.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pytest
77

88
from array_api_extra import (
9-
allclose,
109
at,
1110
atleast_nd,
1211
cov,
@@ -291,7 +290,6 @@ def test_basic(self, a: float, b: float, xp: ModuleType):
291290
b_xp = xp.asarray(b)
292291

293292
xp_assert_equal(isclose(a_xp, b_xp), xp.asarray(np.isclose(a, b)))
294-
xp_assert_equal(allclose(a_xp, b_xp), xp.asarray(np.allclose(a, b)))
295293

296294
with warnings.catch_warnings():
297295
warnings.simplefilter("ignore")
@@ -328,8 +326,6 @@ def test_equal_nan(self, xp: ModuleType):
328326
b = xp.asarray([float("nan"), 1.0, float("nan")])
329327
xp_assert_equal(isclose(a, b), xp.asarray([False, False, False]))
330328
xp_assert_equal(isclose(a, b, equal_nan=True), xp.asarray([True, False, False]))
331-
xp_assert_equal(allclose(a[:1], b[:1]), xp.asarray(False))
332-
xp_assert_equal(allclose(a[:1], b[:1], equal_nan=True), xp.asarray(True))
333329

334330
@pytest.mark.parametrize("dtype", ["float32", "complex64", "int32"])
335331
def test_tolerance(self, dtype: str, xp: ModuleType):
@@ -339,15 +335,10 @@ def test_tolerance(self, dtype: str, xp: ModuleType):
339335
xp_assert_equal(isclose(a, b), xp.asarray([False, False]))
340336
xp_assert_equal(isclose(a, b, atol=1), xp.asarray([True, False]))
341337
xp_assert_equal(isclose(a, b, rtol=0.01), xp.asarray([True, False]))
342-
xp_assert_equal(allclose(a[:1], b[:1]), xp.asarray(False))
343-
xp_assert_equal(allclose(a[:1], b[:1], atol=1), xp.asarray(True))
344-
xp_assert_equal(allclose(a[:1], b[:1], rtol=0.01), xp.asarray(True))
345338

346339
# Attempt to trigger division by 0 in rtol on int dtype
347340
xp_assert_equal(isclose(a, b, rtol=0), xp.asarray([False, False]))
348341
xp_assert_equal(isclose(a, b, atol=1, rtol=0), xp.asarray([True, False]))
349-
xp_assert_equal(allclose(a[:1], b[:1], rtol=0), xp.asarray(False))
350-
xp_assert_equal(allclose(a[:1], b[:1], atol=1, rtol=0), xp.asarray(True))
351342

352343
def test_very_small_numbers(self, xp: ModuleType):
353344
a = xp.asarray([1e-9, 1e-9])
@@ -367,12 +358,6 @@ def test_bool_dtype(self, xp: ModuleType):
367358
xp_assert_equal(isclose(a, b, rtol=1), xp.asarray([True, True, True]))
368359
xp_assert_equal(isclose(a, b, rtol=2), xp.asarray([True, True, True]))
369360

370-
xp_assert_equal(allclose(a, b), xp.asarray(False))
371-
xp_assert_equal(allclose(a, b, atol=1), xp.asarray(True))
372-
xp_assert_equal(allclose(a, b, atol=2), xp.asarray(True))
373-
xp_assert_equal(allclose(a, b, rtol=1), xp.asarray(True))
374-
xp_assert_equal(allclose(a, b, rtol=2), xp.asarray(True))
375-
376361
# Test broadcasting
377362
xp_assert_equal(
378363
isclose(a, xp.asarray(True), atol=1), xp.asarray([True, True, True])

0 commit comments

Comments
 (0)