-
-
Notifications
You must be signed in to change notification settings - Fork 11k
log2
way slower than log
or log10
#13836
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
Comments
Wait I just did a full C benchmark, the results are
Looks like the performance of But anyway the performance of |
The difference is probably that at least |
float32 |
So it might take a long time before fast Anyway, a quick fix would be a = np.ones(2**27, 'f')
%timeit np.log2(a)
%timeit (lambda x:np.divide(x, np.log(2), x))(np.log(a)) 480 ms ± 541 µs per loop (mean ± std. dev. of 7 runs, 1 loop each) A quick precision test a = np.random.rand(2**27).astype('f') * 1e9
np.linalg.norm(np.log2(a) - np.log(a)/np.log(2)) / len(a) 9.88357312659005e-11 |
@ZisIsNotZis that is not a viable "quick fix" within numpy (and probably a bad idea also, since not all arrays can be accelerated with AVX). Having it on Raghuveer's todo list is probably the best way to have it fairly quickly, which likely means it is in 1.18. |
see #19478 |
Reproducing code example:
Output:
Numpy/Python version information:
1.16.4 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34)
[GCC 7.3.0]
Comparison
With my straight forward implementation of
log2
The result shows
So I feel something must be wrong inside
np.log2
that make it slower than a naive single-threaded implementation? Theoretically it should not be slower thannp.log10
anywayThe text was updated successfully, but these errors were encountered: