<s> from __future__ import absolute_import , print_function , division <EOL> import numpy <EOL> import theano <EOL> from theano import tensor <EOL> import theano . tests . unittest_tools as utt <EOL> from theano . tensor . nnet . tests import test_blocksparse <EOL> from . config import mode_with_gpu , test_ctx_name <EOL> from . . type import gpuarray_shared_constructor <EOL> from . . blocksparse import ( GpuSparseBlockGemv , <EOL> GpuSparseBlockOuter , <EOL> gpu_sparse_block_gemv , <EOL> gpu_sparse_block_outer ) <EOL> class BlockSparse_Gemv_and_Outer ( test_blocksparse . BlockSparse_Gemv_and_Outer ) : <EOL> def setUp ( self ) : <EOL> utt . seed_rng ( ) <EOL> self . mode = mode_with_gpu . excluding ( '<STR_LIT>' ) <EOL> self . gemv_op = gpu_sparse_block_gemv <EOL> self . outer_op = gpu_sparse_block_outer <EOL> self . gemv_class = GpuSparseBlockGemv <EOL> self . outer_class = GpuSparseBlockOuter <EOL> def Xtest_blocksparse_grad_merge ( self ) : <EOL> b = tensor . fmatrix ( ) <EOL> h = tensor . ftensor3 ( ) <EOL> iIdx = tensor . lmatrix ( ) <EOL> oIdx = tensor . lmatrix ( ) <EOL> W_val , h_val , iIdx_val , b_val , oIdx_val = self . gemv_data ( ) <EOL> W = gpuarray_shared_constructor ( W_val , context = test_ctx_name ) <EOL> o = gpu_sparse_block_gemv ( b . take ( oIdx , axis = <NUM_LIT:0> ) , W , h , iIdx , oIdx ) <EOL> gW = theano . grad ( o . sum ( ) , W ) <EOL> lr = numpy . asarray ( <NUM_LIT> , dtype = '<STR_LIT>' ) <EOL> upd = W - lr * gW <EOL> f1 = theano . function ( [ h , iIdx , b , oIdx ] , updates = [ ( W , upd ) ] , <EOL> mode = mode_with_gpu ) <EOL> assert isinstance ( f1 . maker . fgraph . outputs [ <NUM_LIT:0> ] . owner . op , <EOL> GpuSparseBlockOuter ) <EOL> mode = mode_with_gpu . excluding ( '<STR_LIT>' ) <EOL> mode = mode . excluding ( '<STR_LIT>' ) <EOL> f2 = theano . function ( [ h , iIdx , b , oIdx ] , updates = [ ( W , upd ) ] , mode = mode ) <EOL> assert not isinstance ( f2 . maker . fgraph . outputs [ <NUM_LIT:0> ] . owner . op , <EOL> GpuSparseBlockOuter ) <EOL> f2 ( h_val , iIdx_val , b_val , oIdx_val ) <EOL> W_ref = W . get_value ( ) <EOL> W . set_value ( W_val ) <EOL> f1 ( h_val , iIdx_val , b_val , oIdx_val ) <EOL> W_opt = W . get_value ( ) <EOL> utt . assert_allclose ( W_ref , W_opt ) </s>
