import numpy
import test_sqrt

from chainer import cuda
import chainer.functions as F
from chainer import testing
from chainer.testing import attr
from chainer.testing import condition


@testing.parameterize(*testing.product({
    'shape': [(3, 2), ()],
    'dtype': [numpy.float16, numpy.float32, numpy.float64],
}))
class TestSquare(test_sqrt.UnaryFunctionsTestBase):

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

    @condition.retry(3)
    def test_forward_cpu(self):
        self.check_forward_cpu(F.square, numpy.square)

    @attr.gpu
    @condition.retry(3)
    def test_forward_gpu(self):
        self.check_forward_gpu(F.square, cuda.cupy.square)

    @condition.retry(3)
    def test_backward_cpu(self):
        self.check_backward_cpu(F.square)

    @attr.gpu
    @condition.retry(3)
    def test_backward_gpu(self):
        self.check_backward_gpu(F.square)

    def test_label(self):
        self.check_label(F.Square, 'square')


testing.run_module(__name__, __file__)

import unittest

import numpy

import chainer.functions as F
from chainer import testing


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


@testing.unary_math_function_test(F.Square(), make_data=make_data)
class TestSquare(unittest.TestCase):
    pass


testing.run_module(__name__, __file__)

Fix test