Skip to content

Allow multi-axis roll as in numpy 1.12+ - #1818

Merged
niboshi merged 14 commits into
cupy:masterfrom
grlee77:roll_multi_axis
Dec 27, 2018
Merged

niboshi merged 14 commits into
cupy:masterfrom
grlee77:roll_multi_axis

Conversation

@grlee77

@grlee77 grlee77 commented Nov 23, 2018

Copy link
Copy Markdown
Member

For ease of review, the body of numpy.roll function is reproduced exactly in the first commit here.
The minimal changes needed for cupy are in the second commit.

This version supports rolling along multiple axes in one call
This functionality requires numpy >= 1.12
@grlee77

grlee77 commented Nov 23, 2018

Copy link
Copy Markdown
Member Author

Importing normalize_axis_tuple from older numpy fails here. This small function could be copied locally to fix the issue.

@niboshi niboshi self-assigned this Nov 26, 2018
@niboshi niboshi added the cat:feature New features/APIs label Nov 26, 2018
@niboshi

niboshi commented Nov 29, 2018

Copy link
Copy Markdown
Contributor

Thank you for PR!
Could you add more tests?
What I could come up with are:

  • More axes than ndim
  • shift is a 2-element tuple and axis is a scalar
  • shift is a tuple and axis is None
  • There are unspecified axes in axis, e.g. ndim=3 and axis=(1,2)
  • Negative axis that turns out to duplicate, e.g. ndim=2 and axis=(-1, 1).

@grlee77

grlee77 commented Nov 29, 2018

Copy link
Copy Markdown
Member Author

I have added several more tests and think I have covered all the cases you mentioned above.

We can remove accept_error from the tests using numpy_cupy_raises if it is not desired to check that the error type is the same.

@niboshi niboshi left a comment

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.

I'm sorry for taking time to review.
It's ok to use accept_error.

Please check the review below.

Comment thread cupy/manipulation/rearrange.py Resolved
@grlee77

grlee77 commented Dec 19, 2018

Copy link
Copy Markdown
Member Author

I removed the copied normalize_axis_tuple and added a new test case verifying that duplicates in axis are allowed.

please check if the change to _get_axis error handling is acceptable.

remove accept_error from new np.roll tests
@niboshi

niboshi commented Dec 25, 2018

Copy link
Copy Markdown
Contributor

Could you fix Travis failure?

./tests/cupy_tests/manipulation_tests/test_rearrange.py:3:1: F401 'numpy' imported but unused

@grlee77

grlee77 commented Dec 25, 2018

Copy link
Copy Markdown
Member Author

I have fixed the Travis error. Thank you for the helpful review!

@niboshi

niboshi commented Dec 25, 2018

Copy link
Copy Markdown
Contributor

Thanks!
Jenkins, test this please.

@chainer-ci

Copy link
Copy Markdown
Member

Jenkins CI test (for commit 5898b9f, target branch master) failed with status FAILURE.
(For contributors, please wait until the reviewer confirms the details of the error.)

@niboshi

niboshi commented Dec 25, 2018

Copy link
Copy Markdown
Contributor

It seems numpy.broadcast.ndim was introduced in NumPy 1.12.0.
How about using nd instead? (it's not recommended in documentation but not deprecated.)

https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.broadcast.html#numpy.broadcast

@niboshi

niboshi commented Dec 26, 2018

Copy link
Copy Markdown
Contributor

Jenkins, test this please

@chainer-ci

Copy link
Copy Markdown
Member

Jenkins CI test (for commit 9ad658a, target branch master) failed with status FAILURE.
(For contributors, please wait until the reviewer confirms the details of the error.)

@niboshi

niboshi commented Dec 27, 2018

Copy link
Copy Markdown
Contributor

LGTM.
Thank you very much!

@niboshi niboshi changed the title allow multi-axis roll as in numpy 1.12+ Allow multi-axis roll as in numpy 1.12+ Dec 27, 2018
@niboshi
niboshi merged commit 6f1807f into cupy:master Dec 27, 2018
@niboshi niboshi added this to the v6.0.0b2 milestone Dec 27, 2018
@niboshi niboshi added cat:enhancement Improvements to existing features and removed cat:feature New features/APIs labels Dec 27, 2018
@grlee77
grlee77 deleted the roll_multi_axis branch December 31, 2018 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:enhancement Improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants