Pure Python Mode

Cython provides language constructs to let the same file be either interpreted or compiled. This is accomplished by the same "magic" module cython that directives use and which must be imported. This is available for both .py and .pyx files.

This is accomplished via special functions and decorators and an (optional) augmenting .pxd file.

Magic Attributes

The currently supported attributes of the cython module are:

will behave differently depending on whether or not the code is loaded as a compiled .so file or a plain .py file.

Augmenting .pxd

If a .pxd file is found with the same name as a .py file, it will be searched for cdef classes and cdef/cpdef functions and methods. It will then convert the corresponding classes/functions/methods in the .py file to be of the correct type. Thus if one had a.pxd

the file a.py

would be interpreted as

Types

There are numerous types builtin to the cython module. One has all the standard c types, namely char, short, int, long, longlong as well as their unsigned versions uchar, ushort, uint, ulong, ulonglong. One also has bint and Py_ssize_t. For each type, one has pointer types p_int, pp_int, ..., up to three levels deep in interpreted mode, and infinitely deep in compiled mode. The Python types int, long and bool are interpreted as c int, long and bint respectively. Also, the python types list, dict, tuple, ... may be used, as well as any user defined types.

Pointer types may be constructed with cython.pointer(cython.int), and arrays as cython.int[10]. A limited attempt is made to emulate these more complex types, but only so much can be done from the Python language.

Decorators

We have settled on @cython.cclass for the cdef class decorators, and @cython.cfunc and @cython.ccall for cdef and cpdef functions (respectively). http://codespeak.net/pipermail/cython-dev/2008-November/002925.html

pure (last edited 2009-10-21 07:57:18 by robertwb)