Skip to content

Commit

Permalink
Numpy 2 compat: replace uses of NPY_MAXARGS with a compile time constant
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Mar 3, 2024
1 parent c498084 commit 5988106
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions erfa/ufunc.c.templ
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,12 @@ static int ErfaUFuncTypeResolver(PyUFuncObject *ufunc,
{
int *types;
PyArray_Descr **dtypes;
int types_array[NPY_MAXARGS];

/* NPY_MAXARGS is runtime dependent in Numpy 2.0,
so it cannot be used as an array size. Replacing it with a compile-time
constant set to its current maximal value (32 in numpy 1.x, 64 in numpy 2.0) */
assert( NPY_MAXARGS <= 64 );
int types_array[64];

if (ufunc->userloops) {
Py_ssize_t unused_pos = 0;
Expand Down Expand Up @@ -752,7 +757,12 @@ PyMODINIT_FUNC PyInit_ufunc(void)
PyArray_Descr *dt_ymdf = NULL, *dt_hmsf = NULL, *dt_dmsf = NULL;
PyArray_Descr *dt_sign = NULL, *dt_type = NULL;
PyArray_Descr *dt_eraASTROM = NULL, *dt_eraLDBODY = NULL;
PyArray_Descr *dtypes[NPY_MAXARGS];

/* NPY_MAXARGS is runtime dependent in Numpy 2.0,
so it cannot be used as an array size. Replacing it with a compile-time
constant set to its current maximal value (32 in numpy 1.x, 64 in numpy 2.0) */
assert( NPY_MAXARGS <= 64 );
PyArray_Descr *dtypes[64];
/* ufuncs and their definitions */
int status;
PyUFuncObject *ufunc;
Expand Down

0 comments on commit 5988106

Please sign in to comment.