I have a cdef function that has amongst its parameters a function. I am trying to generate a python 'wrapper' function that will call it. I know that defining a function as cpdef() I would be able to get access to a python version of the function. However, if I do this, I will get an error (as expected) that says that python cannot recognize the function definition I provided.
Any suggestions?
My original function is domain specific and quite long but I think that the following example captures what I am after. I would have the following cdef() function defined,
ctypedef double (*ftype) (double)
cdef cy_myfunc(int a,..., double x, ftype f):
...
cdef double result
result = f(x)
return result
and I would like to define something like the following so that I can call it in python:
def py_myfunc(a,..., x, f):
return cy_myfunc(a,...,x,f)
If you actually need to this (might think about refactoring so you don't) - you need some kind of
PyObject
to store the c function pointer.The
PyCapsule
api provides a way of passing opaque pointers around in python space. Could do something like this, I'm probably missing some safety checksUsage