8000 Rollaxis always return view by charris · Pull Request #5464 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Rollaxis always return view #5464

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

Merged
merged 3 commits into from
Jan 19, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH: Make rollaxis always return a view.
Previous to this commit, rollaxis returned a view unless the order of
the axis was unchanged, in which case the input array was returned.
  • Loading branch information
charris committed Jan 19, 2015
commit 38b1a7c3038223ee72138413621ef3e00c9224f5
6 changes: 6 additions & 0 deletions doc/release/1.10.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ the case of matrices. Matrices are special cased for backward
compatibility and still return 1-D arrays as before. If you need to
preserve the matrix subtype, use the methods instead of the functions.

*rollaxis* always returns a view
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Previously, a view was returned except when no change was made in the order
of the axes, in which case the input array was returned. A view is now
returned in all cases.


New Features
============
Expand Down
17 changes: 11 additions & 6 deletions numpy/core/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,7 @@ def roll(a, shift, axis=None):
res = res.reshape(a.shape)
return res


def rollaxis(a, axis, start=0):
"""
Roll the specified axis backwards, until it lies in a given position.
Expand All @@ -1410,7 +1411,9 @@ def rollaxis(a, axis, start=0):
Returns
-------
res : ndarray
A view of `a` with its axes permuted.
For Numpy >= 1.10 a view of `a` is always returned. For earlier
Numpy versions a view of `a` is returned only if the order of the
axes is changed, otherwise the input array is returned.

See Also
--------
Expand All @@ -1436,17 +1439,19 @@ def rollaxis(a, axis, start=0):
msg = 'rollaxis: %s (%d) must be >=0 and < %d'
if not (0 <= axis < n):
raise ValueError(msg % ('axis', axis, n))
if not (0 <= start < n+1):
raise ValueError(msg % ('start', start, n+1))
if (axis < start): # it's been removed
if not (0 <= start < n + 1):
raise ValueError(msg % ('start', start, n + 1))
if (axis < start):
# it's been removed
start -= 1
if axis==start:
return a
if axis == start:
return a[...]
axes = list(range(0, n))
axes.remove(axis)
axes.insert(start, axis)
return a.transpose(axes)


# fix hack in scipy which imports this function
def _move_axis_to_0(a, axis):
return rollaxis(a, axis, 0)
Expand Down
0