[Numpy-discussion] Striding on NumArray objects

Francesc Altet faltet at carabos.com
Tue Dec 21 07:29:03 CST 2004


Hi Todd,

A Dimarts 21 Desembre 2004 16:05, vareu escriure:
> This is a difficult question for me,  but I think the answer is that the
> use of _bytestride is very limited.  _bytestride is used to compute the
> "natural" strides of an almost contiguous array, e.g. a field of a
> recarray.   That is,  given a bytestride and a shape,  the strides of a
> field of a contiguous RecArray are implied.  

Yes, I was trying to use _bytestride mainly in RecArray contexts. It just
happens that I've used a NumArray object to check the _bytestride behaviour.

> However,  once we start slicing (say in more than one dimension), 
> _strides contains more and more information and is no longer implied by
> just the shape and bytestride but also by the history of slicing.  From
> that perspective,  it's not clear what _bytestride can be relied upon
> for in general or that it needs to be (or can be) kept up to date during
> slicing.

Well, for the time being it seems that RecArray does not support
multidimensionalty, so I can just use _bytestride as a shortcut of
_strides[0] here. Although now that I think more about this, using
itemsize() as Tim suggested, would be the best to compute strides in
RecArrays; however this is supposing that fields in RecArrays are
contiguous. This would be always the case?

> FWIW,  looking into this uncovered a related bug in numarray.strings
> where I tried to use _bytestride to do a simple iteration over all the
> elements of an array...  that doesn't work.

Good!

Regards,

-- 
Francesc Altet     >qo<   http://www.carabos.com/
Cárabos Coop. V.   V  V   Enjoy Data
                    ""





More information about the Numpy-discussion mailing list