I am writing a rather big simulation in Python and was hoping to get some extra performance from Cython. However, for the code below I don't seem to get all that much, even though it contains a rather large loop. Roughly 100k iterations.
Did I make some beginners mistake or is this loop-size simply to small to have a big effect? (In my tests the Cython code was only about 2 times faster).
import numpy as np;
cimport numpy as np;
import math
ctypedef np.complex64_t cpl_t
cpl = np.complex64
def example(double a, np.ndarray[cpl_t,ndim=2] A):
cdef int N = 100
cdef np.ndarray[cpl_t,ndim=3] B = np.zeros((3,N,N),dtype = cpl)
cdef Py_ssize_t n, m;
for n in range(N):
for m in range(N):
if np.sqrt(A[0,n]) > 1:
B[0,n,m] = A[0,n] + 1j * A[0,m]
return B;