I __next__ falls in the category of special methods, please read the fine docs
http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/version/Doc/Manual/special_methods.html Declare __next__ with 'def', they are treated specially and are as fast as the CPython implementation permits. On Sat, Dec 6, 2008 at 12:23 PM, Jelle Feringa <[EMAIL PROTECTED]> wrote: > 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 > > > > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev > > -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
