[SciPy-dev] Inclusion of cython code in scipy
Prabhu Ramachandran
prabhu at aero.iitb.ac.in
Thu Apr 24 12:38:03 EDT 2008
Brian Granger wrote:
>> > C++ STL containers are truly great for things like this. I would
>> > write a simple c++ header file that defines the Particle class, create
>> > an std::vector<Particle> to hold them and wrap the whole thing into
>> > Cython. I have already done stuff like this (templated c++ with STL)
>> > with cython and it works great. Furthermore, you end up with an
>> > actual C/Python extension type that 1) is super fast 2) has its own C
>> > api that can be called from other C extensions.
For some strange reason I still haven't gotten this email but Brian,
that is the point I was making, STL has all the needed container classes
for this and this is precisely what I use. I just use SWIG to wrap this
C++ code and it works great. Much of the STL is already wrapped via
SWIG and with numpy.i it interfaces quite well with numpy, in addition
you can inject doxygen generated documentation almost automatically so
your generated wrapper code is fully documented.
I've also explored using D and PyD and it makes for a fantastic
combination. D seems to be (gdc) about 1.7 times slower than C++ but is
really nice to work with. PyD's support for numpy is lacking but could
be fixed.
The point is (and what I understand of what Nathan was saying), pyrex
and cython let you wrap the code to an extent but do not provide the
underlying solution. People were arging that Cython may be used in
place of C, and I think our point is that it isn't there yet and for
people used to C or C++ it is much easier to just use those instead.
> Unfortunately, the context I have done this in is proprietary code for
> my employer. But, I will try to put together a simple example this
> weekend and post it to launchpad. The documentation on these
> capabilities of Cython isn't great right now for sure, so some example
> code would sure help.
So why don't we do this together. I'll put together my tiny example of
a shootout with Python C++ and D and lets see how they stack up. If you
would be so kind you can add the cython/pyrex parts to this. Thanks.
cheers,
prabhu
More information about the SciPy-Dev
mailing list