Now that I have my user-defined type, I want to add some funcs. According to the numpy book, I need to use: PyUFunc_RegisterLoopForType The book says I first need a ufunc. The only way I see to create one is PyUFunc_FromFuncAndData. Is the the correct procedure? I wonder, because PyUFunc_FromFuncAndData requires 'type', and 'type' is char, but user-defined types start at 256, which doesn't fit in a char, which gives a compile warning.
Neal Becker wrote:
Now that I have my user-defined type, I want to add some funcs. According to the numpy book, I need to use:
PyUFunc_RegisterLoopForType
The book says I first need a ufunc. The only way I see to create one is
PyUFunc_FromFuncAndData.
Is the the correct procedure?
You'll have to do some digging because the API allowing low-level loops for user-defined types is not well tested or vetted. Also, don't be surprised if you uncover some bugs. The concept is that you create the UFunc with the "built-in" types using PyUFunc_FromFuncAndData and then you add loops for the user-defined type using RegisterLoopForType. So, you have the basic procedure down. -Travis
Travis E. Oliphant wrote:
Neal Becker wrote:
Now that I have my user-defined type, I want to add some funcs. According to the numpy book, I need to use:
PyUFunc_RegisterLoopForType
The book says I first need a ufunc. The only way I see to create one is
PyUFunc_FromFuncAndData.
Is the the correct procedure?
You'll have to do some digging because the API allowing low-level loops for user-defined types is not well tested or vetted. Also, don't be surprised if you uncover some bugs.
The concept is that you create the UFunc with the "built-in" types using PyUFunc_FromFuncAndData and then you add loops for the user-defined type using RegisterLoopForType.
So, you have the basic procedure down.
-Travis
It looks like this works. Basically, the only thing used from
the ufunc obj is: name, nin, nout, nargs, and ntypes.
// Make a generic new ufunc obj
static PyUFuncObject * new_ufunc (char* name) {
PyUFuncObject * u = PyObject_New (PyUFuncObject, &PyUFunc_Type);
u->nin = 0;
u->nout = 0;
u->nargs = 0;
u->identity = 0;
u->functions = 0;
u->data = 0;
u->types = 0;
u->ntypes = 0;
u->check_return = 0;
u->ptr = NULL;
u->obj = NULL;
u->userloops=NULL;
u->name = name;
u->doc = "NULL";
return u;
}
//fill in required fields
PyUFuncObject * u = new_ufunc ("magsqr");
u->nin = 1;
u->nout = 1;
u->nargs = 2;
u->ntypes = 1;
{
int types[] = {d1->type_num, NPY_INT32};
register_unary_loop_func (u, d1->type_num, types, mag_sqr_impl
participants (2)
-
Neal Becker
-
Travis E. Oliphant