File tree Expand file tree Collapse file tree 5 files changed +30
-42
lines changed Expand file tree Collapse file tree 5 files changed +30
-42
lines changed Original file line number Diff line number Diff line change 41
41
42
42
%s
43
43
44
+ #include "numpy/utils.h"
45
+
44
46
#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)
45
47
static int
46
48
_import_array(void)
47
49
{
48
50
int st;
49
- PyObject *numpy = PyImport_ImportModule("numpy._core._multiarray_umath");
50
- PyObject *c_api = NULL;
51
-
51
+ PyObject *numpy = _npy_import_numpy_multiarray_umath();
52
52
if (numpy == NULL) {
53
+ PyErr_SetString(PyExc_ImportError,
54
+ "_multiarray_umath failed to import");
53
55
return -1;
54
56
}
55
- c_api = PyObject_GetAttrString(numpy, "_ARRAY_API");
57
+
58
+ PyObject *c_api = PyObject_GetAttrString(numpy, "_ARRAY_API");
56
59
Py_DECREF(numpy);
57
60
if (c_api == NULL) {
58
61
PyErr_SetString(PyExc_AttributeError, "_ARRAY_API not found");
Original file line number Diff line number Diff line change 30
30
31
31
%s
32
32
33
+ #include "numpy/utils.h"
34
+
33
35
static inline int
34
36
_import_umath(void)
35
37
{
36
- PyObject *numpy = PyImport_ImportModule("numpy._core._multiarray_umath");
37
- PyObject *c_api = NULL;
38
-
38
+ PyObject *numpy = _npy_import_numpy_multiarray_umath();
39
39
if (numpy == NULL) {
40
40
PyErr_SetString(PyExc_ImportError,
41
- "numpy._core. _multiarray_umath failed to import");
41
+ "_multiarray_umath failed to import");
42
42
return -1;
43
43
}
44
- c_api = PyObject_GetAttrString(numpy, "_UFUNC_API");
44
+
45
+ PyObject *c_api = PyObject_GetAttrString(numpy, "_UFUNC_API");
45
46
Py_DECREF(numpy);
46
47
if (c_api == NULL) {
47
48
PyErr_SetString(PyExc_AttributeError, "_UFUNC_API not found");
Original file line number Diff line number Diff line change 128
128
#include <Python.h>
129
129
#include "ndarraytypes.h"
130
130
#include "_dtype_api.h"
131
+ #include "utils.h"
131
132
132
133
/*
133
134
* The contents of PyArrayMethodObject are currently opaque (is there a way
@@ -353,7 +354,7 @@ import_experimental_dtype_api(int version)
353
354
return 0 ;
354
355
}
355
356
356
- PyObject * multiarray = PyImport_ImportModule ( "numpy._core._multiarray_umath" );
357
+ PyObject * multiarray = _npy_import_numpy_multiarray_umath ( );
357
358
if (multiarray == NULL ) {
358
359
return -1 ;
359
360
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
#ifndef NUMPY_CORE_INCLUDE_NUMPY_UTILS_H_
2
2
#define NUMPY_CORE_INCLUDE_NUMPY_UTILS_H_
3
3
4
+ #include <Python.h>
5
+
4
6
#ifndef __COMP_NPY_UNUSED
5
7
#if defined(__GNUC__ )
6
8
#define __COMP_NPY_UNUSED __attribute__ ((__unused__))
34
36
#define NPY_CAT_ (a , b ) NPY_CAT__(a, b)
35
37
#define NPY_CAT (a , b ) NPY_CAT_(a, b)
36
38
39
+ static PyObject * _npy_import_numpy_multiarray_umath ()
40
+ {
41
+ PyObject * multiarray = PyImport_ImportModule ("numpy._core._multiarray_umath" );
42
+ if (
43
+ multiarray == NULL &&
44
+ PyErr_ExceptionMatches (PyExc_ModuleNotFoundError )
45
+ ) {
46
+ PyErr_Clear ();
47
+ multiarray = PyImport_ImportModule ("numpy.core._multiarray_umath" );
48
+ }
49
+ return multiarray ;
50
+ }
51
+
37
52
#endif /* NUMPY_CORE_INCLUDE_NUMPY_UTILS_H_ */
You can’t perform that action at this time.
0 commit comments