Ondrej Certik wrote:
> On Thu, Mar 4, 2010 at 4:05 AM, Dag Sverre Seljebotn
> <[email protected]> wrote:
>
>> Are anybody aware of a library for solving ODEs with fast callbacks to
>> Cython? The ones in SciPy require a Python callback at every step...
>>
>> My needs aren't particularily complicated.
>>
>> I'll just wrap something in C otherwise, of course (such as GSL).
>>
>
> If you do so, please post the code online. I want to see how you did
> the callbacks (so that it works both in python and cython), as I will
> need to implement the same things for our solvers. So far I just
> created a cdef function, that I register for the C callback. But it is
> not visible from Python.
>
I'll have a look at the stuff in Sage first, then try sundials if my
needs aren't met there...
As for doing the callbacks, I'd do what Sage essentially does:
cdef class DoubleFunction:
cdef double evaluate(double x):
raise NotImplementedError()
On the Python frontend side, one can trivially write a coercer object to
wrap Python callbacks if such are supplied. On the backend side, if you
need to feed it to a C library, then assuming the C library is a good
citizen and takes contexts, simply do
cdef double call_double_func(double x, void* ctx):
return (<DoubleFunction>ctx).evaluate(x)
my_c_function(&call_double_func, ....,
<void*>passed_in_DoubleFunction_instance)
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev