[SciPy-User] faster expm
Craig Jones
craig.bulk@brechmos....
Sat Oct 30 11:25:45 CDT 2010
I tried expm, expm2 and expm3 and the total time was no different. Using
q=2 on expm decreased the time by a bit (4m 20s to 3m 38s).
Here is a profile when I use expm:
ncalls tottime percall cumtime percall filename:lineno(function)
469200 58.505 0.000 158.295 0.000 matfuncs.py:26(expm)
4692000 23.989 0.000 23.989 0.000 {method 'any' of
'numpy.ndarray' objects}
2346000 23.508 0.000 52.313 0.000
function_base.py:523(asarray_chkfinite)
5664800 22.470 0.000 22.470 0.000 {numpy.core._dotblas.dot}
938400 19.571 0.000 83.525 0.000 basic.py:23(solve)
469200 18.089 0.000 76.861 0.000 bloch.py:41(updateA)
1878096 14.115 0.000 15.308 0.000
numerictypes.py:808(_can_coerce_all)
1 13.843 13.843 290.918 290.918 bloch.py:90(solve)
In general my matrix looks something like:
-13.59091 28.00000 8.00000 -6419.40476 0.00000 0.00000 0.00000 0.00000
0.00000
0.05091 -58.30303 0.00000 0.00000 -9227.89435 0.00000 0.00000 0.00000
0.00000
1.04000 0.00000 -100008.00000 0.00000 0.00000 -6419.40476 0.00000 0.00000
0.00000
6419.40476 0.00000 0.00000 -13.59091 28.00000 8.00000 0.00000 0.00000
0.00000
0.00000 9227.89435 0.00000 0.05091 -58.30303 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 6419.40476 1.04000 0.00000 -100008.00000 0.00000 0.00000
0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 -2.51948 28.00000 8.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.05091 -29.29870 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 1.04000 0.00000 -8.83333
And the call is:
y = dot(scipy.linalg.expm(A*pulse[m,2], q=2),(y+Ainvb))-Ainvb
In all my experience python/numpy/scipy is very fast. I think for this
situation because I am calling this so many times it just feels bogged
down. I do want to see if I can use this code with a fitting algorithm so
the faster I can make this the better off I am.
Any other ideas?
Craig
On Sat, Oct 30, 2010 at 10:24 AM, Pauli Virtanen <pav@iki.fi> wrote:
> Sat, 30 Oct 2010 10:02:57 -0400, Craig Jones wrote:
> > I have been using scipy etc for just over a year now and am now
> > exclusively using it. One application I have been doing requires a
> > matrix exponential (in lieu of integration). In Matlab it was very fast
> > but using scipy.linalg.expm it is quite slow (as the actual algorithm is
> > implemented in python). In fact about 50% of the code is spent in expm.
> > My matrix is typically 9x9 to 12x12 and is about 50% zeros (most
> > nonzero are along the diagonal and just off diagonal).
>
> Well, it's also quite possible the difference is just that the algorithm
> in Scipy is not optimal and does more matrix products than necessary,
> rather than the problem being in Python overhead. Would require
> benchmarking of the expm code. Moreover, Scipy's expm always uses a fixed
> degree for the Pade approximant, which might not be the optimal choice.
>
> --
> Pauli Virtanen
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20101030/865991dc/attachment.html
More information about the SciPy-User
mailing list