%%cython
import numpy as np
cimport numpy as np
def cy_sum(int n):
cdef double s=0
cdef int i
for i in range(n):
s += np.sqrt(i)
return s
I have the code for calculating the sum of square root as above.
By using cython -a, I got the result as in the picture.
The cython code interacts with python at function call np.sqrt(i), and there is no improvement compared to pure python code.
I don't know if I have done something wrong in specifying the type of variables.
There are other solutions, such as using i**(1/2) or import the function sqrt from clib, but I would like to understand why cython cannot compile np.sqrt in this case.
Thank you.
