Skip to content

Commit

Permalink
Fixes C API for numpy >= 2.0
Browse files Browse the repository at this point in the history
Fixes: #17
  • Loading branch information
mwallerb committed Jun 24, 2024
1 parent ec82b6c commit 3a6f9b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 5 additions & 3 deletions csrc/_dd_linalg.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,13 @@ static int import_ddouble_dtype()
if (dd_module == NULL)
return -1;

// Now, ddouble should be defined
type_num = PyArray_TypeNumFromName("ddouble");
if (type_num == NPY_NOTYPE)
PyArray_Descr *dtype =
(PyArray_Descr *)PyObject_GetAttrString(dd_module, "dtype");
if (dtype == NULL)
return -1;

/* Let's pray at least this stays public */
type_num = dtype->type_num;
return 0;
}

Expand Down
20 changes: 15 additions & 5 deletions csrc/_dd_ufunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,17 +533,27 @@ static int NPyDDouble_ArgMin(void *_data, npy_intp n, npy_intp *min_ind,
MARK_UNUSED(arr);
}

/* This is necessary in order to ensure both 1.0 and 2.0 compatibility.
* https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_RegisterDataType
*/
#if NPY_ABI_VERSION < 0x02000000
#define PyArray_DescrProto PyArray_Descr
#endif

static int make_dtype()
{
/* Check if another module has registered a ddouble type.
*
* FIXME: this check is removed, let's see if it is missed ...
*/
type_num = PyArray_TypeNumFromName("ddouble");
if (type_num != NPY_NOTYPE) {
return type_num;
}
//type_num = PyArray_TypeNumFromName("ddouble");
//if (type_num != NPY_NOTYPE) {
// return type_num;
//}

static PyArray_ArrFuncs ddouble_arrfuncs;
static PyArray_Descr ddouble_dtype = {

static PyArray_DescrProto ddouble_dtype = {
PyObject_HEAD_INIT(NULL)

/* We must register ddouble with a kind other than "f", because numpy
Expand Down

0 comments on commit 3a6f9b1

Please sign in to comment.