[Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)
tim.hochberg at ieee.org
Thu Jan 11 22:24:15 CST 2007
On 1/11/07, Christopher Barker <Chris.Barker at noaa.gov> wrote:
> I'd still like to know if anyone knows how to efficiently loop through
> all the elements of a non-contiguous array in C.
First, it's not that important if the array is contiguous for this sort of
thing. What you really care about is whether it's simply-strided (or maybe
single-strided would be a better term). Anyway, the last dimension of the
array can be strided without making things more difficult. All you need to
be able to do is to address the elements of the array as thedata[offset +
That being said, the strategy that the ufuncs use, and possibly other
functions as well, is to have the core functions operate only on
simply-strided chunks of data. At a higher level, there is some magic that
parcels up non-contiguous array into simply-strided chunks and feeds them to
core functions. How efficient this is obviously depends on how large the
chunks that the magic parceler manages to extract are, but typically it
seems to work pretty well.
I don't know whether the magic that does the parcelling is available for use
by random functions or whether it's specific to the ufunc machinery, I never
delved into that end of the ufuncs.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion