[SciPy-dev] Inclusion of cython code in scipy

Bill Baxter wbaxter@gmail....
Thu Apr 24 19:35:30 CDT 2008


On Fri, Apr 25, 2008 at 1:47 AM, Neal Becker <ndbecker2@gmail.com> wrote:
>
> Prabhu Ramachandran wrote:
>
>  > 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.
>  >
>
>  Is pyd still actively developed?  Seems to be rather quiet for a while.

D!  Yay!

I don't think Kirk is doing a lot of development on it, but he's still
around in the D community.  Nice to see some other folks here keeping
an eye on D.

BUT ...  I think this thread was about alternatives for rewriting
parts of NumPy, and I have to say that writing *any* of numpy in D
seems like the wrong choice at this point.

Examples of using D with numpy on the numpy wiki would be great though.

Also,  Prabhu, I can back up your "1.7x slower than C++" assessment.
My own tests have usually come out around that ballpark too.  But I
prefer to phrase it as "560 times faster than pure Python".  :-)

--bb


More information about the Scipy-dev mailing list