tags:

views:

23

answers:

1

Hello,

is their any way to make this work, without sacrificing the cdef in cdef caller? (no use of cpdef either)

from array import *
from numpy import *
cdef class Agents:
    cdef public caller(self):
        print "caller"
        A[1].called()

    cdef called(self):
        print "called"


A = [Agents() for i in range(2)]

def main():
    A[0].caller()
A: 

Can I ask why you can't use cpdef? As far as I understand, cdef is only used in cdef classes to declare attributes, not functions. You can use cpdef or def inside of a cdef class to declare functions.

As a side note, for anyone who tries out this code, it should be A[0] and A[1] not A[1] and A[2].

Justin Peel
Hi,the problem is that cpdef would handle it as python not cython, therefore it would get very slow. (In the real code it is called extremely often)
Davoud Taghawi-Nejad