Commit 646c23dc authored by Florent Jaillet's avatar Florent Jaillet
Browse files

Fix VisibleDeprecationWarnings reported in issue #2

As reported in Issue #2, many VisibleDeprecationWarnings were raised
when running the tests of ltfatpy with a recent version of numpy.

This is now solved by insuring that values used for indexes in numpy
arrays are integers, either by using integer division (//) where needed,
or by explicitely converting to integer type (changing np.func(X/2) to
int(np.func(X/2))), or by using int as the array dtype.
parent 85a3bc97
......@@ -89,7 +89,7 @@ def assert_sigreshape_pre(f, L=None, dim=None):
# ---- Reshape f to a matrix.
if f.size != 0:
f = np.reshape(f, (f.shape[0], f.size / f.shape[0]))
f = np.reshape(f, (f.shape[0], f.size // f.shape[0]))
W = f.shape[1]
......
......@@ -55,15 +55,15 @@ def isevenfunction(f, tol=1e-10, centering='wp'):
if centering == 'wp':
# Determine middle point of sequence.
if L % 2 == 0:
middle = L / 2
middle = L // 2
else:
middle = (L+1) / 2
middle = (L+1) // 2
# Relative norm of difference between the parts of the signal.
d = (LA.norm(f[1:middle] - np.conj(np.flipud(f[L-middle+1:L]))) /
LA.norm(f))
elif centering == 'hp':
middle = np.floor(L/2)
middle = int(np.floor(L/2))
d = (LA.norm(f[0:middle] - np.conj(np.flipud(f[L-middle:L]))) /
LA.norm(f))
else:
......
......@@ -91,16 +91,16 @@ def middlepad(f, L, dim=None, centering='wp'):
if L % 2 == 0:
# L even. Use average of endpoints.
h = np.concatenate((f[:L/2, :],
(f[np.newaxis, L/2, :] +
f[np.newaxis, Lorig-L/2, :]) / 2,
f[Lorig-L/2+1:Lorig, :]))
h = np.concatenate((f[:L//2, :],
(f[np.newaxis, L//2, :] +
f[np.newaxis, Lorig-L//2, :]) / 2,
f[Lorig-L//2+1:Lorig, :]))
else:
# No problem, just cut.
h = np.concatenate((f[:(L+1)/2, :],
f[Lorig-(L-1)/2:Lorig, :]))
h = np.concatenate((f[:(L+1)//2, :],
f[Lorig-(L-1)//2:Lorig, :]))
else:
d = L - Lorig
......@@ -108,17 +108,17 @@ def middlepad(f, L, dim=None, centering='wp'):
# Extend
if Lorig % 2 == 0:
# Lorig even. We must split a value.
h = np.concatenate((f[:Lorig/2, :],
f[np.newaxis, Lorig/2, :]/2,
h = np.concatenate((f[:Lorig//2, :],
f[np.newaxis, Lorig//2, :]/2,
np.zeros((d-1, W), dtype=f.dtype),
f[np.newaxis, Lorig/2, :]/2,
f[Lorig/2+1:Lorig, :]))
f[np.newaxis, Lorig//2, :]/2,
f[Lorig//2+1:Lorig, :]))
else:
# Lorig is odd, we can just insert zeros.
h = np.concatenate((f[:(Lorig+1)/2, :],
h = np.concatenate((f[:(Lorig+1)//2, :],
np.zeros((d, W), dtype=f.dtype),
f[(Lorig+1)/2:Lorig, :]))
f[(Lorig+1)//2:Lorig, :]))
elif centering == 'hp':
......@@ -140,14 +140,14 @@ def middlepad(f, L, dim=None, centering='wp'):
# L even
# No problem, just cut.
h = np.concatenate((f[:L/2, :], f[Lorig-L/2:Lorig, :]))
h = np.concatenate((f[:L//2, :], f[Lorig-L//2:Lorig, :]))
else:
# Average of endpoints.
h = np.concatenate((f[:(L-1)/2, :],
(f[np.newaxis, (L-1)/2, :] +
f[np.newaxis, Lorig-(L+1)/2, :]) / 2,
f[Lorig-(L-1)/2:Lorig, :]))
h = np.concatenate((f[:(L-1)//2, :],
(f[np.newaxis, (L-1)//2, :] +
f[np.newaxis, Lorig-(L+1)//2, :]) / 2,
f[Lorig-(L-1)//2:Lorig, :]))
else:
......@@ -157,17 +157,17 @@ def middlepad(f, L, dim=None, centering='wp'):
if Lorig % 2 == 0:
# Lorig even. We can just insert zeros in the middle.
h = np.concatenate((f[:Lorig/2, :],
h = np.concatenate((f[:Lorig//2, :],
np.zeros((d, W), dtype=f.dtype),
f[Lorig/2:Lorig, :]))
f[Lorig//2:Lorig, :]))
else:
# Lorig odd. We need to split a value in two
h = np.concatenate((f[:(Lorig-1)/2, :],
f[np.newaxis, (Lorig-1)/2, :]/2,
h = np.concatenate((f[:(Lorig-1)//2, :],
f[np.newaxis, (Lorig-1)//2, :]/2,
np.zeros((d-1, W), f.dtype),
f[np.newaxis, (Lorig-1)/2, :]/2,
f[(Lorig+1)/2:Lorig, :]))
f[np.newaxis, (Lorig-1)//2, :]/2,
f[(Lorig+1)//2:Lorig, :]))
else:
# we don't want this function to return a reference or a view to the
......
......@@ -184,7 +184,7 @@ def dgt(f, g, a, M, L=None, pt='freqinv'):
c = comp_sepdgt(f, gnum, a, M, pt)
# flags_do_timeinv = 1
order = assert_groworder(order)
permutedshape = (M, L/a) + permutedshape[1:]
permutedshape = (M, L//a) + permutedshape[1:]
c = assert_sigreshape_post(c, dim, permutedshape, order)
if [i for i in c.shape if i > 2] and c.shape[0] == 1:
......
......@@ -57,7 +57,7 @@ def gabframediag(g, a, M, L):
# compute the diagonal
glong2 = np.abs(fir2long(g, L))**2
N = L/a
N = L//a
# The diagonal is a-periodic, so compute a single period by summing up
# glong2 in slices.
......
......@@ -305,7 +305,7 @@ def gabphasegrad(method, *args, **kwargs):
# NOTE: in the following lines, the shape of phl is changed so that
# broadcasting works in the following addition with cphase when cphase
# has more than two dimensions
new_shape = np.ones((len(cphase.shape), ))
new_shape = np.ones((len(cphase.shape), ), dtype=int)
new_shape[0] = phl.shape[0]
new_shape[1] = phl.shape[1]
phl = phl.reshape(tuple(new_shape))
......
......@@ -162,7 +162,7 @@ def instfreqplot(f, fs=None, tfr=1., wlen=None, nf=None, thr=None, fmax=None,
if nf:
plotdgt(coef, a, fs=fs, **kwargs)
else:
coef = coef[:np.floor(M/2)+1, :]
coef = coef[:int(np.floor(M/2))+1, :]
plotdgtreal(coef, a, M, fs=fs, **kwargs)
return coef
......
......@@ -106,7 +106,7 @@ def firkaiser(L, beta, centering='wp', norm='null'):
(centering == 'hp' and L % 2 == 1)):
# Explicitly zero last element. This is done to get the right
# symmetry, and because that element sometimes turn negative.
g[np.floor(L/2.)] = 0.
g[int(np.floor(L/2.))] = 0.
"""
elif stype == 'derived':
......
......@@ -105,8 +105,8 @@ def groupthresh(xi, lamb, dim=1, group_type='group', thresh_type='soft'):
# or an empty array. Here an equivalent test is written using a
# more explicit formulation.
if M_ii.size != 0:
tau_ii = float(lamb * np.linalg.norm(y[:M_ii+1], 1) /
(1. + lamb*(M_ii+1)))
tau_ii = float(lamb * np.linalg.norm(y[:M_ii[0]+1], 1) /
(1. + lamb*(M_ii[0]+1)))
else:
tau_ii = 0.
......
......@@ -74,11 +74,11 @@ def long2fir(g, L, centering='unsymmetric'):
elif centering == 'wp':
g = middlepad(g, L)
if L % 2 == 0:
g[L/2] = 0
g[L//2] = 0
elif centering == 'hp':
g = middlepad(g, L, centering='hp')
if L % 2 == 1:
g[np.ceil(L/2) - 1] = 0
g[int(np.ceil(L/2)) - 1] = 0
else:
raise ValueError("centering should take 'hp','wp' or 'unsymmetric'" +
" values.")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment