8000 Merge pull request #25315 from ngoldbaum/expose-add-ufunc-from-spec · numpy/numpy@bcb3463 · GitHub
[go: up one dir, main page]

Skip to content

Commit bcb3463

Browse files
authored
Merge pull request #25315 from ngoldbaum/expose-add-ufunc-from-spec
MAINT: expose PyUFunc_AddPromoter in the internal ufunc API
2 parents 82ba4f4 + c914720 commit bcb3463

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

numpy/_core/src/multiarray/experimental_public_dtype_api.c

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "common_dtype.h"
1717
#include "umathmodule.h"
1818
#include "abstractdtypes.h"
19+
#include "dispatching.h"
1920

2021
int
2122
PyArrayInitDTypeMeta_FromSpec(
@@ -115,9 +116,6 @@ PyArrayInitDTypeMeta_FromSpec(
115116
NPY_NO_EXPORT int
116117
PyUFunc_AddLoop(PyUFuncObject *ufunc, PyObject *info, int ignore_duplicate);
117118

118-
NPY_NO_EXPORT int
119-
PyUFunc_AddLoopFromSpec(PyUFuncObject *ufunc, PyObject *info, int ignore_duplicate);
120-
121119

122120
/*
123121
* Function is defined in umath/wrapping_array_method.c
@@ -130,31 +128,6 @@ PyUFunc_AddWrappingLoop(PyObject *ufunc_obj,
130128
translate_loop_descrs_func *translate_loop_descrs);
131129

132130

133-
static int
134-
PyUFunc_AddPromoter(
135-
PyObject *ufunc, PyObject *DType_tuple, PyObject *promoter)
136-
{
137-
if (!PyObject_TypeCheck(ufunc, &PyUFunc_Type)) {
138-
PyErr_SetString(PyExc_TypeError,
139-
"ufunc object passed is not a ufunc!");
140-
return -1;
141-
}
142-
if (!PyCapsule_CheckExact(promoter)) {
143-
PyErr_SetString(PyExc_TypeError,
144-
"promoter must (currently) be a PyCapsule.");
145-
return -1;
146-
}
147-
if (PyCapsule_GetPointer(promoter, "numpy._ufunc_promoter") == NULL) {
148-
return -1;
149-
}
150-
PyObject *info = PyTuple_Pack(2, DType_tuple, promoter);
151-
if (info == NULL) {
152-
return -1;
153-
}
154-
return PyUFunc_AddLoop((PyUFuncObject *)ufunc, info, 0);
155-
}
156-
157-
158131
/*
159132
* Lightweight function fetch a default instance of a DType class.
160133
* Note that this version is named `_PyArray_GetDefaultDescr` with an

numpy/_core/src/umath/dispatching.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,3 +1291,27 @@ get_info_no_cast(PyUFuncObject *ufunc, PyArray_DTypeMeta *op_dtype,
12911291
Py_DECREF(t_dtypes);
12921292
Py_RETURN_NONE;
12931293
}
1294+
1295+
NPY_NO_EXPORT int
1296+
PyUFunc_AddPromoter(
1297+
PyObject *ufunc, PyObject *DType_tuple, PyObject *promoter)
1298+
{
1299+
if (!PyObject_TypeCheck(ufunc, &PyUFunc_Type)) {
1300+
PyErr_SetString(PyExc_TypeError,
1301+
"ufunc object passed is not a ufunc!");
1302+
return -1;
1303+
}
1304+
if (!PyCapsule_CheckExact(promoter)) {
1305+
PyErr_SetString(PyExc_TypeError,
1306+
"promoter must (currently) be a PyCapsule.");
1307+
return -1;
1308+
}
1309+
if (PyCapsule_GetPointer(promoter, "numpy._ufunc_promoter") == NULL) {
1310+
return -1;
1311+
}
1312+
PyObject *info = PyTuple_Pack(2, DType_tuple, promoter);
1313+
if (info == NULL) {
1314+
return -1;
1315+
}
1316+
return PyUFunc_AddLoop((PyUFuncObject *)ufunc, info, 0);
1317+
}

numpy/_core/src/umath/dispatching.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ object_only_ufunc_promoter(PyUFuncObject *ufunc,
5151
NPY_NO_EXPORT int
5252
install_logical_ufunc_promoter(PyObject *ufunc);
5353

54+
NPY_NO_EXPORT int
55+
PyUFunc_AddPromoter(
56+
PyObject *ufunc, PyObject *DType_tuple, PyObject *promoter);
57+
58+
5459
#ifdef __cplusplus
5560
}
5661
#endif

0 commit comments

Comments
 (0)
0