<s> import unittest <EOL> from nose . plugins . skip import SkipTest <EOL> import numpy <EOL> import theano <EOL> from theano . tensor import dmatrix , iscalar , lscalar , dmatrices <EOL> from theano import tensor <EOL> from theano . compile import In <EOL> from theano . compile . sharedvalue import * <EOL> from theano . compile . pfunc import * <EOL> def data_of ( s ) : <EOL> """<STR_LIT>""" <EOL> return s . container . storage [ <NUM_LIT:0> ] <EOL> class Test_pfunc ( unittest . TestCase ) : <EOL> def test_doc ( self ) : <EOL> """<STR_LIT>""" <EOL> a = lscalar ( ) <EOL> b = shared ( <NUM_LIT:1> ) <EOL> f1 = pfunc ( [ a ] , ( a + b ) ) <EOL> f2 = pfunc ( [ In ( a , value = <NUM_LIT> ) ] , a + b , updates = { b : b + <NUM_LIT:1> } ) <EOL> self . assertTrue ( b . get_value ( ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( f1 ( <NUM_LIT:3> ) == <NUM_LIT:4> ) <EOL> self . assertTrue ( f2 ( <NUM_LIT:3> ) == <NUM_LIT:4> ) <EOL> self . assertTrue ( b . get_value ( ) == <NUM_LIT:2> ) <EOL> self . assertTrue ( f1 ( <NUM_LIT:3> ) == <NUM_LIT:5> ) <EOL> b . set_value ( <NUM_LIT:0> ) <EOL> self . assertTrue ( f1 ( <NUM_LIT:3> ) == <NUM_LIT:3> ) <EOL> a = tensor . lscalar ( ) <EOL> b = shared ( <NUM_LIT:7> ) <EOL> f1 = pfunc ( [ a ] , a + b ) <EOL> f2 = pfunc ( [ a ] , a * b ) <EOL> self . assertTrue ( f1 ( <NUM_LIT:5> ) == <NUM_LIT:12> ) <EOL> b . set_value ( <NUM_LIT:8> ) <EOL> self . assertTrue ( f1 ( <NUM_LIT:5> ) == <NUM_LIT> ) <EOL> self . assertTrue ( f2 ( <NUM_LIT:4> ) == <NUM_LIT:32> ) <EOL> def test_shared ( self ) : <EOL> w = shared ( numpy . random . rand ( <NUM_LIT:2> , <NUM_LIT:2> ) , '<STR_LIT:w>' ) <EOL> wval = w . get_value ( borrow = False ) <EOL> x = dmatrix ( ) <EOL> out1 = w + x <EOL> out2 = w * x <EOL> f1 = pfunc ( [ x ] , [ out1 ] ) <EOL> f2 = pfunc ( [ x ] , [ out2 ] ) <EOL> xval = numpy . random . rand ( <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> assert numpy . all ( f1 ( xval ) == xval + wval ) <EOL> assert numpy . all ( f2 ( xval ) == xval * wval ) <EOL> f3 = pfunc ( [ x ] , out1 , updates = [ ( w , ( w - <NUM_LIT:1> ) ) ] ) <EOL> assert numpy . all ( f3 ( xval ) == xval + wval ) <EOL> assert numpy . all ( f1 ( xval ) == xval + ( wval - <NUM_LIT:1> ) ) <EOL> w . set_value ( w . get_value ( borrow = True ) * <NUM_LIT:10> , borrow = True ) <EOL> assert numpy . all ( f1 ( xval ) == xval + w . get_value ( borrow = True ) ) <EOL> def test_no_shared_as_input ( self ) : <EOL> """<STR_LIT>""" <EOL> w_init = numpy . random . rand ( <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> w = shared ( w_init . copy ( ) , '<STR_LIT:w>' ) <EOL> try : <EOL> pfunc ( [ w ] , theano . tensor . sum ( w * w ) ) <EOL> assert False <EOL> except TypeError as e : <EOL> msg = '<STR_LIT>' <EOL> if str ( e ) . find ( msg ) < <NUM_LIT:0> : <EOL> raise <EOL> def test_default_container ( self ) : <EOL> rng = numpy . random . RandomState ( <NUM_LIT> ) <EOL> w_init = rng . rand ( <NUM_LIT:5> ) <EOL> w = shared ( w_init . copy ( ) , '<STR_LIT:w>' ) <EOL> reg = theano . tensor . sum ( w * w ) <EOL> f = pfunc ( [ ] , reg ) <EOL> assert f ( ) == numpy . sum ( w_init * w_init ) <EOL> w . set_value ( w . get_value ( borrow = True ) + <NUM_LIT:1.0> , borrow = True ) <EOL> assert f ( ) == numpy . sum ( ( w_init + <NUM_LIT:1> ) ** <NUM_LIT:2> ) <EOL> def test_default_scalar_container ( self ) : <EOL> x = shared ( <NUM_LIT:0.0> , '<STR_LIT:x>' ) <EOL> f = pfunc ( [ ] , x ) <EOL> assert f ( ) == <NUM_LIT:0> <EOL> x . set_value ( x . get_value ( borrow = True ) + <NUM_LIT:1> , borrow = True ) <EOL> assert f ( ) == <NUM_LIT:1> <EOL> def test_param_strict ( self ) : <EOL> a = tensor . dvector ( ) <EOL> b = shared ( <NUM_LIT:7> ) <EOL> out = a + b <EOL> f = pfunc ( [ In ( a , strict = False ) ] , [ out ] ) <EOL> f ( numpy . random . rand ( <NUM_LIT:8> ) ) <EOL> f ( numpy . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , dtype = '<STR_LIT>' ) ) <EOL> f = pfunc ( [ In ( a , strict = True ) ] , [ out ] ) <EOL> try : <EOL> f ( numpy . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , dtype = '<STR_LIT>' ) ) <EOL> except TypeError : <EOL> pass <EOL> def test_param_mutable ( self ) : <EOL> a = tensor . dvector ( ) <EOL> a_out = a * <NUM_LIT:2> <EOL> fip = pfunc ( [ In ( a , mutable = True ) ] , [ a_out ] , mode = '<STR_LIT>' ) <EOL> aval = numpy . random . rand ( <NUM_LIT:10> ) <EOL> aval2 = aval . copy ( ) <EOL> assert numpy . all ( fip ( aval ) == ( aval2 * <NUM_LIT:2> ) ) <EOL> assert not numpy . all ( aval == aval2 ) <EOL> f = pfunc ( [ In ( a , mutable = False ) ] , [ a_out ] , mode = '<STR_LIT>' ) <EOL> aval = numpy . random . rand ( <NUM_LIT:10> ) <EOL> aval2 = aval . copy ( ) <EOL> assert numpy . all ( f ( aval ) == ( aval2 * <NUM_LIT:2> ) ) <EOL> assert numpy . all ( aval == aval2 ) <EOL> def test_shared_mutable ( self ) : <EOL> bval = numpy . arange ( <NUM_LIT:5> ) <EOL> b = shared ( bval ) <EOL> b_out = b * <NUM_LIT:2> <EOL> assert b . get_value ( borrow = True ) is not bval <EOL> bval = data_of ( b ) <EOL> f = pfunc ( [ ] , [ b_out ] , mode = '<STR_LIT>' ) <EOL> assert ( f ( ) == numpy . arange ( <NUM_LIT:5> ) * <NUM_LIT:2> ) . all ( ) <EOL> assert numpy . all ( b . get_value ( borrow = True ) == numpy . arange ( <NUM_LIT:5> ) ) <EOL> f = pfunc ( [ ] , [ b_out ] , updates = [ ( b , b_out ) ] , mode = '<STR_LIT>' ) <EOL> assert ( f ( ) == ( numpy . arange ( <NUM_LIT:5> ) * <NUM_LIT:2> ) ) . all ( ) <EOL> assert ( b . get_value ( borrow = True ) == ( numpy . arange ( <NUM_LIT:5> ) * <NUM_LIT:2> ) ) . all ( ) <EOL> assert ( bval == ( numpy . arange ( <NUM_LIT:5> ) * <NUM_LIT:2> ) ) . all ( ) <EOL> bval = numpy . arange ( <NUM_LIT:5> ) <EOL> b . set_value ( bval , borrow = True ) <EOL> bval = data_of ( b ) <EOL> f = pfunc ( [ ] , [ b_out ] , updates = [ ( b , ( b_out + <NUM_LIT:3> ) ) ] , mode = '<STR_LIT>' ) <EOL> assert ( f ( ) == ( numpy . arange ( <NUM_LIT:5> ) * <NUM_LIT:2> ) ) . all ( ) <EOL> assert ( b . get_value ( borrow = True ) == ( ( numpy . arange ( <NUM_LIT:5> ) * <NUM_LIT:2> ) + <NUM_LIT:3> ) ) . all ( ) <EOL> assert not ( bval == numpy . arange ( <NUM_LIT:5> ) ) . all ( ) <EOL> assert not ( bval == b . get_value ( borrow = True ) ) . all ( ) <EOL> def test_param_allow_downcast_int ( self ) : <EOL> a = tensor . wvector ( '<STR_LIT:a>' ) <EOL> b = tensor . bvector ( '<STR_LIT:b>' ) <EOL> c = tensor . bscalar ( '<STR_LIT:c>' ) <EOL> f = pfunc ( [ In ( a , allow_downcast = True ) , <EOL> In ( b , allow_downcast = False ) , <EOL> In ( c , allow_downcast = None ) ] , <EOL> ( a + b + c ) ) <EOL> assert numpy . all ( f ( [ <NUM_LIT:3> ] , [ <NUM_LIT:6> ] , <NUM_LIT:1> ) == <NUM_LIT:10> ) <EOL> self . assertRaises ( TypeError , f , <EOL> [ <NUM_LIT:3> ] , numpy . array ( [ <NUM_LIT:6> ] , dtype = '<STR_LIT>' ) , <NUM_LIT:1> ) <EOL> assert numpy . all ( f ( [ <NUM_LIT:2> ** <NUM_LIT:20> ] , numpy . ones ( <NUM_LIT:1> , dtype = '<STR_LIT>' ) , <NUM_LIT:1> ) == <NUM_LIT:2> ) <EOL> self . assertRaises ( TypeError , f , [ <NUM_LIT:3> ] , [ <NUM_LIT> ] , <NUM_LIT:1> ) <EOL> self . assertRaises ( TypeError , f , [ <NUM_LIT:3> ] , [ <NUM_LIT:6> ] , <NUM_LIT> ) <EOL> def test_param_allow_downcast_floatX ( self ) : <EOL> a = tensor . fscalar ( '<STR_LIT:a>' ) <EOL> b = tensor . fscalar ( '<STR_LIT:b>' ) <EOL> c = tensor . fscalar ( '<STR_LIT:c>' ) <EOL> f = pfunc ( [ In ( a , allow_downcast = True ) , <EOL> In ( b , allow_downcast = False ) , <EOL> In ( c , allow_downcast = None ) ] , <EOL> ( a + b + c ) ) <EOL> assert numpy . all ( f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) == <NUM_LIT:0> ) <EOL> assert numpy . allclose ( f ( <NUM_LIT:0.1> , <NUM_LIT:0> , <NUM_LIT:0> ) , <NUM_LIT:0.1> ) <EOL> self . assertRaises ( TypeError , f , <NUM_LIT:0> , <NUM_LIT:0.1> , <NUM_LIT:0> ) <EOL> if config . floatX == '<STR_LIT>' : <EOL> assert numpy . allclose ( f ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0.1> ) , <NUM_LIT:0.1> ) <EOL> else : <EOL> self . assertRaises ( TypeError , f , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0.1> ) <EOL> def test_param_allow_downcast_vector_floatX ( self ) : <EOL> a = tensor . fvector ( '<STR_LIT:a>' ) <EOL> b = tensor . fvector ( '<STR_LIT:b>' ) <EOL> c = tensor . fvector ( '<STR_LIT:c>' ) <EOL> f = pfunc ( [ In ( a , allow_downcast = True ) , <EOL> In ( b , allow_downcast = False ) , <EOL> In ( c , allow_downcast = None ) ] , <EOL> ( a + b + c ) ) <EOL> z = [ <NUM_LIT:0> ] <EOL> assert numpy . all ( f ( z , z , z ) == <NUM_LIT:0> ) <EOL> assert numpy . allclose ( f ( [ <NUM_LIT:0.1> ] , z , z ) , <NUM_LIT:0.1> ) <EOL> self . assertRaises ( TypeError , f , z , [ <NUM_LIT:0.1> ] , z ) <EOL> self . assertRaises ( TypeError , f , z , z , [ <NUM_LIT:0.1> ] ) <EOL> def test_allow_input_downcast_int ( self ) : <EOL> a = tensor . wvector ( '<STR_LIT:a>' ) <EOL> b = tensor . bvector ( '<STR_LIT:b>' ) <EOL> c = tensor . bscalar ( '<STR_LIT:c>' ) <EOL> f = pfunc ( [ a , b , c ] , ( a + b + c ) , allow_input_downcast = True ) <EOL> assert f ( [ <NUM_LIT:2> ** <NUM_LIT:20> ] , [ <NUM_LIT:1> ] , <NUM_LIT:0> ) == <NUM_LIT:1> <EOL> assert f ( [ <NUM_LIT:3> ] , [ <NUM_LIT> ] , <NUM_LIT:0> ) == <NUM_LIT> <EOL> assert f ( [ <NUM_LIT:3> ] , [ <NUM_LIT:1> ] , <NUM_LIT> ) == <NUM_LIT> <EOL> g = pfunc ( [ a , b , c ] , ( a + b + c ) , allow_input_downcast = False ) <EOL> assert numpy . all ( g ( [ <NUM_LIT:3> ] , [ <NUM_LIT:6> ] , <NUM_LIT:0> ) == <NUM_LIT:9> ) <EOL> self . assertRaises ( TypeError , g , <EOL> [ <NUM_LIT:3> ] , numpy . array ( [ <NUM_LIT:6> ] , dtype = '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertRaises ( TypeError , g , [ <NUM_LIT:3> ] , [ <NUM_LIT> ] , <NUM_LIT:0> ) <EOL> h = pfunc ( [ a , b , c ] , ( a + b + c ) ) <EOL> assert numpy . all ( h ( [ <NUM_LIT:3> ] , [ <NUM_LIT:6> ] , <NUM_LIT:0> ) == <NUM_LIT:9> ) <EOL> self . assertRaises ( TypeError , h , <EOL> [ <NUM_LIT:3> ] , numpy . array ( [ <NUM_LIT:6> ] , dtype = '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertRaises ( TypeError , h , [ <NUM_LIT:3> ] , [ <NUM_LIT> ] , <NUM_LIT:0> ) <EOL> def test_allow_downcast_floatX ( self ) : <EOL> a = tensor . fscalar ( '<STR_LIT:a>' ) <EOL> b = tensor . fvector ( '<STR_LIT:b>' ) <EOL> f = pfunc ( [ a , b ] , ( a + b ) , allow_input_downcast = True ) <EOL> g = pfunc ( [ a , b ] , ( a + b ) , allow_input_downcast = False ) <EOL> h = pfunc ( [ a , b ] , ( a + b ) , allow_input_downcast = None ) <EOL> assert numpy . all ( f ( <NUM_LIT:0> , [ <NUM_LIT:0> ] ) == <NUM_LIT:0> ) <EOL> assert numpy . all ( g ( <NUM_LIT:0> , [ <NUM_LIT:0> ] ) == <NUM_LIT:0> ) <EOL> assert numpy . all ( h ( <NUM_LIT:0> , [ <NUM_LIT:0> ] ) == <NUM_LIT:0> ) <EOL> assert numpy . allclose ( f ( <NUM_LIT:0> , [ <NUM_LIT:0.1> ] ) , <NUM_LIT:0.1> ) <EOL> self . assertRaises ( TypeError , g , <NUM_LIT:0> , [ <NUM_LIT:0.1> ] ) <EOL> self . assertRaises ( TypeError , h , <NUM_LIT:0> , [ <NUM_LIT:0.1> ] ) <EOL> assert numpy . allclose ( f ( <NUM_LIT:0.1> , [ <NUM_LIT:0> ] ) , <NUM_LIT:0.1> ) <EOL> self . assertRaises ( TypeError , g , <NUM_LIT:0.1> , [ <NUM_LIT:0> ] ) <EOL> if config . floatX == '<STR_LIT>' : <EOL> assert numpy . allclose ( h ( <NUM_LIT:0.1> , [ <NUM_LIT:0> ] ) , <NUM_LIT:0.1> ) <EOL> else : <EOL> self . assertRaises ( TypeError , h , <NUM_LIT:0.1> , [ <NUM_LIT:0> ] ) <EOL> def test_update ( self ) : <EOL> """<STR_LIT>""" <EOL> x = shared ( <NUM_LIT:0> ) <EOL> assign = pfunc ( [ ] , [ ] , updates = { x : <NUM_LIT:3> } ) <EOL> assign ( ) <EOL> self . assertTrue ( x . get_value ( ) == <NUM_LIT:3> ) <EOL> x . set_value ( <NUM_LIT:0> ) <EOL> inc = pfunc ( [ ] , [ ] , updates = { x : x + <NUM_LIT:1> } ) <EOL> inc ( ) <EOL> self . assertTrue ( x . get_value ( ) == <NUM_LIT:1> ) <EOL> x . set_value ( - <NUM_LIT:1> ) <EOL> y = shared ( <NUM_LIT:2> ) <EOL> inc_by_y = pfunc ( [ ] , [ ] , updates = { x : x + y } ) <EOL> inc_by_y ( ) <EOL> self . assertTrue ( x . get_value ( ) == <NUM_LIT:1> ) <EOL> def test_update_err_broadcast ( self ) : <EOL> data = numpy . random . rand ( <NUM_LIT:10> , <NUM_LIT:10> ) . astype ( '<STR_LIT>' ) <EOL> output_var = shared ( name = "<STR_LIT>" , value = data ) <EOL> self . assertRaises ( TypeError , theano . function , inputs = [ ] , outputs = [ ] , <EOL> updates = { output_var : output_var . sum ( ) . dimshuffle ( '<STR_LIT:x>' , '<STR_LIT:x>' ) } ) <EOL> def test_duplicate_updates ( self ) : <EOL> x , y = dmatrices ( '<STR_LIT:x>' , '<STR_LIT:y>' ) <EOL> z = shared ( numpy . ones ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) ) <EOL> self . assertRaises ( ValueError , theano . function , [ x , y ] , [ z ] , <EOL> updates = [ ( z , ( z + x + y ) ) , ( z , ( z - x ) ) ] ) <EOL> def test_givens ( self ) : <EOL> x = shared ( <NUM_LIT:0> ) <EOL> assign = pfunc ( [ ] , x , givens = { x : <NUM_LIT:3> } ) <EOL> assert assign ( ) == <NUM_LIT:3> <EOL> assert x . get_value ( borrow = True ) == <NUM_LIT:0> <EOL> y = tensor . ivector ( ) <EOL> f = pfunc ( [ y ] , ( y * x ) , givens = { x : <NUM_LIT:6> } ) <EOL> assert numpy . all ( f ( [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) == [ <NUM_LIT:6> , <NUM_LIT:6> , <NUM_LIT:6> ] ) <EOL> assert x . get_value ( ) == <NUM_LIT:0> <EOL> z = tensor . ivector ( ) <EOL> c = z * y <EOL> f = pfunc ( [ y ] , ( c + <NUM_LIT:7> ) , <EOL> givens = { z : theano . _asarray ( [ <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> ] , dtype = '<STR_LIT>' ) } ) <EOL> assert numpy . all ( f ( [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) == [ <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> ] ) <EOL> assert x . get_value ( ) == <NUM_LIT:0> <EOL> def test_clone0 ( self ) : <EOL> x = shared ( numpy . asarray ( [ <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> ] ) ) <EOL> y = shared ( numpy . asarray ( [ <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> ] ) ) <EOL> z = shared ( numpy . asarray ( [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] ) ) <EOL> up = pfunc ( [ ] , [ ] , updates = { <EOL> x : ( x * <NUM_LIT:5> ) , <EOL> y : ( ( x * <NUM_LIT:5> ) + y ) , <EOL> z : ( ( ( x * <NUM_LIT:5> ) + y ) ** z ) } ) <EOL> up ( ) <EOL> assert numpy . all ( x . get_value ( ) == <NUM_LIT:20> ) <EOL> assert numpy . all ( y . get_value ( ) == <NUM_LIT> ) <EOL> assert numpy . all ( z . get_value ( ) == ( <NUM_LIT> ** <NUM_LIT:2> ) ) <EOL> def test_default_updates ( self ) : <EOL> x = shared ( <NUM_LIT:0> ) <EOL> x . default_update = x + <NUM_LIT:1> <EOL> f = pfunc ( [ ] , [ x ] ) <EOL> f ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:1> <EOL> del x . default_update <EOL> f ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:2> <EOL> g = pfunc ( [ ] , [ x ] ) <EOL> g ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:2> <EOL> def test_no_default_updates ( self ) : <EOL> x = shared ( <NUM_LIT:0> ) <EOL> y = shared ( <NUM_LIT:1> ) <EOL> x . default_update = x + <NUM_LIT:2> <EOL> f1 = pfunc ( [ ] , [ x ] , no_default_updates = True ) <EOL> f1 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:0> <EOL> f2 = pfunc ( [ ] , [ x ] , no_default_updates = [ x ] ) <EOL> f2 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:0> <EOL> f3 = pfunc ( [ ] , [ x ] , no_default_updates = [ x , y ] ) <EOL> f3 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:0> <EOL> f4 = pfunc ( [ ] , [ x ] , no_default_updates = [ y ] ) <EOL> f4 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:2> <EOL> f5 = pfunc ( [ ] , [ x ] , no_default_updates = [ ] ) <EOL> f5 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:4> <EOL> f5 = pfunc ( [ ] , [ x ] , no_default_updates = False ) <EOL> f5 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:6> <EOL> self . assertRaises ( TypeError , pfunc , [ ] , [ x ] , no_default_updates = ( x ) ) <EOL> self . assertRaises ( TypeError , pfunc , [ ] , [ x ] , no_default_updates = x ) <EOL> self . assertRaises ( TypeError , pfunc , [ ] , [ x ] , <EOL> no_default_updates = '<STR_LIT>' ) <EOL> g1 = pfunc ( [ ] , [ x ] , updates = [ ( x , ( x - <NUM_LIT:1> ) ) ] , no_default_updates = True ) <EOL> g1 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:5> <EOL> g2 = pfunc ( [ ] , [ x ] , updates = [ ( x , ( x - <NUM_LIT:1> ) ) ] , no_default_updates = [ x ] ) <EOL> g2 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:4> <EOL> g3 = pfunc ( [ ] , [ x ] , updates = [ ( x , ( x - <NUM_LIT:1> ) ) ] , no_default_updates = [ x , y ] ) <EOL> g3 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:3> <EOL> g4 = pfunc ( [ ] , [ x ] , updates = [ ( x , ( x - <NUM_LIT:1> ) ) ] , no_default_updates = [ y ] ) <EOL> g4 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:2> <EOL> g5 = pfunc ( [ ] , [ x ] , updates = [ ( x , ( x - <NUM_LIT:1> ) ) ] , no_default_updates = [ ] ) <EOL> g5 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:1> <EOL> g5 = pfunc ( [ ] , [ x ] , updates = [ ( x , ( x - <NUM_LIT:1> ) ) ] , no_default_updates = False ) <EOL> g5 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:0> <EOL> def test_default_updates_expressions ( self ) : <EOL> x = shared ( <NUM_LIT:0> ) <EOL> y = shared ( <NUM_LIT:1> ) <EOL> a = lscalar ( '<STR_LIT:a>' ) <EOL> z = a * x <EOL> x . default_update = x + y <EOL> f1 = pfunc ( [ a ] , z ) <EOL> f1 ( <NUM_LIT:12> ) <EOL> assert x . get_value ( ) == <NUM_LIT:1> <EOL> f2 = pfunc ( [ a ] , z , no_default_updates = True ) <EOL> assert f2 ( <NUM_LIT:7> ) == <NUM_LIT:7> <EOL> assert x . get_value ( ) == <NUM_LIT:1> <EOL> f3 = pfunc ( [ a ] , z , no_default_updates = [ x ] ) <EOL> assert f3 ( <NUM_LIT:9> ) == <NUM_LIT:9> <EOL> assert x . get_value ( ) == <NUM_LIT:1> <EOL> def test_default_updates_multiple ( self ) : <EOL> x = shared ( <NUM_LIT:0> ) <EOL> y = shared ( <NUM_LIT:1> ) <EOL> x . default_update = x - <NUM_LIT:1> <EOL> y . default_update = y + <NUM_LIT:1> <EOL> f1 = pfunc ( [ ] , [ x , y ] ) <EOL> f1 ( ) <EOL> assert x . get_value ( ) == - <NUM_LIT:1> <EOL> assert y . get_value ( ) == <NUM_LIT:2> <EOL> f2 = pfunc ( [ ] , [ x , y ] , updates = [ ( x , ( x - <NUM_LIT:2> ) ) ] , no_default_updates = [ y ] ) <EOL> f2 ( ) <EOL> assert x . get_value ( ) == - <NUM_LIT:3> <EOL> assert y . get_value ( ) == <NUM_LIT:2> <EOL> f3 = pfunc ( [ ] , [ x , y ] , updates = [ ( x , ( x - <NUM_LIT:2> ) ) ] , no_default_updates = True ) <EOL> f3 ( ) <EOL> assert x . get_value ( ) == - <NUM_LIT:5> <EOL> assert y . get_value ( ) == <NUM_LIT:2> <EOL> f4 = pfunc ( [ ] , [ x , y ] , updates = [ ( y , ( y - <NUM_LIT:2> ) ) ] ) <EOL> f4 ( ) <EOL> assert x . get_value ( ) == - <NUM_LIT:6> <EOL> assert y . get_value ( ) == <NUM_LIT:0> <EOL> def test_default_updates_chained ( self ) : <EOL> x = shared ( <NUM_LIT:2> ) <EOL> y = shared ( <NUM_LIT:1> ) <EOL> z = shared ( - <NUM_LIT:1> ) <EOL> x . default_update = x - y <EOL> y . default_update = z <EOL> z . default_update = z - <NUM_LIT:1> <EOL> f1 = pfunc ( [ ] , [ x ] ) <EOL> f1 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:1> <EOL> assert y . get_value ( ) == - <NUM_LIT:1> <EOL> assert z . get_value ( ) == - <NUM_LIT:2> <EOL> f2 = pfunc ( [ ] , [ x , y ] ) <EOL> f2 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:2> <EOL> assert y . get_value ( ) == - <NUM_LIT:2> <EOL> assert z . get_value ( ) == - <NUM_LIT:3> <EOL> f3 = pfunc ( [ ] , [ y ] ) <EOL> f3 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:2> <EOL> assert y . get_value ( ) == - <NUM_LIT:3> <EOL> assert z . get_value ( ) == - <NUM_LIT:4> <EOL> f4 = pfunc ( [ ] , [ x , y ] , no_default_updates = [ x ] ) <EOL> f4 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:2> <EOL> assert y . get_value ( ) == - <NUM_LIT:4> <EOL> assert z . get_value ( ) == - <NUM_LIT:5> <EOL> f5 = pfunc ( [ ] , [ x , y , z ] , no_default_updates = [ z ] ) <EOL> f5 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:6> <EOL> assert y . get_value ( ) == - <NUM_LIT:5> <EOL> assert z . get_value ( ) == - <NUM_LIT:5> <EOL> def test_default_updates_input ( self ) : <EOL> x = shared ( <NUM_LIT:0> ) <EOL> y = shared ( <NUM_LIT:1> ) <EOL> if theano . configdefaults . python_int_bitwidth ( ) == <NUM_LIT:32> : <EOL> a = iscalar ( '<STR_LIT:a>' ) <EOL> else : <EOL> a = lscalar ( '<STR_LIT:a>' ) <EOL> x . default_update = y <EOL> y . default_update = y + a <EOL> f1 = pfunc ( [ ] , x , no_default_updates = True ) <EOL> f1 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:0> <EOL> assert y . get_value ( ) == <NUM_LIT:1> <EOL> f2 = pfunc ( [ ] , x , no_default_updates = [ x ] ) <EOL> f2 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:0> <EOL> assert y . get_value ( ) == <NUM_LIT:1> <EOL> f3 = pfunc ( [ ] , x , no_default_updates = [ y ] ) <EOL> f3 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:1> <EOL> assert y . get_value ( ) == <NUM_LIT:1> <EOL> f4 = pfunc ( [ a ] , x ) <EOL> f4 ( <NUM_LIT:2> ) <EOL> assert x . get_value ( ) == <NUM_LIT:1> <EOL> assert y . get_value ( ) == <NUM_LIT:3> <EOL> f5 = pfunc ( [ ] , x , updates = { y : ( y - <NUM_LIT:1> ) } ) <EOL> f5 ( ) <EOL> assert x . get_value ( ) == <NUM_LIT:3> <EOL> assert y . get_value ( ) == <NUM_LIT:2> <EOL> self . assertRaises ( theano . gof . MissingInputError , pfunc , [ ] , x ) <EOL> def test_default_updates_partial_graph ( self ) : <EOL> a = shared ( <NUM_LIT:0> ) <EOL> a . default_update = a + <NUM_LIT:1> <EOL> b = <NUM_LIT:2> * a <EOL> f = pfunc ( [ b ] , b ) <EOL> assert a . get_value ( ) == <NUM_LIT:0> <EOL> f ( <NUM_LIT> ) <EOL> assert a . get_value ( ) == <NUM_LIT:0> <EOL> def test_givens_replaces_shared_variable ( self ) : <EOL> a = shared ( <NUM_LIT:1.> , '<STR_LIT:a>' ) <EOL> a . default_update = a + <NUM_LIT> <EOL> b = tensor . dscalar ( '<STR_LIT:b>' ) <EOL> c = a + <NUM_LIT:10> <EOL> f = pfunc ( [ b ] , c , givens = { a : b } ) <EOL> assert len ( f . maker . fgraph . inputs ) == <NUM_LIT:1> <EOL> assert len ( f . maker . fgraph . outputs ) == <NUM_LIT:1> <EOL> def test_givens_replaces_shared_variable2 ( self ) : <EOL> a = shared ( <NUM_LIT:1.> , '<STR_LIT:a>' ) <EOL> a . default_update = a + <NUM_LIT:3> <EOL> c = a + <NUM_LIT:10> <EOL> f = pfunc ( [ ] , c , givens = { a : ( a + <NUM_LIT:10> ) } ) <EOL> assert f ( ) == <NUM_LIT> <EOL> assert f ( ) == <NUM_LIT> <EOL> def test_duplicate_inputs ( self ) : <EOL> x = theano . tensor . lscalar ( '<STR_LIT:x>' ) <EOL> self . assertRaises ( theano . compile . UnusedInputError , <EOL> theano . function , [ x , x , x ] , x ) <EOL> def test_update_same ( self ) : <EOL> a = shared ( <NUM_LIT:1.> , '<STR_LIT:a>' ) <EOL> b = shared ( numpy . ones ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) , '<STR_LIT:b>' ) <EOL> f = theano . function ( [ ] , [ ] , updates = [ ( a , a ) , ( b , ( <NUM_LIT:2> * b ) ) ] ) <EOL> g = theano . function ( [ ] , [ ] , updates = [ ( a , ( a * <NUM_LIT:2> ) ) , ( b , b ) ] ) <EOL> f ( ) <EOL> assert a . get_value ( borrow = True ) . shape == ( ) , a . get_value ( ) <EOL> assert b . get_value ( borrow = True ) . shape == ( <NUM_LIT:2> , <NUM_LIT:3> ) , b . get_value ( ) <EOL> g ( ) <EOL> assert a . get_value ( borrow = True ) . shape == ( ) , a . get_value ( ) <EOL> assert b . get_value ( borrow = True ) . shape == ( <NUM_LIT:2> , <NUM_LIT:3> ) , b . get_value ( ) <EOL> def test_update_equiv ( self ) : <EOL> a = shared ( <NUM_LIT:1.> , '<STR_LIT:a>' ) <EOL> b = shared ( numpy . ones ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) , '<STR_LIT:b>' ) <EOL> f = theano . function ( [ ] , [ ] , updates = [ ( a , a ) , ( b , ( <NUM_LIT:2> * b - b ) ) ] ) <EOL> g = theano . function ( [ ] , [ ] , updates = [ ( a , ( a * <NUM_LIT:2> - a ) ) , ( b , b ) ] ) <EOL> f ( ) <EOL> assert a . get_value ( borrow = True ) . shape == ( ) , a . get_value ( ) <EOL> assert b . get_value ( borrow = True ) . shape == ( <NUM_LIT:2> , <NUM_LIT:3> ) , b . get_value ( ) <EOL> g ( ) <EOL> assert a . get_value ( borrow = True ) . shape == ( ) , a . get_value ( ) <EOL> assert b . get_value ( borrow = True ) . shape == ( <NUM_LIT:2> , <NUM_LIT:3> ) , b . get_value ( ) <EOL> class Test_aliasing_rules ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def shared ( self , x ) : <EOL> return tensor . _shared ( x ) <EOL> def test_shared_constructor_copies ( self ) : <EOL> orig_a = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> A = self . shared ( orig_a ) <EOL> assert not numpy . may_share_memory ( orig_a , data_of ( A ) ) <EOL> assert not numpy . may_share_memory ( A . get_value ( borrow = False ) , <EOL> data_of ( A ) ) <EOL> def test_sparse_input_aliasing_affecting_inplace_operations ( self ) : <EOL> try : <EOL> import scipy . sparse as sp <EOL> except ImportError : <EOL> pass <EOL> from theano . sparse import enable_sparse <EOL> if enable_sparse == False : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> from theano import sparse <EOL> x = sparse . SparseType ( '<STR_LIT>' , dtype = '<STR_LIT>' ) ( ) <EOL> y = sparse . SparseType ( '<STR_LIT>' , dtype = '<STR_LIT>' ) ( ) <EOL> f = theano . function ( [ theano . In ( x , mutable = True ) , <EOL> theano . In ( y , mutable = True ) ] , <EOL> ( x + y ) + ( x + y ) ) <EOL> m = sp . csc_matrix ( numpy . asarray ( <EOL> [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ] , dtype = '<STR_LIT>' ) ) <EOL> bogus_vals = f ( m , m ) <EOL> m = sp . csc_matrix ( numpy . asarray ( <EOL> [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ] , dtype = '<STR_LIT>' ) ) <EOL> m_copy = m . copy ( ) <EOL> vals = f ( m , m_copy ) <EOL> assert numpy . allclose ( vals . todense ( ) , bogus_vals . todense ( ) ) <EOL> def test_input_aliasing_affecting_inplace_operations ( self ) : <EOL> x = theano . tensor . dvector ( ) <EOL> y = theano . tensor . dvector ( ) <EOL> m1 = theano . tensor . dmatrix ( ) <EOL> m2 = theano . tensor . dmatrix ( ) <EOL> f = theano . function ( [ theano . In ( x , mutable = True ) , <EOL> theano . In ( y , mutable = True ) , <EOL> theano . In ( m1 , mutable = True ) , <EOL> theano . In ( m2 , mutable = True ) ] , <EOL> theano . dot ( ( x * <NUM_LIT:2> ) , m1 ) + theano . dot ( ( y * <NUM_LIT:3> ) , m2 ) ) <EOL> v = numpy . asarray ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , dtype = '<STR_LIT>' ) <EOL> m = numpy . asarray ( [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ] , dtype = '<STR_LIT>' ) <EOL> bogus_vals = f ( v , v , m , m ) <EOL> v = numpy . asarray ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , dtype = '<STR_LIT>' ) <EOL> m = numpy . asarray ( [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] ] , dtype = '<STR_LIT>' ) <EOL> m_copy = m . copy ( ) <EOL> v_copy = v . copy ( ) <EOL> vals = f ( v , v_copy , m , m_copy ) <EOL> assert numpy . allclose ( vals , bogus_vals ) <EOL> def test_partial_input_aliasing_affecting_inplace_operations ( self ) : <EOL> x = theano . tensor . dvector ( ) <EOL> y = theano . tensor . dvector ( ) <EOL> z = theano . tensor . dvector ( ) <EOL> m1 = theano . tensor . dmatrix ( ) <EOL> m2 = theano . tensor . dmatrix ( ) <EOL> m3 = theano . tensor . dmatrix ( ) <EOL> f = theano . function ( <EOL> [ theano . In ( x , mutable = True ) , <EOL> theano . In ( y , mutable = True ) , <EOL> theano . In ( z , mutable = True ) , <EOL> theano . In ( m1 , mutable = True ) , <EOL> theano . In ( m2 , mutable = True ) , <EOL> theano . In ( m3 , mutable = True ) ] , <EOL> ( theano . dot ( ( x * <NUM_LIT:2> ) , m1 ) <EOL> + theano . dot ( ( y * <NUM_LIT:3> ) , m2 ) <EOL> + theano . dot ( ( z * <NUM_LIT:4> ) , m3 ) ) ) <EOL> v = numpy . asarray ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , dtype = '<STR_LIT>' ) <EOL> m = numpy . asarray ( [ [ <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> ] ] , dtype = '<STR_LIT>' ) <EOL> bogus_vals = f ( v [ : <NUM_LIT:2> ] , v [ <NUM_LIT:1> : <NUM_LIT:3> ] , v [ <NUM_LIT:2> : <NUM_LIT:4> ] , m , m , m ) <EOL> v = numpy . asarray ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , dtype = '<STR_LIT>' ) <EOL> m = numpy . asarray ( [ [ <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:1> ] ] , dtype = '<STR_LIT>' ) <EOL> m_copy1 = m . copy ( ) <EOL> v_copy1 = v . copy ( ) <EOL> m_copy2 = m . copy ( ) <EOL> v_copy2 = v . copy ( ) <EOL> vals = f ( v [ : <NUM_LIT:2> ] , v_copy1 [ <NUM_LIT:1> : <NUM_LIT:3> ] , v_copy2 [ <NUM_LIT:2> : <NUM_LIT:4> ] , m , m_copy1 , m_copy2 ) <EOL> assert numpy . allclose ( vals , bogus_vals ) <EOL> def test_potential_output_aliasing_induced_by_updates ( self ) : <EOL> A = self . shared ( numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) <EOL> B = self . shared ( numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) <EOL> C = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> D = tensor . dmatrix ( ) <EOL> DD = D + <NUM_LIT:5> <EOL> f = pfunc ( [ D ] , [ ] , updates = [ ( A , D ) , ( B , D ) ] ) <EOL> f ( C ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> f = pfunc ( [ D ] , [ ] , updates = [ ( A , D [ : ] ) , ( B , D ) ] ) <EOL> f ( C ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> f = pfunc ( [ D ] , [ ] , updates = [ ( A , ( D + <NUM_LIT:5> ) ) , ( B , D [ : ] ) ] ) <EOL> f ( C ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> f = pfunc ( [ D ] , [ ] , updates = [ ( A , ( D + <NUM_LIT:5> ) ) , ( B , D ) ] ) <EOL> f ( C ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> f = pfunc ( [ D ] , DD , updates = [ ( A , DD [ : <NUM_LIT:1> ] ) , ( B , DD ) ] ) <EOL> R = f ( C ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> assert not numpy . may_share_memory ( R , data_of ( B ) ) <EOL> assert not numpy . may_share_memory ( R , data_of ( A ) ) <EOL> f = pfunc ( [ D ] , DD , updates = [ ( A , DD [ : <NUM_LIT:1> ] ) , ( B , ( DD [ : <NUM_LIT:1> ] * <NUM_LIT:2> ) ) ] ) <EOL> R = f ( C ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> assert not numpy . may_share_memory ( R , data_of ( B ) ) <EOL> assert not numpy . may_share_memory ( R , data_of ( A ) ) <EOL> f = pfunc ( [ D ] , ( DD * <NUM_LIT:4> ) , <EOL> updates = [ ( A , ( DD [ : <NUM_LIT:1> ] * <NUM_LIT:3> ) ) , ( B , ( DD [ : <NUM_LIT:1> ] * <NUM_LIT:2> ) ) ] ) <EOL> R = f ( C ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> assert not numpy . may_share_memory ( R , data_of ( B ) ) <EOL> assert not numpy . may_share_memory ( R , data_of ( A ) ) <EOL> f = pfunc ( [ D ] , ( DD * <NUM_LIT:4> ) , <EOL> updates = [ ( A , ( DD [ : <NUM_LIT:1> ] * <NUM_LIT:3> ) ) , ( B , ( DD [ : <NUM_LIT:1> ] * <NUM_LIT:3> ) ) ] ) <EOL> R = f ( C ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> assert not numpy . may_share_memory ( R , data_of ( B ) ) <EOL> assert not numpy . may_share_memory ( R , data_of ( A ) ) <EOL> def test_no_aliasing_0 ( self ) : <EOL> A = self . shared ( numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) + <NUM_LIT> ) <EOL> B = self . shared ( numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) - <NUM_LIT> ) <EOL> f = pfunc ( [ ] , [ ] , updates = [ ( A , B ) ] ) <EOL> f ( ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> def test_no_aliasing_1 ( self ) : <EOL> A = self . shared ( numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) + <NUM_LIT> ) <EOL> B = self . shared ( numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) - <NUM_LIT> ) <EOL> C = tensor . dmatrix ( ) <EOL> f = pfunc ( [ C ] , [ ] , updates = [ ( A , B ) , ( B , C ) ] ) <EOL> z = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) <EOL> f ( z ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> assert not numpy . may_share_memory ( z , data_of ( B ) ) <EOL> assert numpy . all ( data_of ( B ) == z ) <EOL> def test_no_aliasing_2 ( self ) : <EOL> orig_a = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) + <NUM_LIT> <EOL> orig_b = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) - <NUM_LIT> <EOL> A = self . shared ( orig_a ) <EOL> B = self . shared ( orig_b ) <EOL> data_of_a = data_of ( A ) <EOL> data_of_b = data_of ( B ) <EOL> f = pfunc ( [ ] , [ ] , updates = [ ( A , B ) , ( B , A ) ] ) <EOL> f ( ) <EOL> assert numpy . all ( data_of ( A ) == - <NUM_LIT> ) <EOL> assert numpy . all ( data_of ( B ) == + <NUM_LIT> ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> assert numpy . may_share_memory ( data_of ( A ) , data_of_b ) <EOL> assert numpy . may_share_memory ( data_of ( B ) , data_of_a ) <EOL> def test_no_aliasing_2b ( self ) : <EOL> orig_a = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) + <NUM_LIT> <EOL> orig_b = numpy . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) - <NUM_LIT> <EOL> A = self . shared ( orig_a ) <EOL> B = self . shared ( orig_b ) <EOL> data_of_a = data_of ( A ) <EOL> data_of_b = data_of ( B ) <EOL> f = pfunc ( [ ] , [ ] , updates = [ ( A , B [ : , : : - <NUM_LIT:1> ] ) , ( B , A . T ) ] ) <EOL> f ( ) <EOL> assert numpy . all ( data_of ( A ) == - <NUM_LIT> ) <EOL> assert numpy . all ( data_of ( B ) == + <NUM_LIT> ) <EOL> assert not numpy . may_share_memory ( data_of ( A ) , data_of ( B ) ) <EOL> if theano . config . mode not in [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> assert numpy . all ( data_of ( A ) < <NUM_LIT:5> ) <EOL> data_of_b += <NUM_LIT:10> <EOL> assert numpy . all ( data_of ( A ) > <NUM_LIT:5> ) <EOL> data_of_b -= <NUM_LIT:10> <EOL> assert numpy . all ( data_of ( B ) < <NUM_LIT:5> ) <EOL> data_of_a += <NUM_LIT:10> <EOL> assert numpy . all ( data_of ( B ) > <NUM_LIT:5> ) <EOL> data_of_a -= <NUM_LIT:10> <EOL> assert numpy . may_share_memory ( data_of ( A ) , data_of_b ) <EOL> assert numpy . may_share_memory ( data_of ( B ) , data_of_a ) <EOL> class Test_rebuild_strict ( unittest . TestCase ) : <EOL> def test1 ( self ) : <EOL> w = tensor . imatrix ( ) <EOL> x , y = tensor . ivectors ( '<STR_LIT:x>' , '<STR_LIT:y>' ) <EOL> z = x * y <EOL> f = theano . function ( [ w , y ] , z , givens = [ ( x , w ) ] , rebuild_strict = False ) <EOL> z_val = f ( numpy . ones ( ( <NUM_LIT:3> , <NUM_LIT:5> ) , dtype = '<STR_LIT>' ) , numpy . arange ( <NUM_LIT:5> , dtype = '<STR_LIT>' ) ) <EOL> assert z_val . ndim == <NUM_LIT:2> <EOL> assert numpy . all ( z_val == numpy . ones ( ( <NUM_LIT:3> , <NUM_LIT:5> ) ) * numpy . arange ( <NUM_LIT:5> ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> theano . config . mode = '<STR_LIT>' <EOL> Test_pfunc ( ) . test_default_scalar_container ( ) </s>
