On Apr 6, 2008, at 10:57 PM, Gabriel Gellner wrote:
> Looking through the scipy odeint C wrapper, I realized the simple  
> pattern to
> solve this (just having the callback call a global python function,  
> that is
> set by the driver.)
>
> Does anyone think this is worth making a Wiki page for? If so I  
> would be happy
> to write up the solution.

Yes, certainly. Thanks.

>
> Gabriel
>
> On Sat, Apr 05, 2008 at 12:58:21PM -0400, [EMAIL PROTECTED] wrote:
>>> Could anyone give me a tip on how to convert a python function
>>> of the form
>>>
>>> def func(x):
>>>     return some_operation(x)
>>>
>>> to a C function of the form
>>>
>>> cdef void cfunc(double x, double *y):
>>>     y = some_operation(x)
>>
>> y[0] = some_operation(x)
>>
>>>
>>> That is I want to be able to turn a python function into
>>> a C function with pass by reference return semantics.
>>>
>>> I looked at the cheesefinder example, and I am not sure how to  
>>> adapt it,
>>> as I
>>> want to be able to have the user supply the python function, and  
>>> I can't
>>> think
>>> of how to make a cdef callback function that knows what this  
>>> function is,
>>> that
>>> is
>>>
>>> cdef void callback(souble x, double *y):
>>>     y = func(x)
>>>
>>> I am not sure how to set func in this way, without rewriting the  
>>> cdef each
>>> time. In python I would just use a higher order function . . .
>>
>> in general, you need an extra "void *" argument in the callback
>> function (which you would use to pass a python callable).
>> Well designed C libraries use this convention, but it
>> sounds like you don't have this.
>>
>>>
>>> Thanks,
>>> Gabriel
>>> _______________________________________________
>>> Cython-dev mailing list
>>> [email protected]
>>> http://codespeak.net/mailman/listinfo/cython-dev
>>>
>>
>> Simon.
>>
>> _______________________________________________
>> Cython-dev mailing list
>> [email protected]
>> http://codespeak.net/mailman/listinfo/cython-dev
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev

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

Reply via email to