[SciPy-user] C extension to manipulate sparse lil matrix

Georg Holzmann grh@mur...
Fri Jan 9 02:23:33 CST 2009


>> I want to move some time critical bits of code for hidden Markov
>> models from python to C.  I've written code that works and uses sparse
>> matrices.  Next, I want to implement the "backward" algorithm in C.
> <snip>
>> I think I could glean what I need from
>> that example.  Since I'm new to C extensions, I'd like to see type
>> checking and reference counting done right too.
> Have you tried using cython ((http://www.cython.org)?  It makes
> writing C code extensions almost as painless as typing your variables,
> works well with numpy arrays, and handles all the messy stuff for you.
>  If your goal is to learn the ins and outs of how python works with
> extensions, then stick with c.  But if you just want to optimize your
> code, you can't beat cython.  In particular, see
> http://wiki.cython.org/tutorials/numpy for how to work with numpy.

You can also use weave.inline: http://www.scipy.org/PerformancePython
There you just embed the critical C code directly in the python file and 
everything gets compiled automatically ...


More information about the SciPy-user mailing list