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

Reply via email to