[SciPy-user] Speed differences in sqrt calculation: what is good to know
Wed Jun 11 15:06:09 CDT 2008
2008/6/11 David Cournapeau <email@example.com>:
> Ivo Maljevic wrote:
> > Based on comments from Gael Varoquaux and David Cournapeau , I did the
> > execution time test.
> > At least for me, it is clear that if the number is a real scalar, AND
> > the expected result is also real,
> > the best way is to call the math version of sqrt() function. The
> > differences are more than significant, as you can see:
> It is expected for numpy/scipy functions to be much slower than python
> *for scalar*. Since they are optimized to be used with arrays, you are
> paying the cost to initialize the machinery to handle arrays (ufunc),
> without the benefit.
No disagreement there. My comment, which I realize was probably unnecessary,
one has to pay attention as to which version of the function is called.
Since I started SciPy I always used everything from it, never even thinking
that math.sqrt(), math.sin(), etc., are faster if I'm working with scalar
values. And there are always coefficients or scaling parameters that do not
need to be in a vector form.
> The problem really is the difference between numpy and scipy. The funny
> thing is that for arrays, scipy.sqrt (that is, numpy.lib.scimath.sqrt)
> is faster than numpy.sqrt, which does not quite make sense to me since
> scipy.sqrt calls numpy.sqrt... But it is 1 a.m, so maybe I should just
> get some sleep
I think it is the numpy.sqrt that is faster (about 7 to 10 times) than
scipy.sqrt, but anyway, it would be good to have them at the same speed
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-user