[Cython] __next__ | not being able to use cpdef
Jelle Feringa
jelleferinga at gmail.com
Sat Dec 6 16:23:10 CET 2008
Hi,
I just started to use Cython, for writing a set of fast iterators.
Go easy on me, this is all new territory ;')
Now, the thing is that if I understood correctly, it would be faster
to have the __next__ method types a cpdef int __next__(self )
When I do so the module fails to compile.
Is there a specific reason why this is so?
Still, using the object below, accessing objects from an iterable is
twice as fast.
Thanks,
-jelle
cdef class FastLoopObj1d:
cdef int N, i
cdef object obj
def __init__(self, n, obj ):
self.N = n-1
self.i = 0
self.obj = obj
def __iter__(self):
return self
# no cpdef allowed?
def __next__( self ):
if self.i < self.N:
self.i+=1
return self.obj[self.i]
else:
raise StopIteration
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/cython-dev/attachments/20081206/dcd68519/attachment.htm
More information about the Cython-dev
mailing list