@@ -0,0 +1,1223 @@
+import numpy as np%0Aimport unittest%0A%0Aimport chainer%0Afrom chainer import optimizers%0Afrom chainer import testing%0Afrom chainer.testing import attr%0A%0Afrom chainercv.links.model.ssd import GradientScaling%0A%0A%0Aclass SimpleLink(chainer.Link):%0A%0A    def __init__(self, w, g):%0A        super(SimpleLink, self).__init__()%0A        with self.init_scope():%0A            self.param = chainer.Parameter(w)%0A            self.param.grad = g%0A%0A%0Aclass TestGradientScaling(unittest.TestCase):%0A%0A    def setUp(self):%0A        self.target = SimpleLink(%0A            np.arange(6, dtype=np.float32).reshape(2, 3),%0A            np.arange(3, -3, -1, dtype=np.float32).reshape(2, 3))%0A%0A    def check_gradient_scaling(self):%0A        w = self.target.param.data%0A        g = self.target.param.grad%0A%0A        rate = 0.2%0A        expect = w - g * rate%0A%0A        opt = optimizers.SGD(lr=1)%0A        opt.setup(self.target)%0A        opt.add_hook(GradientScaling(rate))%0A        opt.update()%0A%0A        testing.assert_allclose(expect, w)%0A%0A    def test_gradient_scaling_cpu(self):%0A        self.check_gradient_scaling()%0A%0A    @attr.gpu%0A    def test_gradient_scaling_gpu(self):%0A        self.target.to_gpu()%0A        self.check_gradient_scaling()%0A%0A%0Atesting.run_module(__name__, __file__)%0A

add test