Commit d7b5368b authored by Jeroen Demeyer's avatar Jeroen Demeyer

Implement numpy's import_array and import_ufunc in Cython

parent 0d27e211
...@@ -369,7 +369,7 @@ cdef extern from "numpy/arrayobject.h": ...@@ -369,7 +369,7 @@ cdef extern from "numpy/arrayobject.h":
npy_intp *ptr npy_intp *ptr
int len int len
void import_array() int _import_array() except -1
# #
# Macros from ndarrayobject.h # Macros from ndarrayobject.h
...@@ -960,7 +960,7 @@ cdef extern from "numpy/ufuncobject.h": ...@@ -960,7 +960,7 @@ cdef extern from "numpy/ufuncobject.h":
(PyUFuncGenericFunction *, void **, char *, int, int, int, (PyUFuncGenericFunction *, void **, char *, int, int, int,
int, char *, char *, int, char *) int, char *, char *, int, char *)
void import_ufunc() int _import_umath() except -1
cdef inline void set_array_base(ndarray arr, object base): cdef inline void set_array_base(ndarray arr, object base):
...@@ -978,3 +978,24 @@ cdef inline object get_array_base(ndarray arr): ...@@ -978,3 +978,24 @@ cdef inline object get_array_base(ndarray arr):
return None return None
else: else:
return <object>arr.base return <object>arr.base
# Versions of the import_* functions which are more suitable for
# Cython code.
cdef inline int import_array() except -1:
try:
_import_array()
except Exception:
raise ImportError("numpy.core.multiarray failed to import")
cdef inline int import_umath() except -1:
try:
_import_umath()
except Exception:
raise ImportError("numpy.core.umath failed to import")
cdef inline int import_ufunc() except -1:
try:
_import_umath()
except Exception:
raise ImportError("numpy.core.umath failed to import")
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