On Oct 16, 2008, at 10:12 AM, Ondrej Certik wrote:

> Hi,
>
> I want to use scipy's quadrature like this:
>
> val, err = quadrature(func2, a, b, args=(f,))
>
> where func2 is my Cython function and "f" is a C function pointer,
> that will get executed from func2. The problem is, that "f" is passed
> to the Python quadrature function, so it needs to be wrapped.
> Currently what I do is:
>
>
> cdef class MyFunc:
>     cdef f2 thisptr
>
>     cdef set_f(MyFunc self, f2 f):
>         self.thisptr = f
>
>     cdef f2 get_f(MyFunc self):
>         return self.thisptr
>
>
> cdef MyFunc mf = MyFunc()
> mf.set_f(f)
> val, err = quadrature(func2, a, b, args=(mf,))
>
> Where func2 is:
>
> def func2(a, MyFunc mf):
>     cdef f2 f = mf.get_f()
>     return array([f(x) for x in a])
>
> This works nice. Is this the way to do it? Or is there some
> better/simpler way. I don't know if it's a good idea to make Cython
> clever enough to wrap things like this automatically?

If I understand right, you want an automatic python wrapper of a C  
function. Perhaps it could be done, as long as the arguments and  
return type could all be converted, but it's certainly not  
implemented currently and easily enough done by the code you have above.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to