[CentralOH] Cython Bootstrap::Decorators
James Bonanno
james at atlantixeng.com
Mon Apr 6 04:38:21 CEST 2015
Hello All;
As a follow up from last weeks presentation on Cython, I would like to
add a quick explanation of how to use Cython in a more "pure" Pythonic
way. You can use a cython decorator. For example, in the code below, the
@cython.locals decorator is the same as a "cdef" static type definition.
I added this example to the Cython Bootstrap notebook and pushed it to
the GIT repo. The basic code is shown below. To get the repo : git clone
git at github.com:saturn77/CythonBootstrap.git
%%file ./src/exponent.pyx
@cython.locals(a = cython.int, x = cython.int, y = cython.int)
def power(a, x):
y = a**x
return y
from src import exponent
[exponent.power(x,3) for x in range(10)]
Out[222]:
[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
More information about the CentralOH
mailing list