Ondrej, perhaps I'm missing something, but... Why not to implement __call__ on MyFunc cdef class? IMHO, this way your code would looks much better. Moreover, it would be faster.
On Thu, Oct 16, 2008 at 2:12 PM, Ondrej Certik <[EMAIL PROTECTED]> 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? > > Ondrej > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
