<s> '''<STR_LIT>''' <EOL> import itertools as itt <EOL> import numpy as np <EOL> from neon import NervanaObject <EOL> from neon . initializers . initializer import Array , Constant , Uniform , Gaussian , GlorotUniform <EOL> def pytest_generate_tests ( metafunc ) : <EOL> if '<STR_LIT:args>' in metafunc . fixturenames : <EOL> fargs = [ ] <EOL> dim1 = [ <NUM_LIT:1> , <NUM_LIT:5> ] <EOL> dim2 = [ <NUM_LIT:2> , <NUM_LIT:10> ] <EOL> fargs = itt . product ( dim1 , dim2 ) <EOL> metafunc . parametrize ( '<STR_LIT:args>' , fargs ) <EOL> def test_constant ( backend_default , args ) : <EOL> be = NervanaObject . be <EOL> dim1 , dim2 = args <EOL> shape = ( dim1 , dim2 ) <EOL> const_arg = <NUM_LIT:3> <EOL> Wdev = be . empty ( shape ) <EOL> const_init = Constant ( const_arg ) <EOL> const_init . fill ( Wdev ) <EOL> Whost = Wdev . get ( ) <EOL> flat = Whost . flatten ( ) <EOL> for elt in flat : <EOL> assert elt == const_arg <EOL> return <EOL> def test_array ( backend_default , args ) : <EOL> be = NervanaObject . be <EOL> dim1 , dim2 = args <EOL> shape = ( dim1 , dim2 ) <EOL> Wloc = be . array ( np . arange ( shape [ <NUM_LIT:0> ] * shape [ <NUM_LIT:1> ] ) . reshape ( shape ) ) <EOL> Wdev = be . empty ( shape ) <EOL> init = Array ( Wdev ) <EOL> init . fill ( Wloc ) <EOL> assert np . all ( np . equal ( Wdev . get ( ) , Wloc . get ( ) ) ) <EOL> return <EOL> def test_uniform ( backend_default , args ) : <EOL> be = NervanaObject . be <EOL> dim1 , dim2 = args <EOL> shape = ( dim1 , dim2 ) <EOL> Wdev = be . empty ( shape ) <EOL> uniform_init = Uniform ( low = - <NUM_LIT:5> , high = <NUM_LIT:15> ) <EOL> uniform_init . fill ( Wdev ) <EOL> Whost = Wdev . get ( ) <EOL> flat = Whost . flatten ( ) <EOL> for elt in flat : <EOL> assert elt <= <NUM_LIT:15> and elt >= - <NUM_LIT:5> <EOL> return <EOL> def test_gaussian ( backend_default , args ) : <EOL> be = NervanaObject . be <EOL> dim1 , dim2 = args <EOL> shape = ( dim1 , dim2 ) <EOL> Wdev = be . empty ( shape ) <EOL> gaussian_init = Gaussian ( loc = <NUM_LIT> , scale = <NUM_LIT:1> ) <EOL> gaussian_init . fill ( Wdev ) <EOL> Whost = Wdev . get ( ) <EOL> flat = Whost . flatten ( ) <EOL> for elt in flat : <EOL> assert elt >= <NUM_LIT:0> <EOL> return <EOL> def test_glorot ( backend_default , args ) : <EOL> be = NervanaObject . be <EOL> shape_1 = ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> shape_2 = ( <NUM_LIT:1000> , <NUM_LIT> ) <EOL> Wdev_1 = be . empty ( shape_1 ) <EOL> Wdev_2 = be . empty ( shape_2 ) <EOL> glorot_init = GlorotUniform ( ) <EOL> glorot_init . fill ( Wdev_1 ) <EOL> glorot_init . fill ( Wdev_2 ) <EOL> Whost_1 = Wdev_1 . get ( ) <EOL> Whost_2 = Wdev_2 . get ( ) <EOL> mean_1 = np . mean ( Whost_1 ) <EOL> mean_2 = np . mean ( Whost_2 ) <EOL> assert np . abs ( mean_1 ) > np . abs ( mean_2 ) <EOL> return </s>
