Commit 422fd199 authored by Robert Bradshaw's avatar Robert Bradshaw

Inline numpy support.

parent 9de33b2a
...@@ -106,21 +106,24 @@ def cython_inline(code, ...@@ -106,21 +106,24 @@ def cython_inline(code,
arg_names = kwds.keys() arg_names = kwds.keys()
arg_names.sort() arg_names.sort()
arg_sigs = tuple([(get_type(kwds[arg], ctx), arg) for arg in arg_names]) arg_sigs = tuple([(get_type(kwds[arg], ctx), arg) for arg in arg_names])
key = code, arg_sigs key = code, arg_sigs, sys.version_info, sys.executable, Cython.__version__
module_name = _code_cache.get(key) module_name = "_cython_inline_" + hashlib.md5(str(key)).hexdigest()
if module_name is None:
module_name = "_cython_inline_" + hashlib.md5(code + str(arg_sigs) + Cython.__version__).hexdigest()
try: try:
if lib_dir not in sys.path: if lib_dir not in sys.path:
sys.path.append(lib_dir) sys.path.append(lib_dir)
__import__(module_name) __import__(module_name)
except ImportError: except ImportError:
c_include_dirs = []
cimports = [] cimports = []
qualified = re.compile(r'([.\w]+)[.]') qualified = re.compile(r'([.\w]+)[.]')
for type, _ in arg_sigs: for type, _ in arg_sigs:
m = qualified.match(type) m = qualified.match(type)
if m: if m:
cimports.append('\ncimport %s' % m.groups()[0]) cimports.append('\ncimport %s' % m.groups()[0])
# one special case
if m.groups()[0] == 'numpy':
import numpy
c_include_dirs.append(numpy.get_include())
module_body, func_body = extract_func_code(code) module_body, func_body = extract_func_code(code)
params = ', '.join(['%s %s' % a for a in arg_sigs]) params = ', '.join(['%s %s' % a for a in arg_sigs])
module_code = """ module_code = """
...@@ -136,7 +139,7 @@ def __invoke(%(params)s): ...@@ -136,7 +139,7 @@ def __invoke(%(params)s):
extension = Extension( extension = Extension(
name = module_name, name = module_name,
sources = [pyx_file], sources = [pyx_file],
pyrex_include_dirs = include_dirs) include_dirs = c_include_dirs)
build_extension = build_ext(Distribution()) build_extension = build_ext(Distribution())
build_extension.finalize_options() build_extension.finalize_options()
build_extension.extensions = cythonize([extension]) build_extension.extensions = cythonize([extension])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment