diff options
| author | Sebastian Berg <sebastianb@nvidia.com> | 2023-02-10 15:51:57 +0100 |
|---|---|---|
| committer | Sebastian Berg <sebastianb@nvidia.com> | 2023-02-10 15:51:57 +0100 |
| commit | 9d5eafe596e75e30a85c01ed62bb5bea9389adc8 (patch) | |
| tree | edbb8b862867c50ea2b93359f6785da3a679a4c0 /numpy/core/src/multiarray | |
| parent | 0d9d10dd6d23d874701bcff951510a178f6836be (diff) | |
| download | numpy-9d5eafe596e75e30a85c01ed62bb5bea9389adc8.tar.gz | |
MAINT: Use `np._using_numpy2_behavior()` and initialize it in C
Diffstat (limited to 'numpy/core/src/multiarray')
| -rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 86869c8e4..4fa58c4df 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -4422,6 +4422,15 @@ _reload_guard(PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args)) { Py_RETURN_NONE; } + +static PyObject * +_using_numpy2_behavior( + PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args)) +{ + return PyBool_FromLong(npy_numpy2_behavior); +} + + static struct PyMethodDef array_module_methods[] = { {"_get_implementing_args", (PyCFunction)array__get_implementing_args, @@ -4647,6 +4656,8 @@ static struct PyMethodDef array_module_methods[] = { {"_reload_guard", (PyCFunction)_reload_guard, METH_NOARGS, "Give a warning on reload and big warning in sub-interpreters."}, + {"_using_numpy2_behavior", (PyCFunction)_using_numpy2_behavior, + METH_NOARGS, NULL}, {"from_dlpack", (PyCFunction)from_dlpack, METH_O, NULL}, {NULL, NULL, 0, NULL} /* sentinel */ @@ -4919,15 +4930,10 @@ initialize_static_globals(void) return -1; } - PyObject *_is_numpy2 = NULL; - npy_cache_import("numpy", "_numpy2_behavior", &_is_numpy2); - if (_is_numpy2 == NULL) { - return -1; - } - npy_numpy2_behavior = PyObject_IsTrue(_is_numpy2); - Py_DECREF(_is_numpy2); - if (npy_numpy2_behavior < 0) { - return -1; + /* Initialize from certain environment variabels: */ + char *env = getenv("NPY_NUMPY_2_BEHAVIOR"); + if (env != NULL && strcmp(env, "0") != 0) { + npy_numpy2_behavior = NPY_TRUE; } return 0; |
