[Numpy-discussion] missing array type
Sasha
ndarray at mac.com
Mon Feb 27 18:36:02 EST 2006
On 2/27/06, Travis Oliphant <oliphant at ee.byu.edu> wrote:
> .... I think 0-stride arrays are acceptable (I
> think you can make them now but you have to provide your own memory,
> right?)
>
Not really. Ndarray constructor has never allowed zeros in strides. It
was possible to set strides to a tuple containing zeros after
construction in some cases. I've changed that in r2054
<http://projects.scipy.org/scipy/numpy/changeset/2054>. Currently
zero strides are not allowed.
> From one perspective, all we are proposing to do is allow numpy to
> create the memory *and* allow differently strided arrays, right?
Another way to view this is that we are proposing to change the
computation of memory requirements to consider strides instead of item
size and number of items. Zero strides require only one item to be
allocated for any number of items in the array.
> Now, if it creates the memory, the strides must be C-contiguous or
> fortran-contiguous. We are going to allow user-specified strides, now,
> even on memory creation.
>
Yes.
> Sasha, your initial patch was pretty good but I was concerned about the
> speed of array creation being changed for other cases. If you can speed
> up PyArray_NewFromDescr (probably by only changing the branch that
> currently raises an error), then I think your proposed changes should be
> O.K.
>
I will probably not be able to do it right away. Meanwhile I've
created a wiki page for this mini-project
<http://projects.scipy.org/scipy/numpy/wiki/ZeroStrideArray>.
> The check on the provided strides argument needs to be thought through
> so that we don't accept strides that will allow walking outside the
> memory that *is* or *will be* allocated.
>
> I have not reviewed your code for this, but I'm assuming you've thought
> that through?
That was the central issue in the patch: how to compute the size of
the buffer in the presence of zero strides, so I hope I got it right.
In order to make zero stride arrays really useful, they should survive
transformation by ufunc. With my patch if x is a zero-stride array of
length N, then exp(x) is a regular array and exp is called N times to
compute the result. That would be a much bigger project. As a first
step, I would just disallow using zero-stride arrays as output to
avoid problems with inplace operations.
In any case, everyone interested in this feature is invited to edit
the wiki page at
<http://projects.scipy.org/scipy/numpy/wiki/ZeroStrideArray>.
More information about the NumPy-Discussion
mailing list