examples for cython

This commit is contained in:
rasbt 2014-07-06 22:35:00 -04:00
parent 350171ba95
commit d490411a5f
4 changed files with 19629 additions and 146 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,21 @@
cimport numpy as np
cimport cython
@cython.boundscheck(False)
@cython.wraparound(False)
cpdef cython_bubblesort_nomagic(np.ndarray[long, ndim=1] inp_ary):
""" The Cython implementation of Bubblesort with NumPy memoryview."""
cdef unsigned long length, i, swapped, ele, temp
cdef long[:] np_ary = inp_ary
length = np_ary.shape[0]
swapped = 1
for i in xrange(0, length):
if swapped:
swapped = 0
for ele in xrange(0, length-i-1):
if np_ary[ele] > np_ary[ele + 1]:
temp = np_ary[ele + 1]
np_ary[ele + 1] = np_ary[ele]
np_ary[ele] = temp
swapped = 1
return inp_ary

File diff suppressed because one or more lines are too long

14
tutorials/setup.py Normal file
View File

@ -0,0 +1,14 @@
import numpy as np
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [
Extension("cython_bubblesort_nomagic",
["cython_bubblesort_nomagic.pyx"],
include_dirs=[np.get_include()])
]
)