[Numpy-discussion] Make as_strided result writeonly

Nathaniel Smith njs at pobox.com
Sat Jan 23 17:20:26 EST 2016


On Sat, Jan 23, 2016 at 1:25 PM, Sebastian Berg
<sebastian at sipsolutions.net> wrote:
>
> Hi all,
>
> I have just opened a PR, to make as_strided writeonly (as default). The

I think you meant readonly :-)

> reasoning for this change is that an `as_strided` array often have self
> overlapping memory. However, writing to an array where multiple
> elements have the identical memory address can be confusing, and the
> results are typically unpredictable.
>
> Considering the danger, the proposal is to add a `readonly=True`. A
> poweruser (who that function is designed for anyway), could thus still
> get a writeable array.
>
> For the moment, writing to the result would raise a FutureWarning with
> `readonly="warn"`.

This should just be a deprecation warning, right? (Because switching
an array from writeable->readonly might cause previously correct code
to error out, but not to silently start returning different results.)

> Do you agree with this, or would it be a major inconvenience?

AFAIK the only use cases for as_strided involve self-overlap (for
non-self-overlap you can generally use reshape / indexing / etc. and
it's much simpler). So +1 from me.

-n

-- 
Nathaniel J. Smith -- https://vorpus.org



More information about the NumPy-Discussion mailing list