Skip to content

Commit b706536

Browse files
committed
MNT: apply sebastian's refactoring suggestions
1 parent e43275a commit b706536

38 files changed

+301
-297
lines changed

numpy/_core/src/common/npy_cpu_dispatch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
NPY_VISIBILITY_HIDDEN int
99
npy_cpu_dispatch_tracer_init(PyObject *mod)
1010
{
11-
if (npy_ma_static_data.cpu_dispatch_registry != NULL) {
11+
if (npy_static_pydata.cpu_dispatch_registry != NULL) {
1212
PyErr_Format(PyExc_RuntimeError, "CPU dispatcher tracer already initlized");
1313
return -1;
1414
}
@@ -25,21 +25,21 @@ npy_cpu_dispatch_tracer_init(PyObject *mod)
2525
if (err != 0) {
2626
return -1;
2727
}
28-
npy_ma_static_data.cpu_dispatch_registry = reg_dict;
28+
npy_static_pydata.cpu_dispatch_registry = reg_dict;
2929
return 0;
3030
}
3131

3232
NPY_VISIBILITY_HIDDEN void
3333
npy_cpu_dispatch_trace(const char *fname, const char *signature,
3434
const char **dispatch_info)
3535
{
36-
PyObject *func_dict = PyDict_GetItemString(npy_ma_static_data.cpu_dispatch_registry, fname);
36+
PyObject *func_dict = PyDict_GetItemString(npy_static_pydata.cpu_dispatch_registry, fname);
3737
if (func_dict == NULL) {
3838
func_dict = PyDict_New();
3939
if (func_dict == NULL) {
4040
return;
4141
}
42-
int err = PyDict_SetItemString(npy_ma_static_data.cpu_dispatch_registry, fname, func_dict);
42+
int err = PyDict_SetItemString(npy_static_pydata.cpu_dispatch_registry, fname, func_dict);
4343
Py_DECREF(func_dict);
4444
if (err != 0) {
4545
return;

numpy/_core/src/common/npy_ctypes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ npy_ctypes_check(PyTypeObject *obj)
2222
int ret;
2323

2424
npy_cache_import("numpy._core._internal", "npy_ctypes_check",
25-
&npy_ma_thread_unsafe_state.npy_ctypes_check);
26-
if (npy_ma_thread_unsafe_state.npy_ctypes_check == NULL) {
25+
&npy_thread_unsafe_state.npy_ctypes_check);
26+
if (npy_thread_unsafe_state.npy_ctypes_check == NULL) {
2727
goto fail;
2828
}
2929

30-
ret_obj = PyObject_CallFunctionObjArgs(npy_ma_thread_unsafe_state.npy_ctypes_check,
30+
ret_obj = PyObject_CallFunctionObjArgs(npy_thread_unsafe_state.npy_ctypes_check,
3131
(PyObject *)obj, NULL);
3232
if (ret_obj == NULL) {
3333
goto fail;

numpy/_core/src/common/ufunc_override.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ PyUFuncOverride_GetNonDefaultArrayUfunc(PyObject *obj)
4343
return NULL;
4444
}
4545
/* Ignore if the same as ndarray.__array_ufunc__ */
46-
if (cls_array_ufunc == npy_ma_static_data.ndarray_array_ufunc) {
46+
if (cls_array_ufunc == npy_static_pydata.ndarray_array_ufunc) {
4747
Py_DECREF(cls_array_ufunc);
4848
return NULL;
4949
}

numpy/_core/src/multiarray/alloc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ NPY_NO_EXPORT PyObject *
4848
_get_madvise_hugepage(PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args))
4949
{
5050
#ifdef NPY_OS_LINUX
51-
if (npy_ma_thread_unsafe_state.madvise_hugepage) {
51+
if (npy_thread_unsafe_state.madvise_hugepage) {
5252
Py_RETURN_TRUE;
5353
}
5454
#endif
@@ -66,12 +66,12 @@ _get_madvise_hugepage(PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args))
6666
NPY_NO_EXPORT PyObject *
6767
_set_madvise_hugepage(PyObject *NPY_UNUSED(self), PyObject *enabled_obj)
6868
{
69-
int was_enabled = npy_ma_thread_unsafe_state.madvise_hugepage;
69+
int was_enabled = npy_thread_unsafe_state.madvise_hugepage;
7070
int enabled = PyObject_IsTrue(enabled_obj);
7171
if (enabled < 0) {
7272
return NULL;
7373
}
74-
npy_ma_thread_unsafe_state.madvise_hugepage = enabled;
74+
npy_thread_unsafe_state.madvise_hugepage = enabled;
7575
if (was_enabled) {
7676
Py_RETURN_TRUE;
7777
}
@@ -110,7 +110,7 @@ _npy_alloc_cache(npy_uintp nelem, npy_uintp esz, npy_uint msz,
110110
#ifdef NPY_OS_LINUX
111111
/* allow kernel allocating huge pages for large arrays */
112112
if (NPY_UNLIKELY(nelem * esz >= ((1u<<22u))) &&
113-
npy_ma_thread_unsafe_state.madvise_hugepage) {
113+
npy_thread_unsafe_state.madvise_hugepage) {
114114
npy_uintp offset = 4096u - (npy_uintp)p % (4096u);
115115
npy_uintp length = nelem * esz - offset;
116116
/**

numpy/_core/src/multiarray/array_converter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ static int
186186
pyscalar_mode_conv(PyObject *obj, scalar_policy *policy)
187187
{
188188
PyObject *strings[3] = {
189-
npy_ma_str.convert, npy_ma_str.preserve,
190-
npy_ma_str.convert_if_no_array};
189+
npy_interned_str.convert, npy_interned_str.preserve,
190+
npy_interned_str.convert_if_no_array};
191191

192192
/* First quick pass using the identity (should practically always match) */
193193
for (int i = 0; i < 3; i++) {

numpy/_core/src/multiarray/arrayfunction_override.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ get_array_function(PyObject *obj)
2020
{
2121
/* Fast return for ndarray */
2222
if (PyArray_CheckExact(obj)) {
23-
Py_INCREF(npy_ma_static_data.ndarray_array_function);
24-
return npy_ma_static_data.ndarray_array_function;
23+
Py_INCREF(npy_static_pydata.ndarray_array_function);
24+
return npy_static_pydata.ndarray_array_function;
2525
}
2626

27-
PyObject *array_function = PyArray_LookupSpecial(obj, npy_ma_str.array_function);
27+
PyObject *array_function = PyArray_LookupSpecial(obj, npy_interned_str.array_function);
2828
if (array_function == NULL && PyErr_Occurred()) {
2929
PyErr_Clear(); /* TODO[gh-14801]: propagate crashes during attribute access? */
3030
}
@@ -125,7 +125,7 @@ get_implementing_args_and_methods(PyObject *relevant_args,
125125
static int
126126
is_default_array_function(PyObject *obj)
127127
{
128-
return obj == npy_ma_static_data.ndarray_array_function;
128+
return obj == npy_static_pydata.ndarray_array_function;
129129
}
130130

131131

@@ -153,7 +153,7 @@ array_function_method_impl(PyObject *func, PyObject *types, PyObject *args,
153153
}
154154
}
155155

156-
PyObject *implementation = PyObject_GetAttr(func, npy_ma_str.implementation);
156+
PyObject *implementation = PyObject_GetAttr(func, npy_interned_str.implementation);
157157
if (implementation == NULL) {
158158
return NULL;
159159
}
@@ -233,10 +233,10 @@ set_no_matching_types_error(PyObject *public_api, PyObject *types)
233233
/* No acceptable override found, raise TypeError. */
234234
npy_cache_import("numpy._core._internal",
235235
"array_function_errmsg_formatter",
236-
&npy_ma_thread_unsafe_state.array_function_errmsg_formatter);
237-
if (npy_ma_thread_unsafe_state.array_function_errmsg_formatter != NULL) {
236+
&npy_thread_unsafe_state.array_function_errmsg_formatter);
237+
if (npy_thread_unsafe_state.array_function_errmsg_formatter != NULL) {
238238
PyObject *errmsg = PyObject_CallFunctionObjArgs(
239-
npy_ma_thread_unsafe_state.array_function_errmsg_formatter,
239+
npy_thread_unsafe_state.array_function_errmsg_formatter,
240240
public_api, types, NULL);
241241
if (errmsg != NULL) {
242242
PyErr_SetObject(PyExc_TypeError, errmsg);
@@ -299,12 +299,12 @@ array_implement_c_array_function_creation(
299299
}
300300

301301
/* The like argument must be present in the keyword arguments, remove it */
302-
if (PyDict_DelItem(kwargs, npy_ma_str.like) < 0) {
302+
if (PyDict_DelItem(kwargs, npy_interned_str.like) < 0) {
303303
goto finish;
304304
}
305305

306306
/* Fetch the actual symbol (the long way right now) */
307-
numpy_module = PyImport_Import(npy_ma_str.numpy);
307+
numpy_module = PyImport_Import(npy_interned_str.numpy);
308308
if (numpy_module == NULL) {
309309
goto finish;
310310
}

numpy/_core/src/multiarray/arrayobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)
928928
if (result == NULL
929929
&& (cmp_op == Py_EQ || cmp_op == Py_NE)
930930
&& PyErr_ExceptionMatches(
931-
npy_ma_static_data._UFuncNoLoopError)) {
931+
npy_static_pydata._UFuncNoLoopError)) {
932932
PyErr_Clear();
933933

934934
PyArrayObject *array_other = (PyArrayObject *)PyArray_FROM_O(other);

numpy/_core/src/multiarray/arraytypes.c.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4185,7 +4185,7 @@ NPY_NO_EXPORT _PyArray_LegacyDescr @from@_Descr = {
41854185

41864186
/* The smallest type number is ?, the largest bounded by 'z'. */
41874187
#define _MAX_LETTER ('z' + 1)
4188-
#define LETTER_TO_NUM(letter) npy_ma_static_data._letter_to_num[letter - '?']
4188+
#define LETTER_TO_NUM(letter) npy_static_cdata._letter_to_num[letter - '?']
41894189

41904190
static _PyArray_LegacyDescr *_builtin_descrs[] = {
41914191
&BOOL_Descr,

numpy/_core/src/multiarray/arraywrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ npy_find_array_wrap(
5757
}
5858
}
5959
else {
60-
PyObject *new_wrap = PyArray_LookupSpecial_OnInstance(obj, npy_ma_str.array_wrap);
60+
PyObject *new_wrap = PyArray_LookupSpecial_OnInstance(obj, npy_interned_str.array_wrap);
6161
if (new_wrap == NULL) {
6262
if (PyErr_Occurred()) {
6363
goto fail;
@@ -160,7 +160,7 @@ npy_apply_wrap(
160160
else {
161161
/* Replace passed wrap/wrap_type (borrowed refs) with new_wrap/type. */
162162
new_wrap = PyArray_LookupSpecial_OnInstance(
163-
original_out, npy_ma_str.array_wrap);
163+
original_out, npy_interned_str.array_wrap);
164164
if (new_wrap != NULL) {
165165
wrap = new_wrap;
166166
wrap_type = (PyObject *)Py_TYPE(original_out);

numpy/_core/src/multiarray/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ check_and_adjust_axis_msg(int *axis, int ndim, PyObject *msg_prefix)
142142
if (NPY_UNLIKELY((*axis < -ndim) || (*axis >= ndim))) {
143143
/* Invoke the AxisError constructor */
144144
PyObject *exc = PyObject_CallFunction(
145-
npy_ma_static_data.AxisError, "iiO", *axis, ndim,
145+
npy_static_pydata.AxisError, "iiO", *axis, ndim,
146146
msg_prefix);
147147
if (exc == NULL) {
148148
return -1;
149149
}
150-
PyErr_SetObject(npy_ma_static_data.AxisError, exc);
150+
PyErr_SetObject(npy_static_pydata.AxisError, exc);
151151
Py_DECREF(exc);
152152

153153
return -1;

0 commit comments

Comments
 (0)