-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
DEP: deprecate rollaxis #9475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DEP: deprecate rollaxis #9475
Conversation
numpy/linalg/linalg.py
Outdated
@@ -2006,7 +2006,7 @@ def _multi_svd_norm(x, row_axis, col_axis, op): | |||
""" | |||
if row_axis > col_axis: | |||
row_axis -= 1 | |||
y = rollaxis(rollaxis(x, col_axis, x.ndim), row_axis, -1) | |||
y = moveaxis(moveaxis(x, col_axis, -1), row_axis, -2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done with a single call to moveaxis
I'm +1 for moving internal uses of rollaxis to moveaxis. I'm -1 on actually deprecating rollaxis. A louder warning in the docstring for rollaxis against using it would be great (e.g., "We recommend using moveaxis instead."). Take a look at the docs for We don't actually remove functionality in NumPy unless absolutely necessary, and we don't deprecate anything unless we actually plan to remove it. |
Don't forget the DEP: and MAINT: commit prefices. Also, this fails because you're not hiding deprecation warnings in rollaxis tests |
@shoyer: to be clear, by warning you mean documentation-only, as opposed to an actual python warning. |
Perhaps we should introduce a |
I'm with @shoyer on this one. |
Sure, but only if we can silence the warning by default. Otherwise it's an even more annoying version of DeprecationWarning -- one that's entirely useless! A red box like what you find in the Python docs for deprecated functions could be a nice approach: (Notice that none of these functions actually issue a warning when you use them.) |
Thanks for the comments, I've addressed the issues mentioned so far. As for the deprecation, I would say there must be some sort of it. This little text found in Should we tackle this now or on another PR? |
Maybe another PR? There's a long list of semi-deprecated functions. Clarifying that could require some discussion. |
I've added #9478 so we don't lose track of this. |
numpy/core/numeric.py
Outdated
@@ -1436,6 +1436,10 @@ def rollaxis(a, axis, start=0): | |||
""" | |||
Roll the specified axis backwards, until it lies in a given position. | |||
|
|||
This function continues to be supported for backward compatibility, but you | |||
should prefer np.moveaxis. The np.moveaxis function was added in NumPy | |||
1.11. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
referring to this as `moveaxis`
will cause a link to be generated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it because of the missing tick or the additional np.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both, I think. There's nothing special about "np" - remember, the module's called "numpy" (but that's implied anyway in references)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
numpy/linalg/linalg.py
Outdated
@@ -2006,7 +2006,7 @@ def _multi_svd_norm(x, row_axis, col_axis, op): | |||
""" | |||
if row_axis > col_axis: | |||
row_axis -= 1 | |||
y = rollaxis(rollaxis(x, col_axis, x.ndim), row_axis, -1) | |||
y = moveaxis(x, [row_axis, col_axis], [-2, -1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be inclined to pass tuples here, if only because the function used internally is called normalize_index_tuple
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the tests are failing here. travis says
ValueError: repeated axis in
source
argument
so I'm guessing this occurs when row_axis
and col_axis
are equal. Perhaps we do need two moveaxis
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit lost as to why if row_axis > col_axis: row_axis -= 1
is done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a crutch for the rollaxis behaviour to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit that introduced this function is 4 years old, a292614, and the code hasn't been touched since.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in fact, after removing it, there's an assertion for nonequality at the caller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So to conclude: just remove those two lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I get it now: If if row_axis > col_axis
, and col_axis
is moved to the end of the shape first, one needs to row_axis -= 1
to still get the right axis when moving the second one to the end.
Indeed, we don't need this anymore. Praised be moveaxis
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but needs squashing - we can do that from GitHub's ui if needed
@nschloe Could you add a comment to |
@charris Under deprecations? |
Oh, sorry. I see that no actual warning is issued, so no note is needed. |
Late here, but hurray for this cleanup! (and for changing the main documentation to make it clearer that |
@eric-wieser Want to finish this up? |
Thanksfor the patch @nschloe! |
Interestingly this seems to cause a significant performance decrease. I don't think we should reverse this, but maybe |
The changelog of 1.11 says about the then-new moveaxis:
I've recently stumbled upon rollaxis's weirdness myself, so perhaps it's time to deprecate it.
This PR replaces all occurrences of
rollaxis
by its correspondingmoveaxis
equivalent, and arguably the code becomes clearer. For example, instead ofthe new
makes clear that
iaxis
moved to the first spot, then something happens, and then it's moved back.