Using cwrap to automatically generate pxd for UMFPACK - a minimal example

43 views
Skip to first unread message

Björn Dahlgren

unread,
Apr 9, 2013, 1:58:50 PM4/9/13
to cython...@googlegroups.com
Hi!

I just wanted to share what I nice experience it is to use the new cwrap version (in case someone have missed it!).
As a demo I have put up a wrapper for umfpack (state of the art solving of linear unsymmetric sparse systems) on github:

By utilizing a small extra tool (see source) to convert "#define" style enumerations in UMFPACK the .pxd file(s) used
is never touched by human hand! I expect that there will be corner cases as one make something non trivial, but
at least it works "out of the box" for the the simplest programs. (It goes without saying that a proper cython wrapper would do
best in also abstracting away the explicit calls for memory allocation etc, and provide interfaces with e.g. numpy etc.)

On another note, I haven't been able to find a good cython wrapper for umfpack, is anyone aware of any such effort?
I know the scipy wrapper is using SWIG, which is a shame..

Cheers!
/Björn

Dag Sverre Seljebotn

unread,
Apr 9, 2013, 2:04:03 PM4/9/13
to cython...@googlegroups.com
On 04/09/2013 07:58 PM, Bj�rn Dahlgren wrote:
> Hi!
>
> I just wanted to share what I nice experience it is to use the new cwrap
> <https://github.com/geggo/cwrap> version (in case someone have missed it!).
> As a demo I have put up a wrapper for umfpack
> <http://www.cise.ufl.edu/research/sparse/umfpack/> (state of the art
> solving of linear unsymmetric sparse systems) on github:
> https://github.com/bjodah/cython_umfpack
>
> By utilizing a small extra tool (see source) to convert "#define" style
> enumerations in UMFPACK the .pxd file(s) used
> is never touched by human hand! I expect that there will be corner cases
> as one make something non trivial, but
> at least it works "out of the box" for the the simplest programs. (It
> goes without saying that a proper cython wrapper would do
> best in also abstracting away the explicit calls for memory allocation
> etc, and provide interfaces with e.g. numpy etc.)
>
> On another note, I haven't been able to find a good cython wrapper for
> umfpack, is anyone aware of any such effort?
> I know the scipy wrapper is using SWIG, which is a shame..

Haven't see one, but there's Nathaniel Smith's CHOLMOD wrapper in
scikits-sparse, which would share a lot of the boilerplate I guess since
CHOLMOD and UMFPACK are siblings.

Dag Sverre

Nathaniel Smith

unread,
Apr 9, 2013, 2:18:28 PM4/9/13
to cython...@googlegroups.com
On Tue, Apr 9, 2013 at 7:04 PM, Dag Sverre Seljebotn
<d.s.se...@astro.uio.no> wrote:
Sadly, no -- the CHOLMOD and UMFPACK APIs are totally unlike each
other. (I think Tim Davies wrote UMFPACK first, and then figured out
how to do these things better, and wrote CHOLMOD. Later codes like
SPQR do re-use all the CHOLMOD data structures, but UMFPACK is weird
and ugly.)

I did start writing a proper UMFPACK wrapper some years ago, but never
finished it. I just tracked down the file and committed it, in case
anyone else would like to have a go:
https://github.com/njsmith/scikits-sparse/blob/umfpack/scikits/sparse/umfpack.pyx
A quick skim suggests that a lot of the basic stuff should actually be
working... but who knows, because I didn't get around to writing tests
:-). It'd be great to add a proper UMFPACK wrapper to scikits.sparse,
esp. if we can write the high-level API to match the general style of
the existing CHOLMOD wrapper which I (not so humbly) think is quite
nice:
http://pythonhosted.org/scikits.sparse/cholmod.html

-n
Reply all
Reply to author
Forward
0 new messages