<s> import numpy as np <EOL> from neon . backends import gen_backend <EOL> from neon . backends . tests . utils import tensors_allclose <EOL> def test_gpu_randomstate ( device_id ) : <EOL> be = gen_backend ( backend = '<STR_LIT>' , rng_seed = <NUM_LIT:100> , device_id = device_id ) <EOL> a = be . empty ( ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> a [ : ] = be . rand ( ) <EOL> x0 = a . get ( ) <EOL> x1 = be . rng . rand ( <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> a [ : ] = be . rand ( ) <EOL> x2 = a . get ( ) <EOL> be . make_binary_mask ( a , keepthresh = be . rng . rand ( ) ) <EOL> x3 = a . get ( ) <EOL> assert len ( be . context_rand_state_map ) == <NUM_LIT:1> and len ( be . context_rand_state_alive ) == <NUM_LIT:1> <EOL> for ctx in be . context_rand_state_alive : <EOL> assert be . context_rand_state_alive [ ctx ] is True <EOL> be . rng_reset ( ) <EOL> a [ : ] = be . rand ( ) <EOL> y0 = a . get ( ) <EOL> y1 = be . rng . rand ( <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> a [ : ] = be . rand ( ) <EOL> y2 = a . get ( ) <EOL> be . make_binary_mask ( a , keepthresh = be . rng . rand ( ) ) <EOL> y3 = a . get ( ) <EOL> assert len ( be . context_rand_state_map ) == <NUM_LIT:1> and len ( be . context_rand_state_alive ) == <NUM_LIT:1> <EOL> for ctx in be . context_rand_state_alive : <EOL> assert be . context_rand_state_alive [ ctx ] is True <EOL> del ( be ) <EOL> be = gen_backend ( backend = '<STR_LIT>' , rng_seed = <NUM_LIT:100> , device_id = device_id ) <EOL> a = be . empty ( ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> a [ : ] = be . rand ( ) <EOL> z0 = a . get ( ) <EOL> z1 = be . rng . rand ( <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> a [ : ] = be . rand ( ) <EOL> z2 = a . get ( ) <EOL> be . make_binary_mask ( a , keepthresh = be . rng . rand ( ) ) <EOL> z3 = a . get ( ) <EOL> assert tensors_allclose ( [ x0 , x1 , x2 , x3 ] , [ y0 , y1 , y2 , y3 ] , rtol = <NUM_LIT:0.> , atol = <NUM_LIT:0.> ) <EOL> assert tensors_allclose ( [ x0 , x1 , x2 , x3 ] , [ z0 , z1 , z2 , z3 ] , rtol = <NUM_LIT:0.> , atol = <NUM_LIT:0.> ) <EOL> del ( be ) <EOL> def test_cpu_randomstate ( ) : <EOL> be = gen_backend ( backend = '<STR_LIT>' , rng_seed = <NUM_LIT:100> ) <EOL> a = be . empty ( ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> be . make_binary_mask ( a , keepthresh = be . rng . rand ( ) ) <EOL> x0 = a . get ( ) <EOL> be . make_binary_mask ( a , keepthresh = be . rng . rand ( ) ) <EOL> x1 = a . get ( ) <EOL> be . rng_reset ( ) <EOL> be . make_binary_mask ( a , keepthresh = be . rng . rand ( ) ) <EOL> y0 = a . get ( ) <EOL> be . make_binary_mask ( a , keepthresh = be . rng . rand ( ) ) <EOL> y1 = a . get ( ) <EOL> del ( be ) <EOL> be = gen_backend ( backend = '<STR_LIT>' , rng_seed = <NUM_LIT:100> ) <EOL> a = be . empty ( ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> be . make_binary_mask ( a , keepthresh = be . rng . rand ( ) ) <EOL> z0 = a . get ( ) <EOL> be . make_binary_mask ( a , keepthresh = be . rng . rand ( ) ) <EOL> z1 = a . get ( ) <EOL> assert tensors_allclose ( [ x0 , x1 ] , [ y0 , y1 ] , rtol = <NUM_LIT:0.> , atol = <NUM_LIT:0.> ) <EOL> assert tensors_allclose ( [ x0 , x1 ] , [ z0 , z1 ] , rtol = <NUM_LIT:0.> , atol = <NUM_LIT:0.> ) <EOL> del ( be ) <EOL> def test_rng_funcs ( backend_default ) : <EOL> be = backend_default <EOL> sz = <NUM_LIT:32> <EOL> x = be . zeros ( ( sz , sz ) ) <EOL> be . make_binary_mask ( out = x ) <EOL> x1 = x . get ( ) . copy ( ) <EOL> r1 = be . rng_get_state ( ) <EOL> be . make_binary_mask ( out = x ) <EOL> x2 = x . get ( ) . copy ( ) <EOL> assert np . max ( np . abs ( x2 - x1 ) ) > <NUM_LIT:0> <EOL> be . rng_reset ( ) <EOL> be . make_binary_mask ( out = x ) <EOL> x1_2 = x . get ( ) . copy ( ) <EOL> assert np . max ( np . abs ( x1 - x1_2 ) ) == <NUM_LIT:0.0> <EOL> be . rng_reset ( ) <EOL> be . rng_set_state ( r1 ) <EOL> be . make_binary_mask ( out = x ) <EOL> x2_2 = x . get ( ) . copy ( ) <EOL> assert np . max ( np . abs ( x2 - x2_2 ) ) == <NUM_LIT:0.0> </s>
