Had a basic question after reading the Cython documentation on classes, but I thought to get it clear. Here is a sample code from the Cython documentation:
cdef class Rectangle:
cdef int x0, y0
cdef int x1, y1
def __init__(self, int x0, int y0, int x1, int y1):
self.x0 = x0; self.y0 = y0; self.x1 = x1; self.y1 = y1
cpdef int area(self):
cdef int area
area = (self.x1 - self.x0) * (self.y1 - self.y0)
if area < 0:
area = -area
return area
Why is the __init__
preceded by def
and not cdef
or cpdef
?
I realize that there is a __cinit__
function, but shouldn't making cpdef __init__
make the __init__
code faster?
Or, are we supposed to put the code, that we need to make very fast, in the __cinit__
section and the code, which we can afford to run slower, in the __init__
section?