[Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

Timothy Hochberg 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:

[CHOP]


> 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 +
stride*index].

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.

-tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070111/4179ef49/attachment.html 


More information about the Numpy-discussion mailing list