<commit_before>import unittest

import numpy

from chainer import cuda
from chainer import functions
from chainer import gradient_check
from chainer import testing
from chainer.testing import attr
from chainer.utils import type_check


@testing.parameterize(*testing.product_dict(
    [
        {'shape': (), 'pad_width': 1, 'mode': 'constant'},
        {'shape': (2, 3), 'pad_width': 1, 'mode': 'constant'},
        {'shape': (2, 3), 'pad_width': (1, 2), 'mode': 'constant'},
        {'shape': (2, 3), 'pad_width': ((1, 2), (3, 4)), 'mode': 'constant'},
    ],
    [
        {'dtype': numpy.float16},
        {'dtype': numpy.float32},
        {'dtype': numpy.float64},
    ]
))
class TestPadDefault(unittest.TestCase):

    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        out_shape = numpy.pad(self.x, self.pad_width, self.mode).shape
        self.g = numpy.random.uniform(-1, 1, out_shape).astype(self.dtype)
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype == numpy.float16:
            self.check_backward_options = {
                'atol': 2 ** -6, 'rtol': 2 ** -6}<commit_msg>old numpy does not allow ndarray as pad_width<commit_after>import unittest

import numpy

from chainer import cuda
from chainer import functions
from chainer import gradient_check
from chainer import testing
from chainer.testing import attr
from chainer.utils import type_check


@testing.parameterize(*testing.product_dict(
    [
        {'shape': (), 'pad_width': 1, 'mode': 'constant'},
        {'shape': (2, 3), 'pad_width': 1, 'mode': 'constant'},
        {'shape': (2, 3), 'pad_width': (1, 2), 'mode': 'constant'},
        {'shape': (2, 3), 'pad_width': ((1, 2), (3, 4)), 'mode': 'constant'},
    ],
    [
        {'dtype': numpy.float16},
        {'dtype': numpy.float32},
        {'dtype': numpy.float64},
    ]
))
# Old numpy does not work with ndarray as pad_width
@testing.with_requires('numpy>=1.10.1')
class TestPadDefault(unittest.TestCase):

    def setUp(self):
        self.x = numpy.random.uniform(-1, 1, self.shape).astype(self.dtype)
        out_shape = numpy.pad(self.x, self.pad_width, self.mode).shape
        self.g = numpy.random.uniform(-1, 1, out_shape).astype(self.dtype)
        self.check_backward_options = {'dtype': numpy.float64}
        if self.dtype == numpy.float16:
            self.check_backward_options = {
                'atol': 2 ** -6, 'rtol': 2 ** -6}
{'fraction_non_alphanumeric': 0.16653160453808752, 'fraction_numerical': 0.027552674230145867, 'mean_word_length': 3.101328903654485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1691318', 'n_tokens_mistral': 844, 'n_tokens_neox': 812, 'n_words': 204}