[Numpy-discussion] Numpy and C++ integration...
Tue Feb 5 04:52:13 CST 2008
Gael Varoquaux wrote:
> On Tue, Feb 05, 2008 at 11:48:37AM +0100, Sebastian Haase wrote:
>> Thanks fr the reply.
>> How about "manual" overloading. I mean, if -- for example -- I have
>> two functions mmms_b and mmms_i in C, I could still use ctypes; could
>> I then "merge" them into one python function, which "re-routes"
>> depending on the argument dtype !?
> Yes, that's exactly what I do (except I rarely use C++, so I reroute to
> different C functions). It doesn't scale well, but it's OK if you have
> only a few functions to worry about.
It does not scale well if you do it manually, but I don't see any reason
why it cannot be automated. ctypes main developer, Thomas Heller, has
developed a code generator which parses C headers (which uses gcc-xml,
that is can parse anything you can throw at gcc) and gives you
ctypes-compatible code. It can be used on windows.h, which is the most
horrendous/biggest header I can think of :) When using C++, you would
need to find a way to generate C headers (needed anyway because you
cannot dynamically load C++ code and used functions with C++ linkage, at
least in a cross platform way).
I have never used the code generator in such a way (handling multiple
types), but I have used it to wrap win32 functions for sound IO, and it
works pretty well.
More information about the Numpy-discussion