<s> """<STR_LIT>""" <EOL> from __future__ import division , absolute_import , print_function <EOL> from numpy import arange , asarray , zeros , dot , exp , pi , double , cdouble <EOL> import numpy . fft <EOL> from numpy . random import rand <EOL> try : <EOL> from scipy . fftpack import ifft , fft , fftn , irfft , rfft <EOL> except ImportError : <EOL> pass <EOL> from . common import Benchmark <EOL> def random ( size ) : <EOL> return rand ( * size ) <EOL> def direct_dft ( x ) : <EOL> x = asarray ( x ) <EOL> n = len ( x ) <EOL> y = zeros ( n , dtype = cdouble ) <EOL> w = - arange ( n ) * ( <NUM_LIT> * pi / n ) <EOL> for i in range ( n ) : <EOL> y [ i ] = dot ( exp ( i * w ) , x ) <EOL> return y <EOL> def direct_idft ( x ) : <EOL> x = asarray ( x ) <EOL> n = len ( x ) <EOL> y = zeros ( n , dtype = cdouble ) <EOL> w = arange ( n ) * ( <NUM_LIT> * pi / n ) <EOL> for i in range ( n ) : <EOL> y [ i ] = dot ( exp ( i * w ) , x ) / n <EOL> return y <EOL> class Fft ( Benchmark ) : <EOL> params = [ <EOL> [ <NUM_LIT:100> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1000> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> * <NUM_LIT:2> , <NUM_LIT> * <NUM_LIT:4> ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ] <EOL> param_names = [ '<STR_LIT:size>' , '<STR_LIT:type>' , '<STR_LIT>' ] <EOL> def setup ( self , size , cmplx , module ) : <EOL> if cmplx == '<STR_LIT>' : <EOL> self . x = random ( [ size ] ) . astype ( cdouble ) + random ( [ size ] ) . astype ( cdouble ) * <NUM_LIT> <EOL> else : <EOL> self . x = random ( [ size ] ) . astype ( double ) <EOL> def time_fft ( self , size , cmplx , module ) : <EOL> if module == '<STR_LIT>' : <EOL> numpy . fft . fft ( self . x ) <EOL> else : <EOL> fft ( self . x ) <EOL> def time_ifft ( self , size , cmplx , module ) : <EOL> if module == '<STR_LIT>' : <EOL> numpy . fft . ifft ( self . x ) <EOL> else : <EOL> ifft ( self . x ) <EOL> class RFft ( Benchmark ) : <EOL> params = [ <EOL> [ <NUM_LIT:100> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1000> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> * <NUM_LIT:2> , <NUM_LIT> * <NUM_LIT:4> ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ] <EOL> param_names = [ '<STR_LIT:size>' , '<STR_LIT>' ] <EOL> def setup ( self , size , module ) : <EOL> self . x = random ( [ size ] ) . astype ( double ) <EOL> def time_rfft ( self , size , module ) : <EOL> if module == '<STR_LIT>' : <EOL> numpy . fft . rfft ( self . x ) <EOL> else : <EOL> rfft ( self . x ) <EOL> def time_irfft ( self , size , module ) : <EOL> if module == '<STR_LIT>' : <EOL> numpy . fft . irfft ( self . x ) <EOL> else : <EOL> irfft ( self . x ) <EOL> class Fftn ( Benchmark ) : <EOL> params = [ <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ] <EOL> param_names = [ '<STR_LIT:size>' , '<STR_LIT:type>' , '<STR_LIT>' ] <EOL> def setup ( self , size , cmplx , module ) : <EOL> size = map ( int , size . split ( "<STR_LIT:x>" ) ) <EOL> if cmplx != '<STR_LIT>' : <EOL> self . x = random ( size ) . astype ( double ) <EOL> else : <EOL> self . x = random ( size ) . astype ( cdouble ) + random ( size ) . astype ( cdouble ) * <NUM_LIT> <EOL> def time_fftn ( self , size , cmplx , module ) : <EOL> if module == '<STR_LIT>' : <EOL> numpy . fft . fftn ( self . x ) <EOL> else : <EOL> fftn ( self . x ) </s>
