cython

3 views
Skip to first unread message

Ondrej Certik

unread,
Mar 4, 2011, 3:47:35 AM3/4/11
to py...@googlegroups.com
Hi guys,

before the meeting in the morning (evening for you), could you briefly
look at Cython:

http://cython.org/

and browse the documentation + examples. Cython is *extremely* popular
in the Python scientific community, and thanks to our recent
discussion, it just occurred to me now, that they have the exact same
problem as we do, except that they translate to C, but py2js to
JavaScript.

1) Their standard mode compiles *any* Python code (it used to be a
subset, then a bigger subset, and now pretty much any code can be
compiled, except some corner cases) into C, and calls Python C/API in
the generated C
2) If you tell Cython that some variable is a C variable, then it will
not generate a PyObject for it, but a C "int" (if you specify it to be
int), or double, or whatever you specify. You can specify a function
to be a C function.
3) If you call external C code, you need to declare it, as a c
function, defined externally
4) If you want to call the generated Python code from C, you need to
declare a Python function as "api", and it will generate a C header
file with a declaration that you can call and it will just work

Now change C for JavaScript and this is exactly what we need to do.
Their Python C/API is our py-builtins.js. Note that Cython itself can
be compiled by Cython. Just like py2js eventually will be. However,
the Python C/API so far is not written in Cython (in principle it
could be though), just like our py-builtins.js is (so far!) written by
hand. I am just pointing this out, that in the Cython case, it really
doesn't seem to be a problem at all.

Thanks to Cython, you don't need to touch C at all, if you don't want
to, and yet you can write as optimized code as in C, if needed. I can
explain once we talk over skype, but if you could look at it and think
about it, it'd be great.

Off to bed.

Ondrej

Samuel Ytterbrink

unread,
Mar 4, 2011, 5:32:28 AM3/4/11
to py...@googlegroups.com
Done! :D

/Samuel Ytterbrink

2011/3/4 Ondrej Certik <ond...@certik.cz>
Reply all
Reply to author
Forward
0 new messages