Skip to content

Make a.diagonal() writeable. #5407

Open

Description

@charris

The ndarray.diagonal method currently returns a view, but it is not writeable. It is documented to return a writeable view in 1.10.

Activity

  1. added this to the milestone on Jan 1, 2015
  2. maniteja123 commented on Jan 1, 2015

    @maniteja123
    Contributor

    Can I attempt to complete this task ? I am not completely accustomed to the core of numpy but it would be nice if I can try to go through the code for understanding a bit of core python too, since I think this is the line that needs to be removed for the view to be read/write ( as commented in code)
    https://github.com/numpy/numpy/blob/master/numpy/core/src/multiarray/item_selection.c#L2193

    I had found this by searching for PyArray_Diagonal using grep. So, it would be helpful if someone would guide how to find the corresponding core function , say ravel, diagonal or clip.

  3. charris commented on Jan 1, 2015

    @charris
    MemberAuthor

    Sure, have at it. Looks like you found the right spot. There should be a test somewhere that also needs to be updated. If not, you can add one :)

  4. maniteja123 commented on Jan 1, 2015

    @maniteja123
    Contributor

    @charris Thanks :) I will also check if there is corresponding test regarding the diagonal command.

  5. maniteja123 commented on Jan 1, 2015

    @maniteja123
    Contributor

    I think this is the test to check the writability of the view returned by the diagonal. https://github.com/numpy/numpy/blob/master/numpy/core/tests/test_multiarray.py#L1738

    The change needs to be in the assert statement of the a.flags.writeable flag, which needs to be inverted, but the change for the a.flags.owndata need not be changed, I suppose. Do correct me if I am wrong.

  6. charris commented on Jan 1, 2015

    @charris
    MemberAuthor

    Yep, that is the place and the changes you suggest look right. Don't forget to rename the test function.

  7. maniteja123 commented on Jan 1, 2015

    @maniteja123
    Contributor

    Yeah, sure. When we change the name of the test function, do we need to update anywhere ?

  8. charris commented on Jan 1, 2015

    @charris
    MemberAuthor

    Should not matter, nose picks up the test functions by their prefix test.

  9. maniteja123 commented on Jan 1, 2015

    @maniteja123
    Contributor

    Oh thanks , just wanted to confirm. I referenced it in the PR #5409 .

  10. maniteja123 commented on Jan 16, 2015

    @maniteja123
    Contributor

    @charris, I wanted to try out the new changes proposed, it looks like the PyArray_Diagonal needs to be reverted to the scenario before 1.9.0, where a copy was created and returned.here. Though there was a FutureWarning raised then, I think it should be a different scenario now.
    Also, it would be great if you could suggest whether implementing this whole task is feasible for a newcomer like me. If yes, I would want to give it a try to implement the new feature.

  11. njsmith commented on Jan 16, 2015

    @njsmith
    Member

    @maniteja123: Honestly, I'd stay clear of this one as a newcomer -- it's ~5% programming and 95% community debate wrangling.

  12. maniteja123 commented on Jan 16, 2015

    @maniteja123
    Contributor

    @njsmith I do understand the implications of this feature. I just wanted to clarify. Thanks :)

  13. modified the milestones: , on Jun 21, 2015
  14. anntzer commented on Sep 28, 2015

    @anntzer
    Contributor

    Gently bumping the issue. I assume the issue has been indeed moved to 1.11 but the docstring needs some updating in that case. (I would also reorder the sections of the docstring so that "current behavior" rather than "past behavior" goes to the top.)

  15. modified the milestones: 1.12.0 release, on Jan 15, 2016
  16. njsmith commented on Jan 15, 2016

    @njsmith
    Member

    Moving to 1.12, since we haven't talked about this and 1.11 is imminent. Docstrings have been fixed in master to state that this is a planned-at-some-indefinite-future-date rather than giving a specific version.

  17. jakirkham commented on Jan 16, 2016

    @jakirkham
    Contributor

    Seems like it would be a nice feature some day. Especially since it was already documented as a feature. What's the "community debate wrangling" here? Should I even ask? ;)

  18. charris commented on Jan 17, 2016

    @charris
    MemberAuthor

    IIRC, there is a failing test. The transition was from returning a copy of the diagonal to returning a view, that's why the initial step was to make the view ro so folks would not accidentally change the original array.

  19. rgommers commented on Jan 17, 2016

    @rgommers
    Member

    What's the "community debate wrangling" here? Should I even ask? ;)

    It's good to ask. There was a long debate on how bad the backwards compatibility break was: http://article.gmane.org/gmane.comp.python.numeric.general/59620. In hindsight we probably never should have made any changes. It's still a bit up in the air what we'll do now and when I think.

  20. modified the milestone: 1.12.0 release on Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions