Skip to content

Commit

Permalink
Change numeric demo to numpy demo using new features, update setup.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwb committed Dec 10, 2010
1 parent 31fe44b commit b18d94e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 54 deletions.
39 changes: 0 additions & 39 deletions Demos/numeric_demo.pyx

This file was deleted.

9 changes: 9 additions & 0 deletions Demos/numpy_demo.pyx
@@ -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
27 changes: 12 additions & 15 deletions Demos/setup.py
@@ -1,26 +1,23 @@
import glob
# Run as:
# python setup.py build_ext --inplace

from distutils.core import setup
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:
from numpy.distutils.misc_util import get_numpy_include_dirs
numpy_include_dirs = get_numpy_include_dirs()
except:
numpy_include_dirs = []

ext_modules=[
Extension("primes", ["primes.pyx"]),
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))
numpy_demo = Extension("*",
["numpy_*.pyx"],
include_dirs=get_numpy_include_dirs())
ext_modules.extend(cythonize(numpy_demo))
except ImportError:
pass

setup(
name = 'Demos',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,
)

0 comments on commit b18d94e

Please sign in to comment.