-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change numeric demo to numpy demo using new features, update setup.py.
- Loading branch information
Showing
3 changed files
with
21 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
cimport numpy | |||
import numpy | |||
|
|||
def sum_of_squares(numpy.ndarray[double, ndim=1] arr): | |||
cdef long N = arr.shape[0] | |||
cdef double ss = 0 | |||
for i in range(N): | |||
ss += arr[i]**2 | |||
return ss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,26 +1,23 @@ | |||
import glob | # Run as: | ||
# python setup.py build_ext --inplace | |||
|
|
||
from distutils.core import setup | from distutils.core import setup | ||
from distutils.extension import Extension | from distutils.extension import Extension | ||
from Cython.Distutils import build_ext | from Cython.Build import cythonize | ||
|
|
||
ext_modules = cythonize("*.pyx", exclude="numpy_*.pyx") | |||
|
|||
# Only compile the following if numpy is installed. | |||
try: | try: | ||
from numpy.distutils.misc_util import get_numpy_include_dirs | from numpy.distutils.misc_util import get_numpy_include_dirs | ||
numpy_include_dirs = get_numpy_include_dirs() | numpy_demo = Extension("*", | ||
except: | ["numpy_*.pyx"], | ||
numpy_include_dirs = [] | include_dirs=get_numpy_include_dirs()) | ||
|
ext_modules.extend(cythonize(numpy_demo)) | ||
ext_modules=[ | except ImportError: | ||
Extension("primes", ["primes.pyx"]), | pass | ||
Extension("spam", ["spam.pyx"]), | |||
] | |||
|
|||
for file in glob.glob("*.pyx"): | |||
if file != "numeric_demo.pyx": | |||
ext_modules.append(Extension(file[:-4], [file], include_dirs = numpy_include_dirs)) | |||
|
|
||
setup( | setup( | ||
name = 'Demos', | name = 'Demos', | ||
cmdclass = {'build_ext': build_ext}, | |||
ext_modules = ext_modules, | ext_modules = ext_modules, | ||
) | ) |