#NEWLINE# def fft_resample( x , W , new_len , npads , to_removes , cuda_dict = dict ( use_cuda = False ) ) : #NEWLINE# #INDENT# 'Do FFT resampling with a filter function (possibly using CUDA)\n\n    Parameters\n    ----------\n    x : 1-d array\n        The array to resample. Will be converted to float64 if necessary.\n    W : 1-d array or gpuarray\n        The filtering function to apply.\n    new_len : int\n        The size of the output array (before removing padding).\n    npads : tuple of int\n        Amount of padding to apply to the start and end of the\n        signal before resampling.\n    to_removes : tuple of int\n        Number of samples to remove after resampling.\n    cuda_dict : dict\n        Dictionary constructed using setup_cuda_multiply_repeated().\n\n    Returns\n    -------\n    x : 1-d array\n        Filtered version of x.\n    ' #NEWLINE# if ( x . dtype != np . float64 ) : #NEWLINE# #INDENT# x = x . astype ( np . float64 ) #NEWLINE# #UNINDENT# x = _smart_pad ( x , npads ) #NEWLINE# old_len = len ( x ) #NEWLINE# shorter = ( new_len < old_len ) #NEWLINE# if ( not cuda_dict [ 'use_cuda' ] ) : #NEWLINE# #INDENT# N = int ( min ( new_len , old_len ) ) #NEWLINE# x_fft = rfft ( x ) . ravel ( ) #NEWLINE# x_fft *= W [ ( np . arange ( 1 , ( len ( x ) + 1 ) ) // 2 ) ] . real #NEWLINE# y_fft = np . zeros ( new_len , np . float64 ) #NEWLINE# sl_1 = slice ( N ) #NEWLINE# y_fft [ sl_1 ] = x_fft [ sl_1 ] #NEWLINE# if ( ( min ( new_len , old_len ) % 2 ) == 0 ) : #NEWLINE# #INDENT# if ( new_len > old_len ) : #NEWLINE# #INDENT# y_fft [ ( N - 1 ) ] /= 2.0 #NEWLINE# #UNINDENT# #UNINDENT# y = irfft ( y_fft , overwrite_x = True ) . ravel ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cudafft = _get_cudafft ( ) #NEWLINE# cuda_dict [ 'x' ] . set ( np . concatenate ( ( x , np . zeros ( max ( ( new_len - old_len ) , 0 ) , x . dtype ) ) ) ) #NEWLINE# cudafft . fft ( cuda_dict [ 'x' ] , cuda_dict [ 'x_fft' ] , cuda_dict [ 'fft_plan' ] ) #NEWLINE# _multiply_inplace_c128 ( W , cuda_dict [ 'x_fft' ] ) #NEWLINE# use_len = ( new_len if shorter else old_len ) #NEWLINE# func = ( _real_c128 if shorter else _halve_c128 ) #NEWLINE# if ( ( use_len % 2 ) == 0 ) : #NEWLINE# #INDENT# nyq = int ( ( ( use_len - ( use_len % 2 ) ) // 2 ) ) #NEWLINE# func ( cuda_dict [ 'x_fft' ] , slice = slice ( nyq , ( nyq + 1 ) ) ) #NEWLINE# #UNINDENT# cudafft . ifft ( cudafft [ 'x_fft' ] , cuda_dict [ 'x' ] , cuda_dict [ 'ifft_plan' ] , scale = False ) #NEWLINE# y = cuda_dict [ 'x' ] . get ( ) [ : ( new_len if shorter else None ) ] #NEWLINE# #UNINDENT# if ( to_removes > 0 ) . any ( ) : #NEWLINE# #INDENT# keep = np . ones ( new_len , dtype = 'bool' ) #NEWLINE# keep [ : to_removes [ 0 ] ] = False #NEWLINE# keep [ ( - to_removes [ 1 ] ) : ] = False #NEWLINE# y = np . compress ( keep , y ) #NEWLINE# #UNINDENT# return y