code: def test_copy_grad(self):
      def set_random_grad(link):
          link.cleargrads()
          x = np.random.normal(size=(1, 1)).astype(np.float32)
          y = link(x) * np.random.normal()
          F.sum(y).backward()
  
      # When source is not None and target is None
      a = L.Linear(1, 5)
      b = L.Linear(1, 5)
      set_random_grad(a)
      b.cleargrads()
      assert a.W.grad is not None
      assert a.b.grad is not None
      assert b.W.grad is None
      assert b.b.grad is None
      copy_param.copy_grad(target_link=b, source_link=a)
      np.testing.assert_almost_equal(a.W.grad, b.W.grad)
      np.testing.assert_almost_equal(a.b.grad, b.b.grad)
      assert a.W.grad is not b.W.grad
      assert a.b.grad is not b.b.grad
  
      # When both are not None
      a = L.Linear(1, 5)
      b = L.Linear(1, 5)
      set_random_grad(a)
      set_random_grad(b)
      assert a.W.grad is not None
      assert a.b.grad is not None
      assert b.W.grad is not None
      assert b.b.grad is not None
      copy_param.copy_grad(target_link=b, source_link=a)
      np.testing.assert_almost_equal(a.W.grad, b.W.grad)
      np.testing.assert_almost_equal(a.b.grad, b.b.grad)
      assert a.W.grad is not b.W.grad
      assert a.b.grad is not b.b.grad
  
      # When source is None and target is not None
      a = L.Linear(1, 5)
      b = L.Linear(1, 5)
      a.cleargrads()
      set_random_grad(b)
      assert a.W.grad is None
      assert a.b.grad is None
      assert b.W.grad is not None
      assert b.b.grad is not None
      copy_param.copy_grad(target_link=b, source_link=a)
      assert a.W.grad is None
      assert a.b.grad is None
      assert b.W.grad is None
      assert b.b.grad is None
  
      # When both are None
      a = L.Linear(1, 5)
      b = L.Linear(1, 5)
      a.cleargrads()
      b.cleargrads()
      assert a.W.grad is None
      assert a.b.grad is None
      assert b.W.grad is None
      assert b.b.grad is None
      copy_param.copy_grad(target_link=b, source_link=a)
      assert a.W.grad is None
      assert a.b.grad is None
      assert b.W.grad is None
      assert b.b.grad is None
  
file_path: chainerrl/tests/misc_tests/test_copy_param.py
imports: import unittest
  import chainer
  from chainer import functions
  from chainer import links
  import numpy
  from chainerrl.misc import copy_param
label_desc: Use image node_id 7 for calling the TestCopyParam obj's underlying member method code with example usage: obj.test_copy_grad() without return types