Skip to content

Commit 88b64af

Browse files
committed
Verbose maximum keyword for isclose()-like helpers
Also whitespace and docstring nitpick for `isclose_complex()`
1 parent 2b8f5f5 commit 88b64af

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

Diff for: array_api_tests/test_operators_and_elementwise_functions.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def mock_int_dtype(n: int, dtype: DataType) -> int:
4949
def isclose(
5050
a: float,
5151
b: float,
52-
M: float,
52+
maximum: float,
5353
*,
5454
rel_tol: float = 0.25,
5555
abs_tol: float = 1,
@@ -62,35 +62,30 @@ def isclose(
6262
if math.isnan(a) or math.isnan(b):
6363
raise ValueError(f"{a=} and {b=}, but input must be non-NaN")
6464
if math.isinf(a):
65-
return math.isinf(b) or abs(b) > math.log(M)
65+
return math.isinf(b) or abs(b) > math.log(maximum)
6666
elif math.isinf(b):
67-
return math.isinf(a) or abs(a) > math.log(M)
67+
return math.isinf(a) or abs(a) > math.log(maximum)
6868
return math.isclose(a, b, rel_tol=rel_tol, abs_tol=abs_tol)
6969

7070

7171
def isclose_complex(
7272
a: complex,
7373
b: complex,
74-
M: float,
74+
maximum: float,
7575
*,
7676
rel_tol: float = 0.25,
7777
abs_tol: float = 1,
7878
) -> bool:
79-
"""Wraps math.isclose with very generous defaults.
80-
81-
This is useful for many floating-point operations where the spec does not
82-
make accuracy requirements.
83-
"""
79+
"""Like isclose() but specifically for complex values."""
8480
if cmath.isnan(a) or cmath.isnan(b):
8581
raise ValueError(f"{a=} and {b=}, but input must be non-NaN")
8682
if cmath.isinf(a):
87-
return cmath.isinf(b) or abs(b) > cmath.log(M)
83+
return cmath.isinf(b) or abs(b) > cmath.log(maximum)
8884
elif cmath.isinf(b):
89-
return cmath.isinf(a) or abs(a) > cmath.log(M)
85+
return cmath.isinf(a) or abs(a) > cmath.log(maximum)
9086
return cmath.isclose(a, b, rel_tol=rel_tol, abs_tol=abs_tol)
9187

9288

93-
9489
def default_filter(s: Scalar) -> bool:
9590
"""Returns False when s is a non-finite or a signed zero.
9691

0 commit comments

Comments
 (0)