Skip to content

ENH Generalized rot90 - #7347

Merged
charris merged 2 commits into
numpy:masterfrom
erensezener:generalized_rot90
Jun 22, 2016
Merged

charris merged 2 commits into
numpy:masterfrom
erensezener:generalized_rot90

Conversation

@erensezener

Copy link
Copy Markdown
Contributor

This PR generalizes the rot90 function to rotate an arbitrary plane (defined by axes) of a multidimensional array. Our implementation depends on the generalized flip function introduced in PR #7346.

This PR fixes #6506.

This pull request is part of a BCCN Berlin student project by @denisalevi @ge00rg @erensezener

@charris charris added 01 - Enhancement component: numpy.lib 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes labels Feb 26, 2016
@shoyer

shoyer commented Feb 26, 2016

Copy link
Copy Markdown
Member

This also seems like a good idea, but like for flip, please also run this by the mailing list (could be in the same post).

Comment thread numpy/lib/twodim_base.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should A) add a check for len(axes) == 2 (and a test that it raises appropriately), B) change this to check that neither axis is >= ndim. Checking for ndim >= 2 is no longer necessary.

Also, if both axes are the same you may want to either raise or return the input array. Either way, you should document how you do it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @mhvk noted for your previous PR, you should also add support for negative axes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added A) check for len(axes) in 1a52123

added B) removed check for ndim >= 2 in e5b5b96 and added checking for ndim >=2 and a test for it in aa0d4bf

added raise for same axes and a test for it in 83147ee

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh and I added negative axes support in ndim check here b277c31

and tests here 2d56768

@charris

charris commented Mar 2, 2016

Copy link
Copy Markdown
Member

Updated.

@charris

charris commented Mar 2, 2016

Copy link
Copy Markdown
Member

Needs mention in doc/release/1.12.0-notes.rst. Also squash the 24 commits into one or two. You can use git rebase -i HEAD~24 for that followed by a force push git push --force origin <your branch>.

Comment thread numpy/lib/twodim_base.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need .. versionadded:: 1.12.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is flip here? Isn't that another PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rot90 uses flip so it is based on the other PR. After squashing the commits on the flip PR, we will rebase the rot90 branch on the flip branch.

@madphysicist

Copy link
Copy Markdown
Contributor

@shoyer, @seberg, @charris. I just wanted to bring up my comment on the flip PR #7347 (comment) again since I don't think there's been a response one way or the other. Is this the right file for these functions given that they do not pertain to 2D arrays? Would function_base be more appropriate?

@shoyer

shoyer commented Mar 3, 2016

Copy link
Copy Markdown
Member

@madphysicist Yes, I agree -- it would probably make sense to move the generalized versions of these functions out of twodim_base.py.

@charris

charris commented Mar 7, 2016

Copy link
Copy Markdown
Member

@erensezener It would be good to move the functions/tests and squash the commits. Same for #7346. Maybe you should do them together as on PR?

@denisalevi
denisalevi force-pushed the generalized_rot90 branch 2 times, most recently from a3f56c0 to 595cdfa Compare March 11, 2016 15:37
@denisalevi denisalevi mentioned this pull request Mar 12, 2016
@denisalevi
denisalevi force-pushed the generalized_rot90 branch 2 times, most recently from a8156a9 to ad3a97d Compare March 12, 2016 18:12
@charris

charris commented Mar 12, 2016

Copy link
Copy Markdown
Member

You should add this to the documentation like was done for flip.

@charris charris removed the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Mar 13, 2016
@erensezener

Copy link
Copy Markdown
Contributor Author

@charris Do you mean the release note? It already exists.

@charris

charris commented Mar 18, 2016

Copy link
Copy Markdown
Member

I was thinking of the official documentation, but I see the function already exists and is there.

Should probably document that the return is a view whenever possible, which AFAICT, is always the case unless wrapping a subtype does something special. I assume flip is the same.

@madphysicist

Copy link
Copy Markdown
Contributor

Looking at #7421 as an example, it may be a good idea to add a note in the highlights section.

@erensezener

Copy link
Copy Markdown
Contributor Author

@charris how about:
Returns
-------
y : ndarray
A view of m, which is rotated by 90 degrees in the plane specified by axes.

Also, should we add a note in the highlights section as @madphysicist suggests?

Comment thread numpy/lib/function_base.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will return the array as is if k = 0, which can lead to subtle bugs, see #5258, #5260 and #5468 for some context. Could you please make it always return a view of the input, i.e. return m[:]? It may be worth mentioning it in the documentation, e.g. in the "Returns" section make it "rotated view of the array."

@erensezener

Copy link
Copy Markdown
Contributor Author

@jaimefrio implemented your suggestions

@erensezener

Copy link
Copy Markdown
Contributor Author

@charris this is ready for merge as far as I can see.

@charris charris added this to the 1.12.0 release milestone Apr 16, 2016
@charris charris changed the title Generalized rot90 - fixes #6506 ENHL Generalized rot90 May 9, 2016
@charris charris changed the title ENHL Generalized rot90 ENH Generalized rot90 May 9, 2016
@charris
charris merged commit de0fcbd into numpy:master Jun 22, 2016
@charris

charris commented Jun 22, 2016

Copy link
Copy Markdown
Member

Thanks @erensezener .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generalise rot90 to rotate in any plane

7 participants