> Could anyone give me a tip on how to convert a python function > of the form > > def func(x): > return some_operation(x) > > to a C function of the form > > cdef void cfunc(double x, double *y): > y = some_operation(x)
y[0] = some_operation(x) > > That is I want to be able to turn a python function into > a C function with pass by reference return semantics. > > I looked at the cheesefinder example, and I am not sure how to adapt it, > as I > want to be able to have the user supply the python function, and I can't > think > of how to make a cdef callback function that knows what this function is, > that > is > > cdef void callback(souble x, double *y): > y = func(x) > > I am not sure how to set func in this way, without rewriting the cdef each > time. In python I would just use a higher order function . . . in general, you need an extra "void *" argument in the callback function (which you would use to pass a python callable). Well designed C libraries use this convention, but it sounds like you don't have this. > > Thanks, > Gabriel > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev > Simon. _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
