8000 Faster real_if_close. by anntzer · Pull Request #7489 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Faster real_if_close. #7489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
anntzer committed Mar 31, 2016
commit 9fba2cb5ebddd4790be60801aa0aa62027fbfd02
2 changes: 1 addition & 1 deletion numpy/lib/type_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def real_if_close(a,tol=100):
from numpy.core import getlimits
f = getlimits.finfo(a.dtype.type)
tol = f.eps * tol
if _nx.allclose(a.imag, 0, atol=tol):
if _nx.all(_nx.absolute(a.imag) < tol):
a = a.real
return a

Expand Down
0