[SciPy-dev] Inclusion of cython code in scipy

Stéfan van der Walt stefan@sun.ac...
Wed Apr 23 12:11:10 CDT 2008

2008/4/23 Nathan Bell <wnbell@gmail.com>:
>  I don't see how writing Cython is easier than writing C/C++/Fortran.
>  Clearly if you only know Python, then Cython is an easier language to
>  learn.  However, I doubt the Cython abstraction is so complete that
>  one can avoid learning C.

For one, memory management.  Teaching someone to use the Python C API
properly is a pain, which is why we often revert to tools like SWIG
and Ctypes.

Look at ndimage, or the numpy core -- why do so few people dare touch
it?  That code is hard to wrap your head around.

If C code has a well designed API (in other words, if it is being used
like FORTRAN), then sure -- it is easy to wrap in almost any language.
 The moment you start to implement anything more advanced than bit
twiddling in pre-allocated memory, you're in for a long haul.

>  Clearly I think SciPy has a long life ahead of it.  At the same time,
>  I spent effort ensuring that sparsetools knows absolutely nothing
>  about NumPy/SciPy.  IMO the utility of a stand-alone library is
>  greater than a tighter coupling between sparsetools and Python.  For
>  instance, I can now combine the C++ I've written for PyAMG with
>  sparsetools to make a lightweight algebraic multigrid code in pure
>  C++.

I think you made the right decision for your specific application, but
I don't think that is necessarily the route all our packages should
take.  Besides, most of the code we write is in Python, and cannot be
used in non-Python libraries anyway.


More information about the Scipy-dev mailing list