I am trying to optimize a Python code where the following mathematical function has to be evaluated many (many) times
from math import pow, pi
from scipy.special import gamma
def norm_spirals(a,k):
return pi*pow(abs(gamma(0.25+0.5*k+0.5j*a)/gamma(0.75+0.5*k+0.5j*a)),2)
I have already optimized as much as possible my code using cProfile
and timeit
. I also got rid of the call
to the procedure and direcly embedded this calculation in the code. The last step of optimization I could think of, is to tune the order of the mathematical operations in order to accelerate the evaluation. The formula above is the fastest form that I have been able to obtain using timeit
.
- Would you think of another order of calculation for this formula that could be faster ?
- Would you have any ideas of other optimizations I could use ?
Thank you in advance for your help !