import unittest

import numpy

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


@testing.parameterize(*testing.product({
    'func_name': ['cos', 'sin', 'tan'],
    'shape': [(3, 2), ()],
}))
class UnaryFunctionsTest(unittest.TestCase):

    def make_data(self):
        raise NotImplementedError

    def setUp(self):
        self.x = numpy.random.uniform(.5, 1, self.shape).astype(numpy.float32)
        self.gy = numpy.random.uniform(-1, 1, self.shape).astype(numpy.float32)
        self.func = getattr(F, self.func_name)
        camel_name = self.func_name[0].upper() + self.func_name[1:]
        self.func_class = getattr(F, camel_name)
        self.np_func = getattr(numpy, self.func_name)

    def check_forward(self, x_data):
        x = chainer.Variable(x_data)
        y = self.func(x)
        testing.assert_allclose(
            self.np_func(self.x), y.data, atol=1e-7, rtol=1e-7)

    @condition.retry(3)
    def test_forward_cpu(self):
        self.check_forward(self.x)

    @attr.gpu
    @condition.retry(3)
    def test_forward_gpu(self):
        self.check_forward(cuda.to_gpu(self.x))

    def check_backward(self, x_data, y_grad):
        gradient_check.check_backward(self.func, x_data, y_grad)

    @condition.retry(3)
    def test_backward_cpu(self):
        self.check_backward(self.x, self.gy)

    @attr.gpu
    @condition.retry(3)
    def test_backward_gpu(self):
        self.check_backward(cuda.to_gpu(self.x), cuda.to_gpu(self.gy))

    def test_label(self):
        self.assertEqual(self.func_class().label, self.func_name)


testing.run_module(__name__, __file__)

@@ -338,16 +338,76 @@
 ), ()%5D,%0A
+    'dtype': %5Bnumpy.float16, numpy.float32, numpy.float64%5D,%0A
 %7D))%0Aclas
@@ -589,37 +589,34 @@
 ape).astype(
-numpy.float32
+self.dtype
 )%0A        se
@@ -670,29 +670,26 @@
 .astype(
-numpy.float32
+self.dtype
 )%0A      
@@ -901,16 +901,214 @@
 _name)%0A%0A
+        if self.dtype == numpy.float16:%0A            self.backward_options = %7B%0A                'eps': 2 ** -4, 'atol': 2 ** -4, 'rtol': 2 ** -4%7D%0A        else:%0A            self.backward_options = %7B%7D%0A%0A
     def 
@@ -1281,17 +1281,17 @@
 atol=1e-
-7
+4
 , rtol=1
@@ -1296,9 +1296,9 @@
 =1e-
-7
+4
 )%0A%0A 
@@ -1587,24 +1587,37 @@
 ck_backward(
+%0A            
 self.func, x
@@ -1629,16 +1629,41 @@
 , y_grad
+, **self.backward_options
 )%0A%0A    @

Check all dtypes