8000 DEP: deprecate rollaxis by nschloe · Pull Request #9475 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 7 commits into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 8 additions & 5 deletions numpy/core/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 `moveaxis`. The `moveaxis` function was added in NumPy
1.11.

Parameters
----------
a : ndarray
Expand Down Expand Up @@ -1618,7 +1622,7 @@ def moveaxis(a, source, destination):

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


def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None):
Expand Down Expand Up @@ -1743,8 +1747,8 @@ def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None):
axisb = normalize_axis_index(axisb, b.ndim, msg_prefix='axisb')

# Move working axis to the end of the shape
a = rollaxis(a, axisa, a.ndim)
b = rollaxis(b, axisb, b.ndim)
a = moveaxis(a, axisa, -1)
b = moveaxis(b, axisb, -1)
msg = ("incompatible dimensions for cross product\n"
"(dimension must be 2 or 3)")
if a.shape[-1] not in (2, 3) or b.shape[-1] not in (2, 3):
Expand Down Expand Up @@ -1815,8 +1819,7 @@ def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None):
multiply(a0, b1, out=cp2)
cp2 -= a1 * b0

# This works because we are moving the last axis
return rollaxis(cp, -1, axisc)
return moveaxis(cp, -1, axisc)


# Use numarray's printing function
Expand Down
4 changes: 2 additions & 2 deletions numpy/core/tests/test_shape_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ def test_exceptions(self):
np.concatenate((a, b), axis=axis[0]) # OK
assert_raises(ValueError, np.concatenate, (a, b), axis=axis[1])
assert_raises(ValueError, np.concatenate, (a, b), axis=axis[2])
a = np.rollaxis(a, -1)
b = np.rollaxis(b, -1)
a = np.moveaxis(a, -1, 0)
b = np.moveaxis(b, -1, 0)
axis.append(axis.pop(0))

