From 646c23dcd256bbc9af13480993e4dd83a7d85907 Mon Sep 17 00:00:00 2001 From: Florent Jaillet <florent.jaillet@lif.univ-mrs.fr> Date: Tue, 2 Aug 2016 14:09:11 +0200 Subject: [PATCH] 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. --- ltfatpy/comp/assert_sigreshape_pre.py | 2 +- ltfatpy/fourier/isevenfunction.py | 6 ++-- ltfatpy/fourier/middlepad.py | 46 +++++++++++++-------------- ltfatpy/gabor/dgt.py | 2 +- ltfatpy/gabor/gabframediag.py | 2 +- ltfatpy/gabor/gabphasegrad.py | 2 +- ltfatpy/gabor/instfreqplot.py | 2 +- ltfatpy/sigproc/firkaiser.py | 2 +- ltfatpy/sigproc/groupthresh.py | 4 +-- ltfatpy/sigproc/long2fir.py | 4 +-- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/ltfatpy/comp/assert_sigreshape_pre.py b/ltfatpy/comp/assert_sigreshape_pre.py index 2a4d98a..afbfada 100644 --- a/ltfatpy/comp/assert_sigreshape_pre.py +++ b/ltfatpy/comp/assert_sigreshape_pre.py @@ -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] diff --git a/ltfatpy/fourier/isevenfunction.py b/ltfatpy/fourier/isevenfunction.py index ffa8f94..437f5e8 100644 --- a/ltfatpy/fourier/isevenfunction.py +++ b/ltfatpy/fourier/isevenfunction.py @@ -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: diff --git a/ltfatpy/fourier/middlepad.py b/ltfatpy/fourier/middlepad.py index 0f89d57..b7222b3 100644 --- a/ltfatpy/fourier/middlepad.py +++ b/ltfatpy/fourier/middlepad.py @@ -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 diff --git a/ltfatpy/gabor/dgt.py b/ltfatpy/gabor/dgt.py index aa4f537..2f44a71 100644 --- a/ltfatpy/gabor/dgt.py +++ b/ltfatpy/gabor/dgt.py @@ -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: diff --git a/ltfatpy/gabor/gabframediag.py b/ltfatpy/gabor/gabframediag.py index de1ca6a..9788129 100644 --- a/ltfatpy/gabor/gabframediag.py +++ b/ltfatpy/gabor/gabframediag.py @@ -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. diff --git a/ltfatpy/gabor/gabphasegrad.py b/ltfatpy/gabor/gabphasegrad.py index 6b0de41..f63e02a 100644 --- a/ltfatpy/gabor/gabphasegrad.py +++ b/ltfatpy/gabor/gabphasegrad.py @@ -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)) diff --git a/ltfatpy/gabor/instfreqplot.py b/ltfatpy/gabor/instfreqplot.py index 8e80eb7..c44a68d 100644 --- a/ltfatpy/gabor/instfreqplot.py +++ b/ltfatpy/gabor/instfreqplot.py @@ -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 diff --git a/ltfatpy/sigproc/firkaiser.py b/ltfatpy/sigproc/firkaiser.py index 6ac0970..3315357 100644 --- a/ltfatpy/sigproc/firkaiser.py +++ b/ltfatpy/sigproc/firkaiser.py @@ -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': diff --git a/ltfatpy/sigproc/groupthresh.py b/ltfatpy/sigproc/groupthresh.py index 0750015..cb38665 100644 --- a/ltfatpy/sigproc/groupthresh.py +++ b/ltfatpy/sigproc/groupthresh.py @@ -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. diff --git a/ltfatpy/sigproc/long2fir.py b/ltfatpy/sigproc/long2fir.py index eece295..60cd454 100644 --- a/ltfatpy/sigproc/long2fir.py +++ b/ltfatpy/sigproc/long2fir.py @@ -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.") -- GitLab