Cython - Bryant University

Cython

Optimization in Python

April 2008 Brian Blais

Rule #1 of Optimization

"Premature optimization is the root of all evil" - Donald Knuth

What is Cython/Pyrex?

Python to C/Python-API Converter Extension modules to optimize code

Example.pyx

import numpy def this():

print "hello world" a=5 b=numpy.abs(a)

Example.C

static char __pyx_k_2[] = "hello world"; __pyx_v_a = Py_None; Py_INCREF(Py_None); __pyx_v_b = Py_None; Py_INCREF(Py_None);

/* print "hello world"

*/

if (__Pyx_PrintItem(__pyx_k_2p) < 0) { __pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}

if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx _f[0]; __pyx_lineno = 5; goto __pyx_L1;}

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download