Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to improve Cython performance?

I am doing my first steps with Cython, and I am wondering how to improve performance even more. Until now I got to half the usual (python only) execution time, but I think there must be more!

I know cython -a and I already typed my variables. But there is still a lot in yellow in my function. Is this because cython does not recognise numpy or is there something else I am missing?

like image 560
Sebastian Avatar asked Nov 26 '25 07:11

Sebastian


1 Answers

I believe you can benefit by using math functions from libc as you are calling np.sqrt and np.floor on scalars. This has not only the Python call overhead but there are different code paths in the numpy ufuncs for scalars and arrays. So that involves at least a type switch.

like image 164
Robert Franke Avatar answered Nov 27 '25 20:11

Robert Franke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!