[SciPy-dev] Inclusion of cython code in scipy

Brian Granger ellisonbg.net at gmail.com
Thu Apr 24 11:44:49 EDT 2008


> Then why not start a project to get SWIG to do away with the shadow module?

I don't have a passion for actually working seriously on these
projects - I am lazy and simply want to use them :)

>  Lets take a simple case of someone wanting to handle a growing
>  collection of say a million particles and do something to them.  How do
>  you do that in cython/pyrex and get the performance of C and interface
>  to numpy?  Worse, even if it were possible, you'll still need to know
>  something about allocating memory in C and manipulating pointers.  I can
>  do that with C++ and SWIG today.

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.

Sure SWIG can do this too.  If you don't mind the extra pure python
layer that SWIG has, then it is really a matter of personal preference
and experience.  But, if performance is really important and you don't
want the extra python layer, SWIG doesn't cut it.  The one place where
Cython does not do well with C++ code currently is if you have a very
large C++ API (100s of classes).  Then SWIG is the way to go.


>  cheers,
>  prabhu
>
>
> _______________________________________________
>  Scipy-dev mailing list
>  Scipy-dev at scipy.org
>  http://projects.scipy.org/mailman/listinfo/scipy-dev
>



More information about the SciPy-Dev mailing list