def test_swap_SharedVariable(self):
        i = T.iscalar()
        x_list = theano.shared(value=numpy.random.rand(10).astype(config.floatX))

        x = T.scalar('x')
        # SharedVariable for tests, one of them has update
        y = theano.shared(value=1, name='y')
        z = theano.shared(value=2, name='z')
        m = theano.shared(value=0, name='m')

        # SharedVariable to replace
        y_rpl = theano.shared(value=3,name ='y_rpl')
        z_rpl = theano.shared(value=4, name='z_rpl')
        swap = {y:y_rpl, z:z_rpl}
        map_SV = {'y_rpl':y_rpl, 'z_rpl':z_rpl}

        out = x+y+z+m

        # Test for different linkers
        # for mode in ["FAST_RUN","FAST_COMPILE"]:
        second_time = False
        for mode in ["FAST_RUN","FAST_COMPILE"]:
            ori = theano.function([i], [out], mode=mode,
                                  updates=[(z,z+1),(m,m+2)],
                                  givens={x:x_list[i]})
            cpy = ori.copy(swap=swap)

            # run fuction several time
            ori(1), cpy(1),cpy(2)

            # assert same SharedVariable are update in different function
            if not second_time:
                # m should be updated 3 times
                assert m.get_value() == 6
                # z should be updated once
                assert z.get_value() == 3
                # z_rpl should be updated twice
                assert z_rpl.get_value() == 6 
                # y and y_rpl should not be updated
                assert y_rpl.get_value() == 3
                assert y.get_value() == 1
            elif second_time:
                # doule update for sharedvariable
                assert m.get_value() == 12
                assert z.get_value() == 4
                assert z_rpl.get_value() == 8
                assert y_rpl.get_value() == 3

            # test cpy function:
            # 2. SharedVariable is updatable -> values did update(z == 5)
            # 1. sharedvariable is swap ->  Rpl sharedvariables share storage
            names = map_SV.keys()
            for key in cpy.fn.storage_map:
                if key.name in names:
                    assert map_SV[key.name].container.storage[0] ==\
                           cpy.fn.storage_map[key][0]

            second_time = True
dataset/ETHPy150Open rizar/attention-lvcsr/libs/Theano/theano/compile/tests/test_function_module.py/T_function.test_swap_SharedVariable/original