@verbose
def resample(x, up, down, npad=100, axis=(-1), window='boxcar', n_jobs=1, verbose=None):
 from scipy.signal import get_window
 if (not isinstance(axis, int)):
  err = ('The axis parameter needs to be an integer (got %s). The axis parameter was missing from this function for a period of time, you might be intending to specify the subsequent window parameter.' % repr(axis))
  raise TypeError(err)
 x = np.asanyarray(x)
 ratio = (float(up) / down)
 if (axis < 0):
  axis = (x.ndim + axis)
 orig_last_axis = (x.ndim - 1)
 if (axis != orig_last_axis):
  x = x.swapaxes(axis, orig_last_axis)
 orig_shape = x.shape
 x_len = orig_shape[(-1)]
 if (x_len == 0):
  warn('x has zero length along last axis, returning a copy of x')
  return x.copy()
 bad_msg = 'npad must be "auto" or an integer'
 if isinstance(npad, string_types):
  if (npad != 'auto'):
   raise ValueError(bad_msg)
  min_add = (min((x_len // 8), 100) * 2)
  npad = ((2 ** int(np.ceil(np.log2((x_len + min_add))))) - x_len)
  (npad, extra) = divmod(npad, 2)
  npads = np.array([npad, (npad + extra)], int)
 else:
  if (npad != int(npad)):
   raise ValueError(bad_msg)
  npads = np.array([npad, npad], int)
 del npad
 x_flat = x.reshape(((-1), x_len))
 orig_len = (x_len + npads.sum())
 new_len = int(round((ratio * orig_len)))
 final_len = int(round((ratio * x_len)))
 to_removes = [int(round((ratio * npads[0])))]
 to_removes.append(((new_len - final_len) - to_removes[0]))
 to_removes = np.array(to_removes)
 if (window is not None):
  if callable(window):
   W = window(fftfreq(orig_len))
  elif (isinstance(window, np.ndarray) and (window.shape == (orig_len,))):
   W = window
  else:
   W = ifftshift(get_window(window, orig_len))
 else:
  W = np.ones(orig_len)
 W *= (float(new_len) / float(orig_len))
 W = W.astype(np.complex128)
 (n_jobs, cuda_dict, W) = setup_cuda_fft_resample(n_jobs, W, new_len)
 if (n_jobs == 1):
  y = np.zeros((len(x_flat), (new_len - to_removes.sum())), dtype=x.dtype)
  for (xi, x_) in enumerate(x_flat):
   y[xi] = fft_resample(x_, W, new_len, npads, to_removes, cuda_dict)
 else:
  (parallel, p_fun, _) = parallel_func(fft_resample, n_jobs)
  y = parallel((p_fun(x_, W, new_len, npads, to_removes, cuda_dict) for x_ in x_flat))
  y = np.array(y)
 y.shape = (orig_shape[:(-1)] + (y.shape[1],))
 if (axis != orig_last_axis):
  y = y.swapaxes(axis, orig_last_axis)
 return y

@ verbose def resample ( x , up , down , npad = 100 , axis = ( - 1 ) , window = 'boxcar' , n_jobs = 1 , verbose = None ) : from scipy . signal import get_window if ( not isinstance ( axis , int ) ) : err = ( 'The axis parameter needs to be an integer (got %s). The axis parameter was missing from this function for a period of time, you might be intending to specify the subsequent window parameter.' % repr ( axis ) ) raise TypeError ( err ) x = np . asanyarray ( x ) ratio = ( float ( up ) / down ) if ( axis < 0 ) : axis = ( x . ndim + axis ) orig_last_axis = ( x . ndim - 1 ) if ( axis != orig_last_axis ) : x = x . swapaxes ( axis , orig_last_axis ) orig_shape = x . shape x_len = orig_shape [ ( - 1 ) ] if ( x_len == 0 ) : warn ( 'x has zero length along last axis, returning a copy of x' ) return x . copy ( ) bad_msg = 'npad must be "auto" or an integer' if isinstance ( npad , string_types ) : if ( npad != 'auto' ) : raise ValueError ( bad_msg ) min_add = ( min ( ( x_len // 8 ) , 100 ) * 2 ) npad = ( ( 2 ** int ( np . ceil ( np . log2 ( ( x_len + min_add ) ) ) ) ) - x_len ) ( npad , extra ) = divmod ( npad , 2 ) npads = np . array ( [ npad , ( npad + extra ) ] , int ) else : if ( npad != int ( npad ) ) : raise ValueError ( bad_msg ) npads = np . array ( [ npad , npad ] , int ) del npad x_flat = x . reshape ( ( ( - 1 ) , x_len ) ) orig_len = ( x_len + npads . sum ( ) ) new_len = int ( round ( ( ratio * orig_len ) ) ) final_len = int ( round ( ( ratio * x_len ) ) ) to_removes = [ int ( round ( ( ratio * npads [ 0 ] ) ) ) ] to_removes . append ( ( ( new_len - final_len ) - to_removes [ 0 ] ) ) to_removes = np . array ( to_removes ) if ( window is not None ) : if callable ( window ) : W = window ( fftfreq ( orig_len ) ) elif ( isinstance ( window , np . ndarray ) and ( window . shape == ( orig_len , ) ) ) : W = window else : W = ifftshift ( get_window ( window , orig_len ) ) else : W = np . ones ( orig_len ) W *= ( float ( new_len ) / float ( orig_len ) ) W = W . astype ( np . complex128 ) ( n_jobs , cuda_dict , W ) = setup_cuda_fft_resample ( n_jobs , W , new_len ) if ( n_jobs == 1 ) : y = np . zeros ( ( len ( x_flat ) , ( new_len - to_removes . sum ( ) ) ) , dtype = x . dtype ) for ( xi , x_ ) in enumerate ( x_flat ) : y [ xi ] = fft_resample ( x_ , W , new_len , npads , to_removes , cuda_dict ) else : ( parallel , p_fun , _ ) = parallel_func ( fft_resample , n_jobs ) y = parallel ( ( p_fun ( x_ , W , new_len , npads , to_removes , cuda_dict ) for x_ in x_flat ) ) y = np . array ( y ) y . shape = ( orig_shape [ : ( - 1 ) ] + ( y . shape [ 1 ] , ) ) if ( axis != orig_last_axis ) : y = y . swapaxes ( axis , orig_last_axis ) return y
create a timegrouper and return our resampler .