I am numerically integrating some ODE's, e.g.
y'(t) = f(y(t), t) This is easily done using for instance scipy's integrate.ode. The function f is defined using standard Python, e.g.:
def f(y, t, k): return -k*y**3 My understand is that this means that the fortran/C implementation used by integrate.ode must do call-backs to Python all the time and this can be quite slow. My question is whether there is a way to avoid this?
Preferably I am looking for a package that lets me inline in my Python code a C-snippet, e.g.:
double f(double y, double t, double k) { return -k*pow(y,3); } Is there any ODE integrator library for Python that allows this?
I know there are packages like scipy.weave that could be used to inline C code in Python, but I can't see an easy way to interface with integrate.ode. In all cases I think interfacing will have to go through a Python function call.
Inline C-code like this exist in other libraries such as fenics, where Expression allow jit compiled C code.
scipy.ode. I've not actually used it myself though so can't easily provide a useful working example...funcin the documentation).