* Add loop directly to a ufunc from a given ArrayMethod spec. */
| 151 | * Add loop directly to a ufunc from a given ArrayMethod spec. |
| 152 | */ |
| 153 | NPY_NO_EXPORT int |
| 154 | PyUFunc_AddLoopFromSpec(PyObject *ufunc, PyArrayMethod_Spec *spec) |
| 155 | { |
| 156 | if (!PyObject_TypeCheck(ufunc, &PyUFunc_Type)) { |
| 157 | PyErr_SetString(PyExc_TypeError, |
| 158 | "ufunc object passed is not a ufunc!"); |
| 159 | return -1; |
| 160 | } |
| 161 | PyBoundArrayMethodObject *bmeth = |
| 162 | (PyBoundArrayMethodObject *)PyArrayMethod_FromSpec(spec); |
| 163 | if (bmeth == NULL) { |
| 164 | return -1; |
| 165 | } |
| 166 | int nargs = bmeth->method->nin + bmeth->method->nout; |
| 167 | PyObject *dtypes = PyArray_TupleFromItems( |
| 168 | nargs, (PyObject **)bmeth->dtypes, 1); |
| 169 | if (dtypes == NULL) { |
| 170 | return -1; |
| 171 | } |
| 172 | PyObject *info = PyTuple_Pack(2, dtypes, bmeth->method); |
| 173 | Py_DECREF(bmeth); |
| 174 | Py_DECREF(dtypes); |
| 175 | if (info == NULL) { |
| 176 | return -1; |
| 177 | } |
| 178 | return PyUFunc_AddLoop((PyUFuncObject *)ufunc, info, 0); |
| 179 | } |
| 180 | |
| 181 | |
| 182 | /** |
no test coverage detected