How do I speed up matrix functions like the expm function in scipy / numpy?

I use scipy

and numpy

to scipy

calculate the power of 6 * 6.

Compared to Matlab, it is about 10 times slower.

I use scipy.linalg.expm

, I have also tried the deprecated methods scipy.linalg.expm2

and scipy.linalg.expm3

, and they are only twice as fast as expm

. My question is:

  1. What's wrong with expm2

    and expm3

    how are they faster than expm

    ?

  2. I am using the wheel package from http://www.lfd.uci.edu/~gohlke/pythonlibs/ and I found https://software.intel.com/en-us/articles/building-numpyscipy-with- intel- mkl-and-intel-fortran-on-windows . This is a wheel pack compiled with MKL. If not, then I think I can optimize and buy up, compile it myself with MKL?

  3. Are there other ways to optimize performance?

+4


source to share


2 answers


I think I found the answer to question 1 and 2 myself 1. It seems that expm2 and expm3 return an array, not a matrix. But they are about 2x faster than expm

  1. Ok, after a whole day trying to compile scipy from MKL, I succeeded. It is very difficult to build scipy, especially when I am using windows, x64 and python3. It turned out to be a waste of time. It's even slightly faster than the whl package from http://www.lfd.uci.edu/~gohlke/pythonlibs/ .


Hope someone answers question 3.

0


source


Your matrix is ​​relatively small, so maybe the numeric part is not the bottleneck. You must use a profiler to make sure the constraint is in exposure. You can also take a look at the source code of these implementations and write an equivalent function with less conditionals and checks.



0


source







All Articles