Skip to content

Commit 5bad07d

Browse files
committed
Fix is_close tolerance in tests
1 parent ed0a59c commit 5bad07d

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/flint/test/helpers.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def is_close_arb(
2929
isinstance(x, arb)
3030
and x.rad() < max_width_arb
3131
and y.rad() < max_width_arb
32-
and abs(x - y) <= tol_arb + rel_tol_arb * max(abs(x), abs(y))
32+
and abs(x - y) <= tol_arb + rel_tol_arb * abs(y)
3333
)
3434

3535

@@ -42,10 +42,14 @@ def is_close_acb(
4242
max_width: int | float | str | arb = 1e-10,
4343
) -> bool:
4444
y = acb(y)
45+
tol_arb = arb(tol)
46+
rel_tol_arb = arb(rel_tol)
47+
max_width_arb = arb(max_width)
4548
return (
4649
isinstance(x, acb)
47-
and is_close_arb(x.real, y.real, tol=tol, rel_tol=rel_tol, max_width=max_width)
48-
and is_close_arb(x.imag, y.imag, tol=tol, rel_tol=rel_tol, max_width=max_width)
50+
and x.rad() < max_width_arb
51+
and y.rad() < max_width_arb
52+
and abs(x - y) <= tol_arb + rel_tol_arb * abs(y)
4953
)
5054

5155

src/flint/test/test_acb_poly.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ def test_acb_poly_roots_and_complex_roots() -> None:
237237
p = x**2 + 1
238238
rs0 = p.roots()
239239
assert len(rs0) == 2
240-
assert any(is_close_acb(r, 1j, tol=1e-5) for r in rs0)
241-
assert any(is_close_acb(r, -1j, tol=1e-5) for r in rs0)
240+
assert any(is_close_acb(r, 1j, tol=1e-5, max_width=1e-5) for r in rs0)
241+
assert any(is_close_acb(r, -1j, tol=1e-5, max_width=1e-5) for r in rs0)
242242

243243
rs = p.roots(tol=1e-30, maxprec=128)
244244
assert len(rs) == 2

src/flint/test/test_arb_poly.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def test_arb_poly_from_roots_and_complex_roots() -> None:
5959

6060
roots = arb_poly([1, 0, 1]).complex_roots()
6161
assert len(roots) == 2
62-
assert any(is_close_acb(r, acb(0, 1), tol=1e-5) for r in roots)
63-
assert any(is_close_acb(r, acb(0, -1), tol=1e-5) for r in roots)
62+
assert any(is_close_acb(r, acb(0, 1), tol=1e-5, max_width=1e-5) for r in roots)
63+
assert any(is_close_acb(r, acb(0, -1), tol=1e-5, max_width=1e-5) for r in roots)
6464

6565

6666
def test_arb_poly_evaluate() -> None:

0 commit comments

Comments
 (0)