Skip to content

Commit b17e74f

Browse files
MAINT: signal: Don't redefine PyArray_MIN macro.
When building scipy with numpy 1.26.4, the following compiler warning is generated: In file included from ../scipy/signal/_splinemodule.cc:5: ../scipy/signal/_splinemodule.h:13: warning: "PyArray_MIN" redefined 13 | #define PyArray_MIN(a, b) (((a) < (b)) ? (a) : (b)) | In file included from ../../../../../py3.12.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarrayobject.h:12, from ../../../../../py3.12.4/lib/python3.12/site-packages/numpy/core/include/numpy/arrayobject.h:5, from ../scipy/signal/_splinemodule.cc:2: ../../../../../py3.12.4/lib/python3.12/site-packages/numpy/core/include/numpy/ndarraytypes.h:964: note: this is the location of the previous definition 964 | #define PyArray_MIN(a,b) (((a)<(b))?(a):(b)) In numpy 2.0.0, PyArray_MIN is defined in numpy/npy_math.h, so it doesn't result in the redefinition problem. In numpy 1.26.4, PyArray_MIN is defined in numpy/ndarraytypes.h, which is transitively included by the include of numpy/arrayobject.h in _splinemodule.cc, resulting in the redefinition warning. We shouldn't be defining our own macros with the PyArray_ prefix anyway, so the fix here is to move the definition of the macro to _splinemodule.cc (no need for it anywhere else), and rename it to simply MIN.
1 parent 81c53d4 commit b17e74f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

scipy/signal/_splinemodule.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include "_splinemodule.h"
66

77

8+
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
9+
10+
811
static void convert_strides(npy_intp *instrides, npy_intp *convstrides, int size, int N) {
912
int n;
1013
npy_intp bitshift;
@@ -61,7 +64,7 @@ static PyObject *FIRsepsym2d(PyObject *NPY_UNUSED(dummy), PyObject *args) {
6164
return NULL;
6265

6366
thetype = PyArray_ObjectType(image, NPY_FLOAT);
64-
thetype = PyArray_MIN(thetype, NPY_CDOUBLE);
67+
thetype = MIN(thetype, NPY_CDOUBLE);
6568
a_image = (PyArrayObject *)PyArray_FromObject(image, thetype, 2, 2);
6669
if (a_image == NULL)
6770
goto fail;
@@ -180,7 +183,7 @@ static PyObject *IIRsymorder1_ic(PyObject *NPY_UNUSED(dummy), PyObject *args) {
180183
return NULL;
181184

182185
thetype = PyArray_ObjectType(sig, NPY_FLOAT);
183-
thetype = PyArray_MIN(thetype, NPY_CDOUBLE);
186+
thetype = MIN(thetype, NPY_CDOUBLE);
184187
a_sig = (PyArrayObject *)PyArray_FromObject(sig, thetype, 1, 2);
185188

186189
if (a_sig == NULL) {
@@ -316,7 +319,7 @@ static PyObject *IIRsymorder2_ic_fwd(PyObject *NPY_UNUSED(dummy), PyObject *args
316319
return NULL;
317320

318321
thetype = PyArray_ObjectType(sig, NPY_FLOAT);
319-
thetype = PyArray_MIN(thetype, NPY_DOUBLE);
322+
thetype = MIN(thetype, NPY_DOUBLE);
320323
a_sig = (PyArrayObject *)PyArray_FromObject(sig, thetype, 1, 2);
321324

322325
if (a_sig == NULL) {
@@ -432,7 +435,7 @@ static PyObject *IIRsymorder2_ic_bwd(PyObject *NPY_UNUSED(dummy), PyObject *args
432435
return NULL;
433436

434437
thetype = PyArray_ObjectType(sig, NPY_FLOAT);
435-
thetype = PyArray_MIN(thetype, NPY_DOUBLE);
438+
thetype = MIN(thetype, NPY_DOUBLE);
436439
a_sig = (PyArrayObject *)PyArray_FromObject(sig, thetype, 1, 2);
437440

438441
if (a_sig == NULL) {

scipy/signal/_splinemodule.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
PyErr_SetString(PyExc_ValueError, message); \
1111
goto fail; \
1212
} while (0)
13-
#define PyArray_MIN(a, b) (((a) < (b)) ? (a) : (b))
1413

1514

1615
/**

0 commit comments

Comments
 (0)