Gabriel Gellner | 1 Mar 2008 21:20
Picon
Favicon

ctypes callbacks, changing signature

I am wrapping some ode solvers using ctypes. And I have run into, what I
imagine is, a common problem.

The expected C callback is of the form

void func(int n, double t, double* y, double* yprime);

which I can wrap fine using ctypes. But I would like to be able to use a
python (or f2py generated) function of the normal form

def func(t, y):
    # some callculations
    return yprime

# instead of
def func(n, t, y, prime):
    return None

My question is what do people usually do in this case? Any tips suggestions,
examples.

Thanks a bunch.

Gabriel
Robert Kern | 1 Mar 2008 21:26
Picon
Gravatar

Re: ctypes callbacks, changing signature

On Sat, Mar 1, 2008 at 2:20 PM, Gabriel Gellner <ggellner <at> uoguelph.ca> wrote:
> I am wrapping some ode solvers using ctypes. And I have run into, what I
>  imagine is, a common problem.
>
>  The expected C callback is of the form
>
>  void func(int n, double t, double* y, double* yprime);
>
>  which I can wrap fine using ctypes. But I would like to be able to use a
>  python (or f2py generated) function of the normal form
>
>  def func(t, y):
>     # some callculations
>     return yprime
>
>  # instead of
>  def func(n, t, y, prime):
>     return None
>
>  My question is what do people usually do in this case? Any tips suggestions,
>  examples.

Wrap it with a function of the required signature.

--

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
(Continue reading)


Gmane