#NEWLINE# def test_conv_rand( backend_default , rand_convargs ) : #NEWLINE# #INDENT# ( indim , nifm , fshape , nofm , batch_size , stride , rng_max , w_rng , pad ) = rand_convargs #NEWLINE# NervanaObject . be . bsz = batch_size #NEWLINE# inp_rng = [ 0.0 , rng_max ] #NEWLINE# dtypeu = np . float32 #NEWLINE# init_unif = Uniform ( low = w_rng [ 0 ] , high = w_rng [ 1 ] ) #NEWLINE# inshape = ( nifm , indim , indim ) #NEWLINE# insize = np . prod ( inshape ) #NEWLINE# neon_layer = Convolution ( fshape = ( fshape , fshape , nofm ) , strides = stride , padding = pad , init = init_unif ) #NEWLINE# ref_layer = ConvLayerRef ( 1 , batch_size , identity , inshape [ 0 ] , inshape [ 1 : 3 ] , ( fshape , fshape ) , nofm , stride , dtypeu , padding = pad ) #NEWLINE# inpa = np . random . random ( ( insize , batch_size ) ) #NEWLINE# inpa *= ( inp_rng [ 1 ] - inp_rng [ 0 ] ) #NEWLINE# inpa += inp_rng [ 0 ] #NEWLINE# inpa = inpa . astype ( dtypeu ) #NEWLINE# inp = neon_layer . be . array ( inpa ) #NEWLINE# inp . lshape = inshape #NEWLINE# neon_layer . configure ( inshape ) #NEWLINE# neon_layer . prev_layer = True #NEWLINE# neon_layer . allocate ( ) #NEWLINE# neon_layer . set_deltas ( [ neon_layer . be . iobuf ( inshape ) ] ) #NEWLINE# neon_out = neon_layer . fprop ( inp ) . get ( ) #NEWLINE# ref_layer . weights = neon_layer . W . get ( ) . T #NEWLINE# ref_layer . fprop ( inpa . T ) #NEWLINE# ref_out = np . copy ( ref_layer . y ) #NEWLINE# ref_layer . fprop ( inpa . T , permute = True ) #NEWLINE# ref_out_perm = ref_layer . y #NEWLINE# atol = ( 4 * np . max ( np . abs ( ( ref_out - ref_out_perm ) ) ) ) #NEWLINE# assert allclose_with_out ( ref_out . T , neon_out , atol = atol , rtol = 0.0001 ) #NEWLINE# erra = np . random . random ( neon_out . shape ) #NEWLINE# erra *= ( inp_rng [ 1 ] - inp_rng [ 0 ] ) #NEWLINE# erra += inp_rng [ 0 ] #NEWLINE# erra = erra . astype ( dtypeu ) #NEWLINE# err = neon_layer . be . array ( erra ) #NEWLINE# neon_deltas = neon_layer . bprop ( err ) . get ( ) #NEWLINE# neon_dW = neon_layer . dW . get ( ) #NEWLINE# ref_layer . bprop ( erra . T , 1.0 ) #NEWLINE# ref_deltas = np . copy ( ref_layer . berror_nopad . T ) #NEWLINE# ref_dW = np . copy ( ref_layer . updates ) #NEWLINE# ref_layer . bprop ( erra . T , 1.0 , permute = True ) #NEWLINE# ref_deltas_perm = ref_layer . berror_nopad . T #NEWLINE# ref_dW_perm = ref_layer . updates #NEWLINE# atol = ( 4 * np . max ( np . abs ( ( ref_deltas - ref_deltas_perm ) ) ) ) #NEWLINE# assert allclose_with_out ( ref_deltas , neon_deltas , atol = atol , rtol = 0.0001 ) #NEWLINE# atol = ( 4 * np . max ( np . abs ( ( ref_dW - ref_dW_perm ) ) ) ) #NEWLINE# assert allclose_with_out ( ref_dW . T , neon_dW , atol = atol , rtol = 0.0001 ) #NEWLINE# return