#NEWLINE# def check_correctness_bc01( f ) : #NEWLINE# #INDENT# '\n    Tests that the theano expression emitted by f computes the same values\n    as the ground truth python function\n    Note: to keep the python version as dead simple as possible (i.e., to make\n    sure there are not bugs in the ground truth) it uses the numerically\n    unstable verison of softmax. So this test does not work with too big of\n    numbers.\n    ' #NEWLINE# rng = np . random . RandomState ( [ 2012 , 7 , 19 ] ) #NEWLINE# batch_size = 5 #NEWLINE# rows = 32 #NEWLINE# cols = 30 #NEWLINE# channels = 3 #NEWLINE# pool_rows = 2 #NEWLINE# pool_cols = 3 #NEWLINE# zv = ( ( rng . randn ( batch_size , rows , cols , channels ) . astype ( config . floatX ) * 1.0 ) - 1.5 ) #NEWLINE# top_down_v = rng . randn ( batch_size , ( rows / pool_rows ) , ( cols / pool_cols ) , channels ) . astype ( config . floatX ) #NEWLINE# ( p_np , h_np ) = max_pool_python ( zv , ( pool_rows , pool_cols ) , p_np ) #NEWLINE# z_th = T . TensorType ( broadcastable = ( False , False , False , False ) , dtype = config . floatX ) ( ) #NEWLINE# z_th . name = 'z_th' #NEWLINE# zr = z_th . dimshuffle ( 0 , 3 , 1 , 2 ) #NEWLINE# top_down_th = T . TensorType ( broadcastable = ( False , False , False , False ) , dtype = config . floatX ) ( ) #NEWLINE# top_down_th . name = 'top_down_th' #NEWLINE# top_down_r = top_down_th . dimshuffle ( 0 , 3 , 1 , 2 ) #NEWLINE# ( p_th , h_th ) = f ( zr , ( pool_rows , pool_cols ) , top_down_r ) #NEWLINE# func = function ( [ z_th , top_down_th ] , [ p_th . dimshuffle ( 0 , 2 , 3 , 1 ) , h_th . dimshuffle ( 0 , 2 , 3 , 1 ) ] ) #NEWLINE# ( pv , hv ) = func ( zv , top_down_v ) #NEWLINE# assert ( p_np . shape == pv . shape ) #NEWLINE# assert ( h_np . shape == hv . shape ) #NEWLINE# if ( not np . allclose ( h_np , hv ) ) : #NEWLINE# #INDENT# print ( ( h_np . min ( ) , h_np . max ( ) ) ) #NEWLINE# print ( ( hv . min ( ) , hv . max ( ) ) ) #NEWLINE# assert False #NEWLINE# #UNINDENT# if ( not np . allclose ( p_np , pv ) ) : #NEWLINE# #INDENT# diff = abs ( ( p_np - pv ) ) #NEWLINE# print ( 'max diff ' , diff . max ( ) ) #NEWLINE# print ( 'min diff ' , diff . min ( ) ) #NEWLINE# print ( 'ave diff ' , diff . mean ( ) ) #NEWLINE# assert False