<commit_before>import unittest

import numpy

import chainer.functions as F
from chainer import testing


# sqrt

def make_data(shape, dtype):
    x = numpy.random.uniform(0.1, 5, shape).astype(dtype)
    gy = numpy.random.uniform(-1, 1, shape).astype(dtype)
    ggx = numpy.random.uniform(-1, 1, shape).astype(dtype)
    return x, gy, ggx


@testing.unary_math_function_unittest(F.sqrt, make_data=make_data)
class TestSqrt(unittest.TestCase):
    pass


# rsqrt

def rsqrt(x):
    return numpy.reciprocal(numpy.sqrt(x))


class TestRsqrt(unittest.TestCase):

    def test_rsqrt(self):
        x = numpy.random.uniform(0.1, 5, (3, 2)).astype(numpy.float32)
        testing.assert_allclose(F.rsqrt(x).data, rsqrt(x))


testing.run_module(__name__, __file__)
<commit_msg>add tolerance option to F.sqrt<commit_after>import unittest

import numpy

import chainer.functions as F
from chainer import testing


# sqrt

def make_data(shape, dtype):
    x = numpy.random.uniform(0.1, 5, shape).astype(dtype)
    gy = numpy.random.uniform(-1, 1, shape).astype(dtype)
    ggx = numpy.random.uniform(-1, 1, shape).astype(dtype)
    return x, gy, ggx


@testing.unary_math_function_unittest(
    F.sqrt,
    make_data=make_data,
    backward_options={'atol': 1e-3, 'rtol': 1e-3},
)
class TestSqrt(unittest.TestCase):
    pass


# rsqrt

def rsqrt(x):
    return numpy.reciprocal(numpy.sqrt(x))


class TestRsqrt(unittest.TestCase):

    def test_rsqrt(self):
        x = numpy.random.uniform(0.1, 5, (3, 2)).astype(numpy.float32)
        testing.assert_allclose(F.rsqrt(x).data, rsqrt(x))


testing.run_module(__name__, __file__)

{'fraction_non_alphanumeric': 0.1341991341991342, 'fraction_numerical': 0.019789734075448363, 'mean_word_length': 4.024844720496894, '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': '5215326', 'n_tokens_mistral': 634, 'n_tokens_neox': 601, 'n_words': 119}