You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 25, 2022. It is now read-only.
2. In the 'initrational' function used to initialize the Rational dtype with numpy,
296
+
a new PyUFuncObject is created for the new 'matrix_multiply' generalized ufunc using the
297
+
PyUFunc_FromFuncAndDataAndSignature function:
298
+
299
+
PyObject* gufunc = PyUFunc_FromFuncAndDataAndSignature(0,0,0,0,2,1,PyUFunc_None,(char*)"matrix_multiply",(char*)"return result of multiplying two matrices of rationals",0,"(m,n),(n,p)->(m,p)");
300
+
301
+
This is identical to the PyUFunc_FromFuncAndData function used to create a ufunc object in the examples above,
302
+
with the addition of a ufunc signature describing the core dimensions of the input and output arrays. In this example,
303
+
the generalized ufunc operates on pairs of matrices with dimensions (m,n) and (n,p), producing an
304
+
output matrix of dimensions (m,p).
305
+
306
+
3. The loop function is registered using the loop function and the PyUFuncObject created in step 2:
307
+
308
+
int types2[3] = {npy_rational,npy_rational,npy_rational};
309
+
if (PyUFunc_RegisterLoopForType((PyUFuncObject*)gufunc,npy_rational,rational_gufunc_matrix_multiply,types2,0) < 0) {
310
+
return;
311
+
}
312
+
313
+
4. Finally, a function called 'matrix_multiply' is added to the rational module which
PyObject*gufunc=PyUFunc_FromFuncAndDataAndSignature(0,0,0,0,2,1,PyUFunc_None,(char*)"matrix_multiply",(char*)"return result of multiplying two matrices of rationals",0,"(m,n),(n,p)->(m,p)");
0 commit comments