#NEWLINE# def test_one_sequence_one_output_weights_gpu2( self ) : #NEWLINE# #INDENT# def f_rnn( u_t , x_tm1 , W_in , W ) : #NEWLINE# #INDENT# return ( ( u_t * W_in ) + ( x_tm1 * W ) ) #NEWLINE# #UNINDENT# u = theano . tensor . fvector ( 'u' ) #NEWLINE# x0 = theano . tensor . fscalar ( 'x0' ) #NEWLINE# W_in = theano . tensor . fscalar ( 'win' ) #NEWLINE# W = theano . tensor . fscalar ( 'w' ) #NEWLINE# ( output , updates ) = theano . scan ( f_rnn , u , x0 , [ W_in , W ] , n_steps = None , truncate_gradient = ( - 1 ) , go_backwards = False , mode = mode_with_gpu ) #NEWLINE# f2 = theano . function ( [ u , x0 , W_in , W ] , output , updates = updates , allow_input_downcast = True , mode = mode_with_gpu ) #NEWLINE# rng = numpy . random . RandomState ( utt . fetch_seed ( ) ) #NEWLINE# v_u = rng . uniform ( size = ( 4 , ) , low = ( - 5.0 ) , high = 5.0 ) #NEWLINE# v_x0 = rng . uniform ( ) #NEWLINE# W = rng . uniform ( ) #NEWLINE# W_in = rng . uniform ( ) #NEWLINE# v_out = numpy . zeros ( ( 4 , ) ) #NEWLINE# v_out [ 0 ] = ( ( v_u [ 0 ] * W_in ) + ( v_x0 * W ) ) #NEWLINE# for step in xrange ( 1 , 4 ) : #NEWLINE# #INDENT# v_out [ step ] = ( ( v_u [ step ] * W_in ) + ( v_out [ ( step - 1 ) ] * W ) ) #NEWLINE# #UNINDENT# theano_values = f2 ( v_u , v_x0 , W_in , W ) #NEWLINE# utt . assert_allclose ( theano_values , v_out ) #NEWLINE# topo = f2 . maker . fgraph . toposort ( ) #NEWLINE# assert ( sum ( [ isinstance ( node . op , HostFromGpu ) for node in topo ] ) == 1 ) #NEWLINE# assert ( sum ( [ isinstance ( node . op , GpuFromHost ) for node in topo ] ) == 4 ) #NEWLINE# scan_node = [ node for node in topo if isinstance ( node . op , theano . scan_module . scan_op . Scan ) ] #NEWLINE# assert ( len ( scan_node ) == 1 ) #NEWLINE# scan_node = scan_node [ 0 ] #NEWLINE# scan_node_topo = scan_node . op . fn . maker . fgraph . toposort ( ) #NEWLINE# assert any ( [ isinstance ( node . op , GpuElemwise ) for node in scan_node_topo ] ) #NEWLINE# assert ( not any ( [ isinstance ( node . op , HostFromGpu ) for node in scan_node_topo ] ) ) #NEWLINE# assert ( not any ( [ isinstance ( node . op , GpuFromHost ) for node in scan_node_topo ] ) )