static void addUfuncs(PyObject *dictionary) { PyObject *f; f = PyUFunc_FromFuncAndDataAndSignature(inner1d_functions, inner1d_data, inner1d_signatures, 2, 2, 1, PyUFunc_None, "inner1d", "inner on the last dimension and broadcast on the rest \n"\ " \"(i),(i)->()\" \n", 0, inner1d_signature); PyDict_SetItemString(dictionary, "inner1d", f); Py_DECREF(f); f = PyUFunc_FromFuncAndDataAndSignature(innerwt_functions, innerwt_data, innerwt_signatures, 2, 3, 1, PyUFunc_None, "innerwt", "inner1d with a weight argument \n"\ " \"(i),(i),(i)->()\" \n", 0, innerwt_signature); PyDict_SetItemString(dictionary, "innerwt", f); Py_DECREF(f); f = PyUFunc_FromFuncAndDataAndSignature(matrix_multiply_functions, matrix_multiply_data, matrix_multiply_signatures, 3, 2, 1, PyUFunc_None, "matrix_multiply", "matrix multiplication on last two dimensions \n"\ " \"(m,n),(n,p)->(m,p)\" \n", 0, matrix_multiply_signature); PyDict_SetItemString(dictionary, "matrix_multiply", f); Py_DECREF(f); }
static PyObject * UMath_Tests_test_signature(PyObject *NPY_UNUSED(dummy), PyObject *args) { int nin, nout; PyObject *signature, *sig_str; PyObject *f; int core_enabled; if (!PyArg_ParseTuple(args, "iiO", &nin, &nout, &signature)) return NULL; if (PyString_Check(signature)) { sig_str = signature; } else if (PyUnicode_Check(signature)) { sig_str = PyUnicode_AsUTF8String(signature); } else { PyErr_SetString(PyExc_ValueError, "signature should be a string"); return NULL; } f = PyUFunc_FromFuncAndDataAndSignature(NULL, NULL, NULL, 0, nin, nout, PyUFunc_None, "no name", "doc:none", 1, PyString_AS_STRING(sig_str)); if (sig_str != signature) { Py_DECREF(sig_str); } if (f == NULL) return NULL; core_enabled = ((PyUFuncObject*)f)->core_enabled; Py_DECREF(f); return Py_BuildValue("i", core_enabled); }
/* Duplicate for FromFuncAndDataAndSignature Need to refactor to reduce code duplication. */ static PyObject * PyDynUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void **data, char *types, int ntypes, int nin, int nout, int identity, char *name, char *doc, char *signature, PyObject *object) { PyUFuncObject *ufunc = NULL; PyObject *result; ufunc = (PyUFuncObject *) PyUFunc_FromFuncAndDataAndSignature( func, data, types, ntypes, nin, nout, identity, name, doc, 0, signature); if (!ufunc) return NULL; /* Kind of a gross-hack */ /* Py_TYPE(ufunc) = &PyDynUFunc_Type; */ /* Hold on to whatever object is passed in */ result = PyDynUFunc_New(ufunc, NULL); if (!result) goto err; /* Hold on to whatever object is passed in */ Py_XINCREF(object); ufunc->obj = object; return result; err: Py_XDECREF(ufunc); return NULL; }