Hi all,
I'm trying to get the grasp on Cython. I know a little bit of C, so I
understand the concept of data types.
But I'm still not sure how to use things properly. So, for instance, is the
following optimization reasonable?
(there is an ~30% increase in speed from pure python code)
%cython
import itertools
cdef int j
cdef int commonzeros
cdef int i
# L: A list of tuples of positive integers, each having a couple of hundred
elements.
# L itself has length at most 3 or 4.
# e: A tuple of integers. e has length no more than a couple of hundred.
# w a small integer
def myfunction(L,e, int w):
for rows in itertools.product(range(w), repeat=len(L)):
commonzeros=0
for j in e:
for i in range(len(L)):
if all( [(L[i][rows[i]]+j %w)==0] ):
commonzeros+=1
if commonzeros==4:
return(1)
return(0)
Here is the spyx.html file. It seems that I haven't really optimized much,
have I?
Any advice? What would you do to optimize the above code in cython?
<https://lh4.googleusercontent.com/-iu0cS3g_E44/UyDGpNnbNRI/AAAAAAAAEC8/rWTnA_1sGyw/s1600/Screenshot+from+2014-03-12+16%3A37%3A38.png>
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.