[OT] pass a C callback function to a cythom module via python

Nadav Horesh nadavh.horesh at gmail.com
Sun Apr 1 09:42:52 EDT 2012


A nice idea. As is, it can not replace the link to C code linking because
it contains to much yellow lines ("cython -a" output) in the main loop, so
there is a speed penalty, and also I suspect it wouldn't be possible to
parallelise that function call. Anyway I plan to add this option.

  About ctypes: I am not a ctypes fond either, neither I think that my use
is elegant or very portable. The ctypes is used for one purpose: load a
shared library and provide a pointer to an object within that library. It
seems to be that it is inevitable that there is a simpler way to to that,
but I am clueless.

  Nadav.

בתאריך 28 במרץ 2012 00:03, מאת Stéfan van der Walt <stefan at sun.ac.za>:
>
>> Hi Nadav
>>
>> I just had a chat with Dag, a core Cython contributor.  He mentioned
>> to me another alternative, which is to encapsulate the callback
>> function in a class:
>>
>>
>> https://github.com/dagss/cython-pydata12/blob/master/examples/oointegrate/integrate.pyx
>>
>> You can import this class from Python, and pass it along as the
>> callback object.  There may be some work on improving this
>> functionality in the future, but for now I think that's the cleanest
>> route (and helps us to avoid ctypes!).
>>
>> Stéfan
>>
>>
>> On Tue, Mar 20, 2012 at 1:02 AM, Nadav Horesh <nadavh.horesh at gmail.com>
>> wrote:
>> >
>> > Can you explain in more details how can I implement it? Any case I am
>> > attaching an scheme that may clarify my intend. Soon I'll post a code
>> > demonstrating the problem.
>> >
>> >   Thank you,
>> >      Nadav,
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20120401/12f4975f/attachment.html>


More information about the scikit-image mailing list