#NEWLINE# def _smart_pad( x , n_pad ) : #NEWLINE# #INDENT# 'Pad vector x\n    ' #NEWLINE# if ( n_pad == 0 ) . all ( ) : #NEWLINE# #INDENT# return x #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( n_pad < 0 ) . any ( ) : #NEWLINE# #INDENT# raise RuntimeError ( 'n_pad must be non-negative' ) #NEWLINE# #UNINDENT# #UNINDENT# l_z_pad = np . zeros ( max ( ( ( n_pad [ 0 ] - len ( x ) ) + 1 ) , 0 ) , dtype = x . dtype ) #NEWLINE# r_z_pad = np . zeros ( max ( ( ( n_pad [ 0 ] - len ( x ) ) + 1 ) , 0 ) , dtype = x . dtype ) #NEWLINE# return np . concatenate ( [ l_z_pad , ( ( 2 * x [ 0 ] ) - x [ n_pad [ 0 ] : 0 : ( - 1 ) ] ) , x , ( ( 2 * x [ ( - 1 ) ] ) - x [ ( - 2 ) : ( ( - n_pad [ 1 ] ) - 2 ) : ( - 1 ) ] ) , r_z_pad ] )