cdef class Function:
cpdef double evaluate(self, double x) except *:
- return 0
+ return 0
Like before, cpdef makes two versions of the method available; one
fast for use from Cython and one slower for use from Python. Then::
cdef class SinOfSquareFunction(Function):
cpdef double evaluate(self, double x) except *:
- return sin(x**2)
+ return sin(x**2)
Using this, we can now change our integration example::
cdef public double freq
# Available in Python-space:
property period:
- def __get__(self):
- return 1.0 / self. freq
- def __set__(self, value):
- self. freq = 1.0 / value
+ def __get__(self):
+ return 1.0 / self.freq
+ def __set__(self, value):
+ self.freq = 1.0 / value
<...>
raise IndexError("Queue is empty")
return value
- cdef int pop(self) except? -1:
+ cpdef int pop(self) except? -1:
if cqueue.queue_is_empty(self._c_queue):
raise IndexError("Queue is empty")
return <int>cqueue.queue_pop_head(self._c_queue)