[Numpy-discussion] The future of ndarray.diagonal()

Maniteja Nandana maniteja.modesty067 at gmail.com
Thu Jan 15 11:44:36 EST 2015


Hello everyone,

I just wanted to highlight the point made by Charles, it would be great if
he would clarify any mistakes in the points that I put forward.

Quoting the documentation,

In versions of NumPy prior to 1.7, this function always returned a
new,independent array containing a copy of the values in the diagonal.

    In NumPy 1.7 and 1.8, it continues to return a copy of the
diagonal,but depending on this fact is deprecated. Writing to the
resulting array continues to work as it used to, but a FutureWarning
is issued.

    In NumPy 1.9 it returns a read-only view on the original array.
Attempting to write to the resulting array will produce an error.

    In NumPy 1.10, it will return a read/write view, Writing to the
returned array will alter your original array.

Though the expected behaviour has its pros and cons,the points put forward are :


   1. revert the changes so that *PyArray_Diagonal *returns a *copy.*
   2. introduce new API function *PyArray_Diagonal2, *which has a
*copy *argument, so that copy or view can be returned.
   3. if a *view* is to be returned, its *write-ability *depends on
whether the *input* is writeable.
   4. implement *PyArray_Diagonal *in terms of the new function,
thought the default value of *copy *is unsure.
   5. Raise a *FutureWarning*, when trying to write to the result.
   6. add *copy *argument to the *diagonal *function and method,
updating the function in *methods.c *and *fromnumeric.py, *probably in
other places also.
   7. Also update the release notes and documentation.

I would love to do the PR once a decision is reached.

Cheers,

N.Maniteja.

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion at scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150115/3ab06ead/attachment.html>


More information about the NumPy-Discussion mailing list