[Numpy-discussion] Learning "strides"
oliphant.travis at ieee.org
Thu Feb 2 16:45:01 EST 2006
>I don't know if this came from numarray or not, but for me as someone
>who transitions from Numeric, the "strides" attribute to an ndarray is
>a a new feature. I've spend some time playing with it and there are
>some properties that I dislike. Some of these undesired properties
>are probably bugs and easy to fix, but others require some discussion.
Of course strides have always been there, they've just never been
visible from Python.
Allowing the user to set the strides may not be a good idea. It was
done largely so that the code that deals with misaligned data could be
tested. However, it also allows you a lot of flexibility for
interacting with arbitrary data-buffers that might be useful, so I'm
inclined to allow it if the possible problems can be fixed.
Users that set strides will have to know what they are doing, of
course. The average user wouldn't bother with it.
>1. Negative strides:
>>>>x = zeros(5)
>array([ 0, 25, 0, -136009696, -136009536])
>Looks like a bug. PyArray_CheckStrides only checks for one end of the
Right. PyArray_CheckStrides needs to be better or we can't allow
>3. "Fractional" strides:
>I call "fractional" strides that are not a multiple of "itemsize".
In dealing with an arbitrary data-buffer, I could see this as being
useful, so I'm not sure if disallowing it is a good idea. Again,
setting strides is not something that should be done by the average user
so I'm not as concerned about "forgetting" the units strides are in.
If a user is going to be setting strides you have to assume they are
A separate attribute called steps that uses element-sizes instead of
byte-sizes is a possible idea.
More information about the NumPy-Discussion