#NEWLINE# def test_consistency_GPU_serial( ) : #NEWLINE# #INDENT# "\n    Verify that the random numbers generated by GPU_mrg_uniform, serially,\n    are the same as the reference (Java) implementation by L'Ecuyer et al.\n\n    " #NEWLINE# if ( not cuda_available ) : #NEWLINE# #INDENT# raise SkipTest ( 'Optional package cuda not available' ) #NEWLINE# #UNINDENT# if ( config . mode == 'FAST_COMPILE' ) : #NEWLINE# #INDENT# mode = 'FAST_RUN' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mode = config . mode #NEWLINE# #UNINDENT# seed = 12345 #NEWLINE# n_samples = 5 #NEWLINE# n_streams = 12 #NEWLINE# n_substreams = 7 #NEWLINE# samples = [ ] #NEWLINE# curr_rstate = numpy . array ( ( [ seed ] * 6 ) , dtype = 'int32' ) #NEWLINE# for i in range ( n_streams ) : #NEWLINE# #INDENT# stream_rstate = curr_rstate . copy ( ) #NEWLINE# for j in range ( n_substreams ) : #NEWLINE# #INDENT# substream_rstate = numpy . array ( stream_rstate . copy ( ) , dtype = 'int32' ) #NEWLINE# tmp_float_buf = numpy . frombuffer ( substream_rstate . data , dtype = 'float32' ) #NEWLINE# rstate = float32_shared_constructor ( tmp_float_buf ) #NEWLINE# ( new_rstate , sample ) = rng_mrg . GPU_mrg_uniform . new ( rstate , ndim = None , dtype = 'float32' , size = ( 1 , ) ) #NEWLINE# rstate . default_update = new_rstate #NEWLINE# sample . rstate = rstate #NEWLINE# sample . update = ( rstate , new_rstate ) #NEWLINE# cpu_sample = tensor . as_tensor_variable ( sample ) #NEWLINE# f = theano . function ( [ ] , cpu_sample , mode = mode ) #NEWLINE# for k in range ( n_samples ) : #NEWLINE# #INDENT# s = f ( ) #NEWLINE# samples . append ( s ) #NEWLINE# #UNINDENT# stream_rstate = rng_mrg . ff_2p72 ( stream_rstate ) #NEWLINE# #UNINDENT# curr_rstate = rng_mrg . ff_2p134 ( curr_rstate ) #NEWLINE# #UNINDENT# samples = numpy . array ( samples ) . flatten ( ) #NEWLINE# assert numpy . allclose ( samples , java_samples )