#NEWLINE# def basictest( f , steps , sample_size , prefix = '' , allow_01 = False , inputs = None , target_avg = 0.5 , target_std = None , mean_rtol = 0.01 , std_tol = 0.01 ) : #NEWLINE# #INDENT# if ( inputs is None ) : #NEWLINE# #INDENT# inputs = [ ] #NEWLINE# #UNINDENT# dt = 0.0 #NEWLINE# avg_var = 0.0 #NEWLINE# for i in xrange ( steps ) : #NEWLINE# #INDENT# t0 = time . time ( ) #NEWLINE# ival = f ( * inputs ) #NEWLINE# assert ( ival . shape == sample_size ) #NEWLINE# dt += ( time . time ( ) - t0 ) #NEWLINE# ival = numpy . asarray ( ival ) #NEWLINE# if ( i == 0 ) : #NEWLINE# #INDENT# mean = numpy . array ( ival , copy = True ) #NEWLINE# avg_var = numpy . mean ( ( ( ival - target_avg ) ** 2 ) ) #NEWLINE# min_ = ival . min ( ) #NEWLINE# max_ = ival . max ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# alpha = ( 1.0 / ( 1 + i ) ) #NEWLINE# mean = ( ( alpha * i ) + ( ( 1 - alpha ) * mean ) ) #NEWLINE# avg_var = ( ( alpha * numpy . mean ( ( ( ival - target_avg ) ** 2 ) ) ) + ( ( 1 - alpha ) * avg_var ) ) #NEWLINE# min_ = min ( min_ , ival . min ( ) ) #NEWLINE# max_ = max ( max_ , ival . max ( ) ) #NEWLINE# #UNINDENT# if ( not allow_01 ) : #NEWLINE# #INDENT# assert ( min_ > 0 ) #NEWLINE# assert ( max_ < 1 ) #NEWLINE# #UNINDENT# #UNINDENT# if hasattr ( target_avg , 'shape' ) : #NEWLINE# #INDENT# diff = numpy . mean ( abs ( ( mean - target_avg ) ) ) #NEWLINE# assert numpy . all ( ( diff < ( mean_rtol * ( 1 + abs ( target_avg ) ) ) ) ) , ( 'bad mean? %s %s' % ( mean , target_avg ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mean = numpy . mean ( mean ) #NEWLINE# assert ( abs ( ( mean - target_avg ) ) < ( mean_rtol * ( 1 + abs ( target_avg ) ) ) ) , ( 'bad mean? %f %f' % ( mean , target_avg ) ) #NEWLINE# #UNINDENT# std = numpy . sqrt ( avg_var ) #NEWLINE# if ( target_std is not None ) : #NEWLINE# #INDENT# assert ( abs ( ( std - target_std ) ) < ( std_tol * ( 1 + abs ( target_std ) ) ) ) , ( 'bad std? %f %f %f' % ( std , target_std , std_tol ) )