import numpy as np
cimport numpy as np
cimport cython
from libc.math cimport pow
from math import pow as pypow
# using np.power
def run():
cdef int i
cdef double[:] result = np.empty(20, dtype=np.double)
cdef double[:] r_array = np.random.rand(20)
for i in range(20000):
result = np.power(r_array, 1.5)
return result
# using pow() from libc.math
def pure_run():
cdef unsigned int i, j
cdef double[:] result = np.empty(20, dtype=np.double)
cdef double[:] r_array = np.random.rand(20)
for i in range(20000):
for j in range(20):
result[j] = pow(r_array[j], 1.5)
return result
# using python's pow()
def py_run():
cdef int i, j
cdef double[:] result = np.empty(20, dtype=np.double)
cdef double[:] r_array = np.random.rand(20)
for i in range(20000):
for j in range(20):
result[j] = pypow(r_array[j], 1.5)
return result