Hi,
This e-mail is an attempt at proposing an API to solve Numba's needs.
Attribute access
----------------
int PyUFunc_Nin(PyUFuncObject *)
Replaces ufunc->nin.
int PyUFunc_Nout(PyUFuncObject *)
Replaces ufunc->nout.
int PyUFunc_Nargs(PyUFuncObject *)
Replaces ufunc->nargs.
PyObject *PyUFunc_Name(PyUFuncObject *)
Replaces ufunc->name, returns a unicode object.
(alternative: return a const char *)
For introspection, the following would be nice too:
int PyUFunc_Identity(PyFuncObject *)
Replaces ufunc->identity.
const char *PyUFunc_Signature(PyUFuncObject *, int i)
Gives a pointer to the types of the i'th signature.
(equivalent today to &ufunc->ntypes[i * ufunc->nargs])
Lifetime control
----------------
PyObject *PyUFunc_SetObject(PyUFuncObject *, PyObject *)
Sets the ufunc's "object" to the given object. The object has no
special semantics except that it is DECREF'ed when the ufunc is
deallocated (this is today's ufunc->obj). The DECREF should happen
only after the ufunc has accessed any internal resources (since the
DECREF could deallocate some of those resources).
PyObject *PyUFunc_GetObject(PyUFuncObject *)
Return the ufunc's current "object".
Loop registration
-----------------
int PyUFunc_RegisterLoopForSignature(
PyUFuncObject* ufunc,
PyUFuncGenericFunction function, int *arg_types,
void *data, PyObject *obj)
Register a loop implementation for the given arg_types (built-in
types, presumably). This either appends the loop to the types and
functions array (reallocating it if necessary), or replaces an
existing one with the same signature.
A copy of arg_types is done, such that the caller does not have to
manage its lifetime. The optional "PyObject *obj" is an object which
gets DECREF'ed when the loop is relinquished (for example when the
ufunc is destroyed, or when the loop gets replaced with another by
calling this function again).
I cannot say I'm 100% sure this is sufficient, but this seems it should
cover our current needs.
Note this is a minimal proposal. For example, Numpy could instead decide
to pass and return all argument types as PyArray_Descr pointers rather
than raw integers, and that would probably work for us too.
Regards
Antoine.
_______________________________________________
NumPy-Discussion mailing list
[email protected]
https://mail.scipy.org/mailman/listinfo/numpy-discussion