[SciPy-user] Speed differences in sqrt calculation: what is good to know

Ivo Maljevic ivo.maljevic@gmail....
Wed Jun 11 15:06:09 CDT 2008

2008/6/11 David Cournapeau <david@ar.media.kyoto-u.ac.jp>:

> 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,
is that
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...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080611/0e179be6/attachment.html 

More information about the SciPy-user mailing list