I might have spoken a bit too...excitedly at the Clawpack dev meeting last Monday about my progress with using Cython in the next version of Clawpack and as a result I got a few confused looks. :) My fault for not explaining the vision well. So just to be clear, Cython is a programming language built on top of Python that makes it easy to use and write fast C code with which Python functions and classes can interact. Anyway, right now I'm using Cython to come up with ways to allow users to provide their own solver routines, such as rp, src, step, etc., via a nice Python interface.
So I was looking deeper into how Cython turns a Cython source file (.pyx, .pxd) into a C file and then into a compiled Python module. Essentially, Cython is a tool built around the Python package, distutils. distutils is a module for importing specially-formatted C / C++ code. Cython makes is easier to write this code without having think to hard about the Python API.
First the user writes some C / C++ code using all sorts of pre-defined, Python interoperable structs and classes and such. That is, the user needs to conform to the Python C API, via#include "Python.h", and write the functions and operations such that they can properly interact with Python objects. Poke around this documentation and you'll see what I mean.
Now, you can feed that file into the usual setup() function from distutils. See the Cython documentation for more information on how to do that.
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment