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

David Cournapeau david at ar.media.kyoto-u.ac.jp
Fri Jan 12 00:12:31 EST 2007

Timothy Hochberg wrote:
> On 1/11/07, *Christopher Barker* <Chris.Barker at noaa.gov 
> <mailto: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].
I don't understand why we need to do thedata[offset + stride * index] 
instead of thedata[index] when the data are aligned ? It looks like I 
seriously misunderstood the meaning of alignement...

> 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
> ------------------------------------------------------------------------
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list