<commit_before>import unittest

import numpy

import chainer
from chainer import cuda
from chainer import links
from chainer.testing import attr


class TestMGU(unittest.TestCase):

    in_size = 4
    out_size = 5

    def setUp(self):
        self.h = numpy.random.uniform(
            -1, 1, (3, self.out_size)).astype(numpy.float32)
        self.x = numpy.random.uniform(
            -1, 1, (3, self.in_size)).astype(numpy.float32)
        self.gy = numpy.random.uniform(
            -1, 1, (3, self.out_size)).astype(numpy.float32)

        self.mgu = links.MGU(self.in_size, self.out_size)

    def check_forward(self, h_data, x_data):
        h = chainer.Variable(h_data)
        x = chainer.Variable(x_data)
        self.mgu(h, x)

    def test_forward_cpu(self):
        self.check_forward(self.h, self.x)

    @attr.gpu
    def test_forward_gpu(self):
        self.mgu.to_gpu()
        self.check_forward(cuda.to_gpu(self.h), cuda.to_gpu(self.x))


class TestStatefulMGU(unittest.TestCase):

    in_size = 4
    out_size = 5

    def setUp(self):
        self.x = numpy.random.uniform(
            -1, 1, (3, self.in_size)).astype(numpy.float32)
        self.gy = numpy.random.uniform(
            -1, 1, (3, self.out_size)).astype(numpy.float32)

        self.mgu = links.StatefulMGU(self.in_size, self.out_size)

    def check_forward(self, x_data):
        x = chainer.Variable(x_data)
        self.mgu(x)
        self.mgu(x)

    def test_forward_cpu(self):
        self.check_forward(self.x)

    @attr.gpu
    def test_forward_gpu(self):
        self.mgu.to_gpu()
        self.check_forward(cuda.to_gpu(self.x))<commit_msg>Add run_module<commit_after>import unittest

import numpy

import chainer
from chainer import cuda
from chainer import links
from chainer import testing
from chainer.testing import attr


class TestMGU(unittest.TestCase):

    in_size = 4
    out_size = 5

    def setUp(self):
        self.h = numpy.random.uniform(
            -1, 1, (3, self.out_size)).astype(numpy.float32)
        self.x = numpy.random.uniform(
            -1, 1, (3, self.in_size)).astype(numpy.float32)
        self.gy = numpy.random.uniform(
            -1, 1, (3, self.out_size)).astype(numpy.float32)

        self.mgu = links.MGU(self.in_size, self.out_size)

    def check_forward(self, h_data, x_data):
        h = chainer.Variable(h_data)
        x = chainer.Variable(x_data)
        self.mgu(h, x)

    def test_forward_cpu(self):
        self.check_forward(self.h, self.x)

    @attr.gpu
    def test_forward_gpu(self):
        self.mgu.to_gpu()
        self.check_forward(cuda.to_gpu(self.h), cuda.to_gpu(self.x))


class TestStatefulMGU(unittest.TestCase):

    in_size = 4
    out_size = 5

    def setUp(self):
        self.x = numpy.random.uniform(
            -1, 1, (3, self.in_size)).astype(numpy.float32)
        self.gy = numpy.random.uniform(
            -1, 1, (3, self.out_size)).astype(numpy.float32)

        self.mgu = links.StatefulMGU(self.in_size, self.out_size)

    def check_forward(self, x_data):
        x = chainer.Variable(x_data)
        self.mgu(x)
        self.mgu(x)

    def test_forward_cpu(self):
        self.check_forward(self.x)

    @attr.gpu
    def test_forward_gpu(self):
        self.mgu.to_gpu()
        self.check_forward(cuda.to_gpu(self.x))


testing.run_module(__name__, __file__)
{'fraction_non_alphanumeric': 0.12485065710872162, 'fraction_numerical': 0.017323775388291517, 'mean_word_length': 2.4849115504682624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6270512', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1220, 'n_words': 216}