[Numpy-discussion] Advice on converting Numarray C extension?
Charles R Harris
Tue Jun 30 20:00:00 CDT 2009
On Tue, Jun 30, 2009 at 12:31 PM, Russell E. Owen <email@example.com>wrote:
> In article
> Charles R Harris <firstname.lastname@example.org> wrote:
> > On Mon, Jun 29, 2009 at 4:17 PM, Russell E. Owen
> > <email@example.com>wrote:
> > > In article
> > > <firstname.lastname@example.org>,
> > > Charles R Harris <email@example.com> wrote:
> > >
> > > > On Mon, Jun 29, 2009 at 3:03 PM, Russell E. Owen
> > > > <firstname.lastname@example.org>wrote:
> > > >
> > > > > I have an old Numarray C extension (or, rather, a Python package
> > > > > containing a C extension) that I would like to convert to numpy
> > > > > (in a way that is likely to be supported long-term).
> > > >
> > > > How big is the extension and what does it do?
> > >
> > > It basically contains 2 functions:
> > > 1: radProfile: given a masked image (2d array), a radius and a desired
> > > center: compute a new 1d array whose value at index r is the sum of all
> > > unmasked pixels at radius r.
> > >
> > > 2: radAsymm: given the same inputs as radProfile, return a (scalar)
> > > measure of radial asymmetry by computing the variance of unmasked
> > > at each radius and combining the results.
> > >
> > > The original source file is about 1000 lines long, of which 1/3 to 1/2
> > > is the basic C code and the rest is Python wrapper.
> > It sounds small enough that you should be able to update it to the numpy
> > interface. What functions do you need? You should also be able to attach
> > copy (zipped) if it is small enough, which might help us help you.
> It is the PyGuide package
> a 525k zip file. The extension code is in the src directory.
> I would certainly be grateful for any pointers to how the old numarray C
> API functions map to the new numpy ones. I would prefer to use the new
> numpy API if I can figure out what to do.
This doesn't look too bad, I only count 5 functions/macros.
The quick and dirty solution would be to just copy those functions in at the
top of your code. You might want to fix up the NumarrayType enum instead of
including it and a few other such.
The code looks like it would go over into cython fairly nicely since it is
split between interface code, which would look good in python, and a couple
of pure c functions. If you have the time that might be a good way to go.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion