@@ -0,0 +1,1936 @@
+import unittest%0A%0Aimport numpy%0A%0Aimport chainer%0Afrom chainer import cuda%0Afrom chainer import functions%0Afrom chainer import gradient_check%0A%0A%0Adef _sigmoid(x):%0A    xp = cuda.get_array_module(x)%0A    return 1 / (1 + xp.exp(-x))%0A%0A%0Adef _gru(func, h, x):%0A    xp = cuda.get_array_module(h, x)%0A%0A    r = _sigmoid(func.W_r.forward((x,))%5B0%5D + func.U_r.forward((h,))%5B0%5D)%0A    z = _sigmoid(func.W_z.forward((x,))%5B0%5D + func.U_z.forward((h,))%5B0%5D)%0A    h_bar = xp.tanh(func.W.forward((x,))%5B0%5D + func.U.forward((r * h,))%5B0%5D)%0A    y = (1 - z) * h + z * h_bar%0A    return y%0A%0A%0Aclass TestGRU(unittest.TestCase):%0A%0A    def setUp(self):%0A        self.func = functions.GRU(8)%0A        self.x = numpy.random.uniform(-1, 1, (3, 8)).astype(numpy.float32)%0A        self.h = numpy.random.uniform(-1, 1, (3, 8)).astype(numpy.float32)%0A        self.gy = numpy.random.uniform(-1, 1, (3, 8)).astype(numpy.float32)%0A%0A    def check_forward(self, h_data, x_data):%0A        h = chainer.Variable(h_data)%0A        x = chainer.Variable(x_data)%0A        y = self.func(h, x)%0A        self.assertEqual(y.data.dtype, numpy.float32)%0A%0A        y_expect = _gru(self.func, h_data, x_data)%0A        gradient_check.assert_allclose(y_expect, y.data)%0A%0A    def test_forward_cpu(self):%0A        self.check_forward(self.h, self.x)%0A%0A    def test_forward_gpu(self):%0A        self.func.to_gpu()%0A        self.check_forward(cuda.to_gpu(self.h),%0A                           cuda.to_gpu(self.x))%0A%0A    def check_backward(self, h_data, x_data, y_grad):%0A        h = chainer.Variable(h_data)%0A        x = chainer.Variable(x_data)%0A        y = self.func(h, x)%0A%0A        y.grad = y_grad%0A        y.backward()%0A%0A        f = lambda: _gru(self.func, h.data, x.data)%0A        gh, gx = gradient_check.numerical_grad(f, (h.data, x.data), (y.grad,))%0A%0A        # gradient_check.assert_allclose(gh, h.grad)%0A        # gradient_check.assert_allclose(gx, x.grad)%0A%0A    def test_backward(self):%0A        self.check_backward(self.h, self.x, self.gy)%0A

Write test for GRU