0940b083d3cdd0db46c867523e9a58b196e6e9d5,python/test/function/test_assign.py,,test_assign_forward_backward,#Any#Any#Any#,30

Before Change


def test_assign_forward_backward(seed, ctx, func_name):
    from nbla_test_utils import function_tester
    rng = np.random.RandomState(seed)
    inputs = [rng.randn(2, 3, 4).astype(np.float32) * 2 for _ in range(2)]
    grads = np.zeros((48,))
    function_tester(rng, F.assign, lambda dst, src: src, inputs, ref_grad=lambda *args: grads,
                    ctx=ctx, func_name=func_name, atol_f=1e-3, atol_b=1e-2)

After Change


def test_assign_forward_backward(seed, ctx, func_name):
    rng = np.random.RandomState(seed)
    dst = nn.Variable((2, 3, 4), need_grad=True)
    src = nn.Variable((2, 3, 4), need_grad=True)

    assign = F.assign(dst, src)

    src.d = np.random.random((2, 3, 4))
    assign.forward()

    assert np.allclose(dst.d, src.d)

    dummy = assign + np.random.random()

    dst.grad.zero()
    src.grad.zero()
    dummy.forward()
    dummy.backward()

    // assign should not propagate gradients
    assert np.all(dst.g == np.zeros((2, 3, 4)))
    assert np.all(src.g == np.zeros((2, 3, 4)))
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: sony/nnabla
Commit Name: 0940b083d3cdd0db46c867523e9a58b196e6e9d5
Time: 2019-01-09
Author: takuma.seno@gmail.com
File Name: python/test/function/test_assign.py
Class Name:
Method Name: test_assign_forward_backward


Project Name: horovod/horovod
Commit Name: 9dbf8ff1a0bf28ab804185f641cbce846a339c68
Time: 2019-03-01
Author: linhaibin.eric@gmail.com
File Name: examples/mxnet_imagenet_resnet50.py
Class Name:
Method Name: train_gluon


Project Name: pytorch/examples
Commit Name: 9faf2c65f74e3ee9bdaeedf9f3e5856727f0afe7
Time: 2017-12-04
Author: design@kaixhin.com
File Name: reinforcement_learning/reinforce.py
Class Name:
Method Name: finish_episode