# No arrays to concatenate raises ValueError
Expand Down
14 changes: 7 additions & 7 deletions numpy/lib/function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4328,7 +4328,7 @@ def _percentile(a, q, axis=None, out=None,

ap.partition(indices, axis=axis)
# ensure axis with qth is first
ap = np.rollaxis(ap, axis, 0)
ap = np.moveaxis(ap, axis, 0)
axis = 0

# Check if the array contains any nan's
Expand Down Expand Up @@ -4361,9 +4361,9 @@ def _percentile(a, q, axis=None, out=None,
ap.partition(concatenate((indices_below, indices_above)), axis=axis)

# ensure axis with qth is first
ap = np.rollaxis(ap, axis, 0)
weights_below = np.rollaxis(weights_below, axis, 0)
weights_above = np.rollaxis(weights_above, axis, 0)
ap = np.moveaxis(ap, axis, 0)
weights_below = np.moveaxis(weights_below, axis, 0)
weights_above = np.moveaxis(weights_above, axis, 0)
axis = 0

# Check if the array contains any nan's
Expand All @@ -4375,8 +4375,8 @@ def _percentile(a, q, axis=None, out=None,
x2 = take(ap, indices_above, axis=axis) * weights_above

# ensure axis with qth is first
x1 = np.rollaxis(x1, axis, 0)
x2 = np.rollaxis(x2, axis, 0)
x1 = np.moveaxis(x1, axis, 0)
x2 = np.moveaxis(x2, axis, 0)

if zerod:
x1 = x1.squeeze(0)
Expand Down Expand Up @@ -5032,7 +5032,7 @@ def insert(arr, obj, values, axis=None):
# broadcasting is very different here, since a[:,0,:] = ... behaves
# very different from a[:,[0],:] = ...! This changes values so that
# it works likes the second case. (here a[:,0:1,:])
values = np.rollaxis(values, 0, (axis % values.ndim) + 1)
values = np.moveaxis(values, 0, axis)
numnew = values.shape[axis]
newshape[axis] += numnew
new = empty(newshape, arr.dtype, arrorder)
Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/nanfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ def _nanpercentile(a, q, axis=None, out=None, overwrite_input=False,
# Move that axis to the beginning to match percentile's
# convention.
if q.ndim != 0:
result = np.rollaxis(result, axis)
result = np.moveaxis(result, axis, 0)

if out is not None:
out[...] = result
Expand Down
4 changes: 2 additions & 2 deletions numpy/lib/tests/test_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2958,7 +2958,7 @@ def test_extended_axis(self):
o = np.random.normal(size=(71, 23))
x = np.dstack([o] * 10)
assert_equal(np.percentile(x, 30, axis=(0, 1)), np.percentile(o, 30))
x = np.rollaxis(x, -1, 0)
x = np.moveaxis(x, -1, 0)
assert_equal(np.percentile(x, 30, axis=(-2, -1)), np.percentile(o, 30))
x = x.swapaxes(0, 1).copy()
assert_equal(np.percentile(x, 30, axis=(0, -1)), np.percentile(o, 30))
Expand Down Expand Up @@ -3339,7 +3339,7 @@ def test_extended_axis(self):
o = np.random.normal(size=(71, 23))
x = np.dstack([o] * 10)
assert_equal(np.median(x, axis=(0, 1)), np.median(o))
x = np.rollaxis(x, -1, 0)
x = np.moveaxis(x, -1, 0)
assert_equal(np.median(x, axis=(-2, -1)), np.median(o))
x = x.swapaxes(0, 1).copy()
assert_equal(np.median(x, axis=(0, -1)), np.median(o))
Expand Down
2 changes: 1 addition & 1 deletion numpy/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ def _median_nancheck(data, result, axis, out):
"""
if data.size == 0:
return result
data = np.rollaxis(data, axis, data.ndim)
data = np.moveaxis(data, axis, -1)
n = np.isnan(data[..., -1])
# masked NaN values are ok
if np.ma.isMaskedArray(n):
Expand Down
6 changes: 2 additions & 4 deletions numpy/linalg/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
array, asarray, zeros, empty, empty_like, transpose, intc, single, double,
csingle, cdouble, inexact, complexfloating, newaxis, ravel, all, Inf, dot,
add, multiply, sqrt, maximum, fastCopyAndTranspose, sum, isfinite, size,
finfo, errstate, geterrobj, longdouble, rollaxis, amin, amax, product, abs,
finfo, errstate, geterrobj, longdouble, moveaxis, amin, amax, product, abs,
broadcast, atleast_2d, intp, asanyarray, isscalar, object_, ones
)
from numpy.core.multiarray import normalize_axis_index
Expand Down Expand Up @@ -2004,9 +2004,7 @@ def _multi_svd_norm(x, row_axis, col_axis, op):
is `numpy.amin` or `numpy.amax` or `numpy.sum`.

"""
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))
result = op(svd(y, compute_uv=0), axis=-1)
return result

Expand Down
10 changes: 5 additions & 5 deletions numpy/polynomial/chebyshev.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ def chebder(c, m=1, scl=1, axis=0):
if cnt == 0:
return c

c = np.rollaxis(c, iaxis)
c = np.moveaxis(c, iaxis, 0)
n = len(c)
if cnt >= n:
c = c[:1]*0
Expand All @@ -958,7 +958,7 @@ def chebder(c, m=1, scl=1, axis=0):
der[1] = 4*c[2]
der[0] = c[1]
c = der
c = np.rollaxis(c, 0, iaxis + 1)
c = np.moveaxis(c, 0, iaxis)
return c


Expand Down Expand Up @@ -1067,7 +1067,7 @@ def chebint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
if cnt == 0:
return c

c = np.rollaxis(c, iaxis)
c = np.moveaxis(c, iaxis, 0)
k = list(k) + [0]*(cnt - len(k))
for i in range(cnt):
n = len(c)
Expand All @@ -1086,7 +1086,7 @@ def chebint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
tmp[j - 1] -= c[j]/(2*(j - 1))
tmp[0] += k[i] - chebval(lbnd, tmp)
c = tmp
c = np.rollaxis(c, 0, iaxis + 1)
c = np.moveaxis(c, 0, iaxis)
return c


Expand Down Expand Up @@ -1458,7 +1458,7 @@ def chebvander(x, deg):
v[1] = x
for i in range(2, ideg + 1):
v[i] = v[i-1]*x2 - v[i-2]
return np.rollaxis(v, 0, v.ndim)
return np.moveaxis(v, 0, -1)


def chebvander2d(x, y, deg):
Expand Down
10 changes: 5 additions & 5 deletions numpy/polynomial/hermite.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def hermder(c, m=1, scl=1, axis=0):
if cnt == 0:
return c

c = np.rollaxis(c, iaxis)
c = np.moveaxis(c, iaxis, 0)
n = len(c)
if cnt >= n:
c = c[:1]*0
Expand All @@ -718,7 +718,7 @@ def hermder(c, m=1, scl=1, axis=0):
for j in range(n, 0, -1):
der[j - 1] = (2*j)*c[j]
c = der
c = np.rollaxis(c, 0, iaxis + 1)
c = np.moveaxis(c, 0, iaxis)
return c


Expand Down Expand Up @@ -825,7 +825,7 @@ def hermint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
if cnt == 0:
return c

c = np.rollaxis(c, iaxis)
c = np.moveaxis(c, iaxis, 0)
k = list(k) + [0]*(cnt - len(k))
for 10000 i in range(cnt):
n = len(c)
Expand All @@ -840,7 +840,7 @@ def hermint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
tmp[j + 1] = c[j]/(2*(j + 1))
tmp[0] += k[i] - hermval(lbnd, tmp)
c = tmp
c = np.rollaxis(c, 0, iaxis + 1)
c = np.moveaxis(c, 0, iaxis)
return c


Expand Down Expand Up @@ -1229,7 +1229,7 @@ def hermvander(x, deg):
v[1] = x2
for i in range(2, ideg + 1):
v[i] = (v[i-1]*x2 - v[i-2]*(2*(i - 1)))
return np.rollaxis(v, 0, v.ndim)
return np.moveaxis(v, 0, -1)


def hermvander2d(x, y, deg):
Expand Down
10 changes: 5 additions & 5 deletions numpy/polynomial/hermite_e.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ def hermeder(c, m=1, scl=1, axis=0):
if cnt == 0:
return c

c = np.rollaxis(c, iaxis)
c = np.moveaxis(c, iaxis, 0)
n = len(c)
if cnt >= n:
return c[:1]*0
Expand All @@ -717,7 +717,7 @@ def hermeder(c, m=1, scl=1, axis=0):
for j in range(n, 0, -1):
der[j - 1] = j*c[j]
c = der
c = np.rollaxis(c, 0, iaxis + 1)
c = np.moveaxis(c, 0, iaxis)
return c


Expand Down Expand Up @@ -824,7 +824,7 @@ def hermeint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
if cnt == 0:
return c

c = np.rollaxis(c, iaxis)
c = np.moveaxis(c, iaxis, 0)
k = list(k) + [0]*(cnt - len(k))
for i in range(cnt):
n = len(c)
Expand All @@ -839,7 +839,7 @@ def hermeint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
tmp[j + 1] = c[j]/(j + 1)
tmp[0] += k[i] - hermeval(lbnd, tmp)
c = tmp
c = np.rollaxis(c, 0, iaxis + 1)
c = np.moveaxis(c, 0, iaxis)
return c


Expand Down Expand Up @@ -1226,7 +1226,7 @@ def hermevander(x, deg):
v[1] = x
for i in range(2, ideg + 1):
v[i] = (v[i-1]*x - v[i-2]*(i - 1))
return np.rollaxis(v, 0, v.ndim)
return np.moveaxis(v, 0, -1)


def hermevander2d(x, y, deg):
Expand Down
10 changes: 5 additions & 5 deletions numpy/polynomial/laguerre.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def lagder(c, m=1, scl=1, axis=0):
if cnt == 0:
return c

c = np.rollaxis(c, iaxis)
c = np.moveaxis(c, iaxis, 0)
n = len(c)
if cnt >= n:
c = c[:1]*0
Expand All @@ -717,7 +717,7 @@ def lagder(c, m=1, scl=1, axis=0):
c[j - 1] += c[j]
der[0] = -c[1]
c = der
c = np.rollaxis(c, 0, iaxis + 1)
c = np.moveaxis(c, 0, iaxis)
return c


Expand Down Expand Up @@ -825,7 +825,7 @@ def lagint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
if cnt == 0:
return c

c = np.rollaxis(c, iaxis)
c = np.moveaxis(c, iaxis, 0)
k = list(k) + [0]*(cnt - len(k))
for i in range(cnt):
n = len(c)
Expand All @@ -841,7 +841,7 @@ def lagint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
tmp[j + 1] = -c[j]
tmp[0] += k[i] - lagval(lbnd, tmp)
c = tmp
c = np.rollaxis(c, 0, iaxis + 1)
c = np.moveaxis(c, 0, iaxis)
return c


Expand Down Expand Up @@ -1228,7 +1228,7 @@ def lagvander(x, deg):
v[1] = 1 - x
for i in range(2, ideg + 1):
v[i] = (v[i-1]*(2*i - 1 - x) - v[i-2]*(i - 1))/i
return np.rollaxis(v, 0, v.ndim)
return np.moveaxis(v, 0, -1)


def lagvander2d(x, y, deg):
Expand Down
10 changes: 5 additions & 5 deletions numpy/polynomial/legendre.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def legder(c, m=1, scl=1, axis=0):
if cnt == 0:
return c

c = np.rollaxis(c, iaxis)
c = np.moveaxis(c, iaxis, 0)
n = len(c)
if cnt >= n:
c = c[:1]*0
Expand All @@ -758,7 +758,7 @@ def legder(c, m=1, scl=1, axis=0):
der[1] = 3*c[2]
der[0] = c[1]
c = der
c = np.rollaxis(c, 0, iaxis + 1)
c = np.moveaxis(c, 0, iaxis)
return c


Expand Down Expand Up @@ -867,7 +867,7 @@ def legint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
if cnt == 0:
return c

c = np.rollaxis(c, iaxis)
c = np.moveaxis(c, iaxis, 0)
k = list(k) + [0]*(cnt - len(k))
for i in range(cnt):
n = len(c)
Expand All @@ -886,7 +886,7 @@ def legint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
tmp[j - 1] -= t
tmp[0] += k[i] - legval(lbnd, tmp)
c = tmp
c = np.rollaxis(c, 0, iaxis + 1)
c = np.moveaxis(c, 0, iaxis)
return c


Expand Down Expand Up @@ -1259,7 +1259,7 @@ def legvander(x, deg):
v[1] = x
for i in range(2, ideg + 1):
v[i] = (v[i-1]*x*(2*i - 1) - v[i-2]*(i - 1))/i
return np.rollaxis(v, 0, v.ndim)
return np.moveaxis(v, 0, -1)


def legvander2d(x, y, deg):
Expand Down
Loading
0