Improving Cython code
Closed this issue · 1 comments
I am (yet again) impressed by the performance of Numba compared to Cython and Fortran. I just wanted to note that the Cython version can be made slightly faster (on par with Fortran) with a couple of tweaks. Using @cython.wraparound(False)
and avoiding negative indices helps, as does @cython.cdivision(True)
. Further, annotations (use %%cython -a
) show that there are some remaining Python calls within the main loop. All that is needed is to hand code loops that copy the array at the beginning and calculate the difference at the end. Cython does not seem to be able to translate the NumPy calls fully to C.
Hey @OndrejMarsalek -- awesome! Thanks for the tips! I am definitely not a Cython expert so it's great to have some input on how to improve it. PRs definitely welcome if you're up to it, otherwise I'll try to put this tips to good use some time in the next few weeks.