Cythonized Function Unexpectedly Slow
I wanted to speed up a function that I'm using a lot and I though about using cython. However, after trying all the possible cython optimizations that I've been able to find in the
Solution 1:
Just glancing at your code, it looks like something (A subtraction of arrays and dot product.) that numpy
is already very optimized for.
Cython is great for speeding up cases where numpy often performs poorly (e.g. iterative algorithms where the iteration is written in python), but in this case, the inner loop is already being preformed by a BLAS library.
If you want to speed things up, the first place I'd look is what BLAS/LAPACK/ATLAS/etc libraries numpy is linked against. Using a "tuned" linear algebra library (e.g. ATLAS or Intel's MKL) will make a large (>10x in some cases) difference in cases like this.
To find out what you're currently using have a look at the output of numpy.show_config()
Post a Comment for "Cythonized Function Unexpectedly Slow"