[SciPy-User] sqrtm is too slow for matrices of size 1000

Nathaniel Smith njs at pobox.com
Fri Jun 14 10:07:50 EDT 2013


On 14 Jun 2013 14:46, "Paul Blelloch" <paul.blelloch at gmail.com> wrote:
>
> I think that I found the problem.  It was in not recognizing that the
inner for loop is actually a dot product.  If I replace the following lines
of code:
>
>
> s = 0
>
> for k in range(i+1,j):
>
>     s = s + R[i,k]*R[k,j]
>
>
> with
>
>
> s = np.dot(R[i,(i+1):j],R[(i+1):j,j])
>
>
> Run time decreases from 367 to 15.6 seconds.  My guess is that you could
get considerable further speedup, but I'm pleased with the 15.6 seconds.
If you copy the sqrtm function from scipy and make that change I think that
you'll see considerable improvement.

If you'd like to submit a pull request with this change then I bet the
scipy developers will be very interested...

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20130614/8350d13e/attachment.html>


More information about the SciPy-User mailing list