summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2023-02-12 09:12:36 +0200
committerGitHub <noreply@github.com>2023-02-12 09:12:36 +0200
commit5c7fde654c7cc9d9f32f29f82f5cb034c3c3ccaa (patch)
tree9d21c3e3f62276dbd35303d49203ca4834ee1e09 /numpy/core/src
parent9dde0a930aa568bbdd3ba176b12d1d46c72d3d4e (diff)
parent9d5eafe596e75e30a85c01ed62bb5bea9389adc8 (diff)
downloadnumpy-5c7fde654c7cc9d9f32f29f82f5cb034c3c3ccaa.tar.gz
Merge pull request #23089 from seberg/numpy2-flag
API: Add environment variable for behavior planned in a 2.0
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c23
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.h2
2 files changed, 25 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index db7fda32d..4fa58c4df 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -98,6 +98,12 @@ _umath_strings_richcompare(
* future.
*/
int npy_legacy_print_mode = INT_MAX;
+/*
+ * Global variable to check whether NumPy 2.0 behavior is opted in.
+ * This flag is considered a runtime constant.
+ */
+int npy_numpy2_behavior = NPY_FALSE;
+
static PyObject *
set_legacy_print_mode(PyObject *NPY_UNUSED(self), PyObject *args)
@@ -4416,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,
@@ -4641,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 */
@@ -4913,6 +4930,12 @@ initialize_static_globals(void)
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;
}
diff --git a/numpy/core/src/multiarray/multiarraymodule.h b/numpy/core/src/multiarray/multiarraymodule.h
index 809736cd2..992acd09f 100644
--- a/numpy/core/src/multiarray/multiarraymodule.h
+++ b/numpy/core/src/multiarray/multiarraymodule.h
@@ -1,6 +1,8 @@
#ifndef NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_
#define NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_
+NPY_VISIBILITY_HIDDEN extern int npy_numpy2_behavior;
+
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_current_allocator;
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array;
NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_function;