<s> '''<STR_LIT>''' <EOL> import itertools as itt <EOL> import numpy as np <EOL> from neon import NervanaObject <EOL> from neon . initializers . initializer import Uniform <EOL> from neon . layers import Affine , MergeMultistream , Sequential <EOL> def pytest_generate_tests ( metafunc ) : <EOL> fargs = [ ] <EOL> eps = np . finfo ( np . float32 ) . eps <EOL> w_rng = [ [ - <NUM_LIT:1.0> , <NUM_LIT:1.0> ] ] <EOL> rng_max = [ eps ] <EOL> fargs = itt . product ( w_rng , rng_max ) <EOL> metafunc . parametrize ( '<STR_LIT>' , fargs ) <EOL> def test_concat_l1_l1 ( backend_default , allrand_args ) : <EOL> dtypeu = np . float32 <EOL> w_rng , rngmax = allrand_args <EOL> nins = [ <NUM_LIT> , <NUM_LIT> ] <EOL> nouts = [ <NUM_LIT:64> , <NUM_LIT> ] <EOL> batch_size = <NUM_LIT:16> <EOL> NervanaObject . be . bsz = batch_size <EOL> be = NervanaObject . be <EOL> init_unif = Uniform ( low = w_rng [ <NUM_LIT:0> ] , high = w_rng [ <NUM_LIT:1> ] ) <EOL> layers = [ Sequential ( Affine ( nout = nout , init = init_unif ) ) for nout in nouts ] <EOL> inputs = [ be . array ( dtypeu ( np . random . random ( ( nin , batch_size ) ) ) ) for nin in nins ] <EOL> merge = MergeMultistream ( layers , merge = "<STR_LIT>" ) <EOL> assert ( len ( inputs ) == len ( layers ) ) <EOL> merge . configure ( inputs ) <EOL> merge . allocate ( ) <EOL> merge . set_deltas ( None ) <EOL> out = merge . fprop ( inputs ) . get ( ) <EOL> sublayers = [ s . layers [ <NUM_LIT:0> ] for s in layers ] <EOL> weights = [ layer . W . get ( ) for layer in sublayers ] <EOL> out_exp = np . concatenate ( [ np . dot ( w , inp . get ( ) ) for ( w , inp ) in zip ( weights , inputs ) ] ) <EOL> assert np . allclose ( out , out_exp , atol = <NUM_LIT> ) <EOL> err_lst = [ dtypeu ( np . random . random ( ( nout , batch_size ) ) ) for nout in nouts ] <EOL> err_concat = np . concatenate ( err_lst ) <EOL> merge . bprop ( be . array ( err_concat ) ) <EOL> dW_exp_lst = [ np . dot ( err , inp . get ( ) . T ) for ( err , inp ) in zip ( err_lst , inputs ) ] <EOL> for layer , dW_exp in zip ( sublayers , dW_exp_lst ) : <EOL> assert np . allclose ( layer . dW . get ( ) , dW_exp ) <EOL> return <EOL> def test_concat_sequence_l1_l1 ( backend_default , allrand_args ) : <EOL> dtypeu = np . float32 <EOL> w_rng , rngmax = allrand_args <EOL> nin = <NUM_LIT> <EOL> steps = [ <NUM_LIT:32> , <NUM_LIT:64> ] <EOL> nout = <NUM_LIT> <EOL> batch_size = <NUM_LIT:16> <EOL> NervanaObject . be . bsz = batch_size <EOL> be = NervanaObject . be <EOL> init_unif = Uniform ( low = w_rng [ <NUM_LIT:0> ] , high = w_rng [ <NUM_LIT:1> ] ) <EOL> layers = [ Sequential ( Affine ( nout = nout , init = init_unif ) ) for _ in range ( <NUM_LIT:2> ) ] <EOL> inputs = [ be . array ( dtypeu ( np . random . random ( ( nin , batch_size * step ) ) ) ) <EOL> for step in steps ] <EOL> merge = MergeMultistream ( layers , merge = "<STR_LIT>" ) <EOL> assert ( len ( inputs ) == len ( layers ) ) <EOL> merge . configure ( inputs ) <EOL> merge . allocate ( ) <EOL> merge . set_deltas ( None ) <EOL> out = merge . fprop ( inputs ) . get ( ) <EOL> sublayers = [ s . layers [ <NUM_LIT:0> ] for s in layers ] <EOL> weights = [ layer . W . get ( ) for layer in sublayers ] <EOL> out_exp = np . concatenate ( [ np . dot ( w , inp . get ( ) ) for ( w , inp ) in zip ( weights , inputs ) ] , axis = <NUM_LIT:1> ) <EOL> assert np . allclose ( out , out_exp , atol = <NUM_LIT> ) <EOL> err_lst = [ dtypeu ( np . random . random ( ( nout , batch_size * step ) ) ) for step in steps ] <EOL> err_concat = be . array ( np . concatenate ( err_lst , axis = <NUM_LIT:1> ) ) <EOL> merge . bprop ( err_concat ) <EOL> dW_exp_lst = [ np . dot ( err , inp . get ( ) . T ) for ( err , inp ) in zip ( err_lst , inputs ) ] <EOL> for layer , dW_exp in zip ( sublayers , dW_exp_lst ) : <EOL> assert np . allclose ( layer . dW . get ( ) , dW_exp ) <EOL> return </s>
