[Numpy-discussion] Zeros in strides
oliphant.travis at ieee.org
Thu Feb 2 17:39:02 EST 2006
>A rank-1 array with strides=0 behaves almost like a scalar, in fact
>scalar arithmetics is currently implemented by setting stride to 0 is
>generic umath loops. Like scalar, rank-1 array with stride=0 only
>needs a buffer of size 1*itemsize, but currently numpy does not allow
>creation of rank-1 arrays with buffer smaller than size*itemsize:
As you noted, broadcasting is actually done by setting strides equal to
0 in the affected dimensions.
The changes you describe, however, require serious thought with C-level
explanations because you will be changing some fundamental assumptions
that are made throughout the code.
For example, currently there is no way you can construct new memory for
an array and have different strides assigned (that's why strides is
ignored if no buffer is given). You would have to change the behavior
of the C-level function PyArray_NewFromDescr. You need to propose how
exactly you would change that.
Checking for strides that won't cause later segfaults can be tricky
especially if you start allowing buffer-sizes to be different than array
dimensions. How do you propose to ensure that you won't walk outside
of allocated memory when somebody changes the strides later?
I'm concerned that your proposal has too many potential pitfalls. At
least you haven't addressed them sufficiently. My current inclination
is to simply disallow setting the strides attribute now that the
misaligned segments of code have been tested.
More information about the NumPy-Discussion