mirror of
https://github.com/rasbt/python_reference.git
synced 2025-04-23 13:17:35 +00:00
examples for cython
This commit is contained in:
parent
350171ba95
commit
d490411a5f
19147
tutorials/cython_bubblesort_nomagic.c
Normal file
19147
tutorials/cython_bubblesort_nomagic.c
Normal file
File diff suppressed because it is too large
Load Diff
21
tutorials/cython_bubblesort_nomagic.pyx
Normal file
21
tutorials/cython_bubblesort_nomagic.pyx
Normal 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
14
tutorials/setup.py
Normal 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()])
|
||||||
|
]
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user