np.isclose is slow
See original GitHub issuenp.isclose is very slow compared with math.isclose
Reproducing code example:
import numpy as np
import timeit
print(timeit.timeit('np.isclose(0.5, 0, atol=1e-4)', 'import numpy as np', number=10000))
# 0.487607091999962
print(timeit.timeit('math.isclose(0.5, 0, abs_tol=1e-4)', 'import math', number=10000))
# 0.007888869999987946
Error message:
Numpy/Python version information:
1.17.4 3.7.5 (default, Dec 9 2019, 22:42:26) [Clang 11.0.0 (clang-1100.0.33.12)]
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Unable to understand working of np.isclose() - Stack Overflow
I am unable to understand why np.isclose() is unable to match column element-wise but is able to do it correctly for rows.
Read more >is numpy isclose function returning bad answer?
No, it uses both an absolute and relative tolerance, and the default of rtol is nonzero, adding some more tolerance.
Read more >How to speed up segment of code that are slowed by ... - Reddit
Having profiled the code, I know the bottleneck is the repeated call to numpy.isclose() within the function, since the profiler explicitly ...
Read more >numpy.isclose — NumPy v1.24 Manual
For finite values, isclose uses the following equation to test whether two floating point ... np.isclose([1e10,1e-7], [1.00001e10,1e-8]) array([ True, ...
Read more >Interpolation of an expression is slow, starting at a certain time ...
I'm slowly getting hang of how things work, but still a lot of things are ... CellType.tetrahedron, ) def bottom(x): return np.isclose(x[2], ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hehe, one of the least used and stranger features… But, its not exposed for reductions:
It feels a bit silly that it includes the buffersize, although you could use
np.geterrobj()[0]
, which probably incurs mainly existing overheads. (at this time, what will make that above line slower, is probably mainly the fact thatextobj
is passed by kwargs, and we do not use vectorcall.@Hoiy I think we will accept PRs for some of the things you found, but there is probably only so much to be done, considering that this calls many functions all of which incur a significant overhead since they are written to be fast for arrays and not scalars. (and in general any function call has a fairly significant overhead).
Apologies, I missed the
import *
used at the bottom (!) of this file.