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 :
- revert the changes so that PyArray_Diagonal returns a copy.
- introduce new API function PyArray_Diagonal2, which has a copy argument, so that copy or view can be returned.
- if a view is to be returned, its write-ability depends on whether the input is writeable.
- implement PyArray_Diagonal in terms of the new function, thought the default value of copy is unsure.
- Raise a FutureWarning, when trying to write to the result.
- add copy argument to the diagonal function and method, updating the function in methods.c and fromnumeric.py, probably in other places also.
- Also update the release notes and documentation.
I would love to do the PR once a decision is reached.