Skip to content

Instantly share code, notes, and snippets.

@kigawas
Created June 26, 2018 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kigawas/cc4f84cb8c51a0fa92448e85da603d7b to your computer and use it in GitHub Desktop.
Save kigawas/cc4f84cb8c51a0fa92448e85da603d7b to your computer and use it in GitHub Desktop.
Cython example of multiple pyx files
cdef int _fib(int n):
cdef int i
cdef int a=0, b=1
for i in range(n):
a, b = a + b,a
return a
def fib(n):
return _fib(n)
import a
def caller(n):
return a.fib(n)
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize('./*.pyx'))
@kigawas
Copy link
Author

kigawas commented Jun 26, 2018

Run:
python3 setup.py build_ext --inplace
Test in ipython or python shell like:

>>> import a, b
>>> a.fib(10)
55
>>> b.caller(10)
55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment