<s> from __future__ import division , absolute_import , print_function <EOL> from itertools import product <EOL> import numpy as np <EOL> try : <EOL> import scipy . signal as signal <EOL> except ImportError : <EOL> pass <EOL> from . common import Benchmark <EOL> class CalculateWindowedFFT ( Benchmark ) : <EOL> def setup ( self ) : <EOL> np . random . seed ( <NUM_LIT> ) <EOL> x = np . random . randn ( <NUM_LIT:2> ** <NUM_LIT:20> ) <EOL> y = np . random . randn ( <NUM_LIT:2> ** <NUM_LIT:20> ) <EOL> self . x = x <EOL> self . y = y <EOL> def time_welch ( self ) : <EOL> signal . welch ( self . x ) <EOL> def time_csd ( self ) : <EOL> signal . csd ( self . x , self . y ) <EOL> def time_periodogram ( self ) : <EOL> signal . periodogram ( self . x ) <EOL> def time_spectrogram ( self ) : <EOL> signal . spectrogram ( self . x ) <EOL> def time_coherence ( self ) : <EOL> signal . coherence ( self . x , self . y ) <EOL> class Convolve2D ( Benchmark ) : <EOL> param_names = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> params = [ <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ] <EOL> def setup ( self , mode , boundary ) : <EOL> np . random . seed ( <NUM_LIT> ) <EOL> pairs = [ ] <EOL> for ma , na , mb , nb in product ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:30> ) , repeat = <NUM_LIT:4> ) : <EOL> a = np . random . randn ( ma , na ) <EOL> b = np . random . randn ( mb , nb ) <EOL> pairs . append ( ( a , b ) ) <EOL> self . pairs = pairs <EOL> def time_convolve2d ( self , mode , boundary ) : <EOL> for a , b in self . pairs : <EOL> if mode == '<STR_LIT>' : <EOL> if b . shape [ <NUM_LIT:0> ] > a . shape [ <NUM_LIT:0> ] or b . shape [ <NUM_LIT:1> ] > a . shape [ <NUM_LIT:1> ] : <EOL> continue <EOL> signal . convolve2d ( a , b , mode = mode , boundary = boundary ) <EOL> def time_correlate2d ( self , mode , boundary ) : <EOL> for a , b in self . pairs : <EOL> if mode == '<STR_LIT>' : <EOL> if b . shape [ <NUM_LIT:0> ] > a . shape [ <NUM_LIT:0> ] or b . shape [ <NUM_LIT:1> ] > a . shape [ <NUM_LIT:1> ] : <EOL> continue <EOL> signal . correlate2d ( a , b , mode = mode , boundary = boundary ) <EOL> class FFTConvolve ( Benchmark ) : <EOL> param_names = [ '<STR_LIT>' ] <EOL> params = [ <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ] <EOL> def setup ( self , mode ) : <EOL> np . random . seed ( <NUM_LIT> ) <EOL> pairs = [ ] <EOL> for ma , nb in product ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> ) , repeat = <NUM_LIT:2> ) : <EOL> a = np . random . randn ( ma ) <EOL> b = np . random . randn ( nb ) <EOL> pairs . append ( ( a , b ) ) <EOL> self . pairs = pairs <EOL> def time_convolve2d ( self , mode ) : <EOL> for a , b in self . pairs : <EOL> if b . shape [ <NUM_LIT:0> ] > a . shape [ <NUM_LIT:0> ] : <EOL> continue <EOL> signal . fftconvolve ( a , b , mode = mode ) <EOL> class Convolve ( Benchmark ) : <EOL> param_names = [ '<STR_LIT>' ] <EOL> params = [ <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ] <EOL> def setup ( self , mode ) : <EOL> np . random . seed ( <NUM_LIT> ) <EOL> pairs = [ ] <EOL> for ma , nb in product ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> ) , repeat = <NUM_LIT:2> ) : <EOL> a = np . random . randn ( ma ) <EOL> b = np . random . randn ( nb ) <EOL> pairs . append ( ( a , b ) ) <EOL> self . pairs = pairs <EOL> def time_convolve ( self , mode ) : <EOL> for a , b in self . pairs : <EOL> if b . shape [ <NUM_LIT:0> ] > a . shape [ <NUM_LIT:0> ] : <EOL> continue <EOL> signal . convolve ( a , b , mode = mode ) <EOL> def time_correlate ( self , mode ) : <EOL> for a , b in self . pairs : <EOL> if b . shape [ <NUM_LIT:0> ] > a . shape [ <NUM_LIT:0> ] : <EOL> continue <EOL> signal . correlate ( a , b , mode = mode ) <EOL> class LTI ( Benchmark ) : <EOL> def setup ( self ) : <EOL> self . system = signal . lti ( <NUM_LIT:1.0> , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> self . t = np . arange ( <NUM_LIT:0> , <NUM_LIT:100> , <NUM_LIT:0.5> ) <EOL> self . u = np . sin ( <NUM_LIT:2> * self . t ) <EOL> def time_lsim ( self ) : <EOL> signal . lsim ( self . system , self . u , self . t ) <EOL> def time_lsim2 ( self ) : <EOL> signal . lsim2 ( self . system , self . u , self . t ) <EOL> def time_step ( self ) : <EOL> signal . step ( self . system , T = self . t ) <EOL> def time_impulse ( self ) : <EOL> signal . impulse ( self . system , T = self . t ) <EOL> def time_bode ( self ) : <EOL> signal . bode ( self . system ) </s>
