[Numpy-discussion] Questions about C API
Russell E Owen
owen at astro.washington.edu
Fri Apr 9 10:26:09 CDT 2004
I'm trying to write a median function (surely one is there already,
but if so I've not found it). The fastest technique seems to involve
rearranging the data in place. So I'd like to offer two calls:
- A version that rearranges the input array if no local copy needed
to be made (e.g. the input data was already contiguous and of the
expected type). I know how to write that one.
- A safer, slower version that always makes a copy of the input data.
I'm stuck on that. The high-level interface has flags for when to
make a local copy, but none of them seems to mean "always make a
local copy". Surely I am missing something there? I guess I could get
the data, see if a local copy was made and if not, make a copy of my
own, but that seems messy.
Also, is there any simple sample code running around for handling
arrays of any type (e.g. with C++ templates)? Right now I'm writing
to a specific type (since it's easy and I know what type to expect
for my application), but I'd rather make my code more general and
numarray-like. I figured the numarray code itself would be a good
example, but, well, I didn't understand the parts I looked at (maybe
I'm clueless, maybe I didn't find the right bits to examine).
More information about the Numpy-discussion