February 2019
Intermediate to advanced
672 pages
16h 50m
English
We can define an extension type using the cdef class statement and declaring its attributes in the class body. For example, we can create an extension type--Point--as shown in the following code, which stores two coordinates (x, y) of the double type:
cdef class Point cdef double x cdef double y def __init__(self, double x, double y): self.x = x self.y = y
Accessing the declared attributes in the class methods allows Cython to bypass expensive Python attribute look-ups by direct access to the given fields in the underlying C struct. For this reason, attribute access in typed classes is an extremely fast operation.
To use the cdef class in your code, you need to explicitly declare the type of the variables you intend to use at ...