1

The Numpy C API contains a function PyUFunc_FromFuncAndData for creating a PyUFuncObject data structure. This function takes a char[] types argument that specifies the function's built-in argument types (int, float, etc.). But, the type number for a user-defined data type is an int, not a char. If I use the C-API to create a custom (user-defined) data type, how do I create a ufunc that operates on this data type?

1 Answer 1

1

I don't see this explained in the Numpy documentation, but there are examples around.

int my_type_num = PyArray_RegisterDataType(&my_custom_type_descr);

PyUFuncObject* ufunc = (PyUFuncObject*)PyUFunc_FromFuncAndData(
    NULL, NULL, NULL, 0, nin, nout, identity, name, doc, 0);
PyUFunc_RegisterLoopForType(ufunc, my_type_num, my_loop_func, NULL, NULL);

This was discussed relative to an older version of Numpy on the Numpy mailing list. The source code for these API functions is here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.