<div dir="ltr"><div dir="ltr"><div>Hi, <br></div><div><br></div><div>Was it ever brought up the possibility of a new array class (ndrefonly, ndview) that is strictly no copy?<br></div><div><br></div><div>All operations on ndrefonly will return ndrefonly and if the operation cannot be completed without making a copy, it shall throw an error.</div><div><br></div><div>On the implementation there are two choices if we use subclasses:</div><div><br></div><div>- ndrefonly can be a subclass of ndarray. The pattern would be subclass limiting functionality of super, but ndrefonly is a ndarray.<br></div><div>- ndarray as a subclass of ndarray. Subclass supplements functionality of super. : ndarray will not throw an error when a copy is necessary. However ndarray is not a ndarray.</div><div><br></div><div>If we want to be wild they do not even need to be subclasses of each other, or maybe they shall both be subclasses of something more fundamental. <br></div><div></div><div><br></div><div></div><div></div><div>- Yu<br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Dec 28, 2018 at 5:45 AM Sebastian Berg <<a href="mailto:sebastian@sipsolutions.net">sebastian@sipsolutions.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, 2018-12-27 at 17:45 -0800, Nathaniel Smith wrote:<br>
> On Thu, Dec 27, 2018 at 3:27 PM Juan Nunez-Iglesias <<br>
> <a href="mailto:jni.soma@gmail.com" target="_blank">jni.soma@gmail.com</a>> wrote:<br>
> > On Fri, Dec 28, 2018, at 3:40 AM, Sebastian Berg wrote:<br>
> > <br>
> > > It’s consistent with np.newaxis in spelling (modulo the _)<br>
> > > If mistyped, it can be caught easily by IDEs.<br>
> > > It’s typeable with mypy, unlike constant string literals which<br>
> > > currently aren’t<br>
> > > If code written against new numpy is run on old numpy, it will<br>
> > > error<br>
> > > rather than doing the wrong thing<br>
> > <br>
> > I am not sure I think that the above are too strong arguments,<br>
> > since it<br>
> > is not what is typically done for keywords (nobody suggests np.CLIP<br>
> > instead of "clip"). Unless you feel this is different because it is<br>
> > a<br>
> > mix of strings and bools here?<br>
> > <br>
> > <br>
> > :+1: to Eric's list. I don't think it's different because of the<br>
> > mix, I think it's different because deprecating things is painful.<br>
> > But now that we have good typing in Python, I think of string<br>
> > literals as an anti-pattern going forward.<br>
> <br>
> I've certainly seen people argue that it's better to use proper<br>
> enum's<br>
> in this kind of case instead of strings. The 'enum' package is even<br>
> included in the stdlib on all our supported versions now:<br>
> <a href="https://docs.python.org/3/library/enum.html" rel="noreferrer" target="_blank">https://docs.python.org/3/library/enum.html</a><br>
> <br>
<br>
I am sympathetic with that, but it is something we (or scipy, etc.) <br>
currently simply do not use, so I am not sure that I think it has much<br>
validity at this time. That is least unless we agree to aim to use this<br>
more generally in the future.<br>
<br>
> I guess another possibility to throw out there would be a second<br>
> kwarg, require_view=False/True.<br>
> <br>
<br>
My first gut feeling was that it is clumsy at least for `reshape`, but<br>
one will always only use one of the two arguments at a time.<br>
The more I look at it, the better the suggestion seems. Plus it reduces<br>
the possible `copy=False` not meaning "never" confusion.<br>
<br>
I think with a bit more pondering, that will become my favorite<br>
solution.<br>
<br>
- Sebastian<br>
<br>
<br>
> -n<br>
> <br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div>