8000 Faster real_if_close. · numpy/numpy@9fba2cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 9fba2cb

Browse files
committed
Faster real_if_close.
Because of the complexity of `allclose`, `real_if_close(t)` used to be ~2.5-3x slower than, say, `t + t`. This patch makes it approximately as fast.
1 parent 25d60a9 commit 9fba2cb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

numpy/lib/type_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def real_if_close(a,tol=100):
424424
from numpy.core import getlimits
425425
f = getlimits.finfo(a.dtype.type)
426426
tol = f.eps * tol
427-
if _nx.allclose(a.imag, 0, atol=tol):
427+
if _nx.all(_nx.absolute(a.imag) < tol):
428428
a = a.real
429429
return a
430430

0 commit comments

Comments
 (0)
0