<s> import unittest <EOL> import numpy <EOL> import chainer <EOL> from chainer import cuda <EOL> import chainer . functions as F <EOL> from chainer import gradient_check <EOL> from chainer import testing <EOL> from chainer . testing import attr <EOL> from chainer . testing import condition <EOL> class UnaryFunctionsTestBase ( object ) : <EOL> def make_data ( self ) : <EOL> raise NotImplementedError <EOL> def setUp ( self ) : <EOL> self . x , self . gy = self . make_data ( ) <EOL> def check_forward ( self , op , op_np , x_data ) : <EOL> x = chainer . Variable ( x_data ) <EOL> y = op ( x ) <EOL> gradient_check . assert_allclose ( <EOL> op_np ( self . x ) , y . data , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def check_forward_cpu ( self , op , op_np ) : <EOL> self . check_forward ( op , op_np , self . x ) <EOL> def check_forward_gpu ( self , op , op_np ) : <EOL> self . check_forward ( op , op_np , cuda . to_gpu ( self . x ) ) <EOL> @ condition . retry ( <NUM_LIT:3> ) <EOL> def test_cos_forward_cpu ( self ) : <EOL> self . check_forward_cpu ( F . cos , numpy . cos ) <EOL> @ condition . retry ( <NUM_LIT:3> ) <EOL> def test_sin_forward_cpu ( self ) : <EOL> self . check_forward_cpu ( F . sin , numpy . sin ) <EOL> @ attr . gpu <EOL> @ condition . retry ( <NUM_LIT:3> ) <EOL> def test_cos_forward_gpu ( self ) : <EOL> self . check_forward_gpu ( F . cos , numpy . cos ) <EOL> @ attr . gpu <EOL> @ condition . retry ( <NUM_LIT:3> ) <EOL> def test_sin_forward_gpu ( self ) : <EOL> self . check_forward_gpu ( F . sin , numpy . sin ) <EOL> def check_backward ( self , op , x_data , y_grad ) : <EOL> gradient_check . check_backward ( op , x_data , y_grad ) <EOL> def check_backward_cpu ( self , op ) : <EOL> self . check_backward ( op , self . x , self . gy ) <EOL> def check_backward_gpu ( self , op ) : <EOL> self . check_backward ( op , cuda . to_gpu ( self . x ) , cuda . to_gpu ( self . gy ) ) <EOL> @ condition . retry ( <NUM_LIT:3> ) <EOL> def test_cos_backward_cpu ( self ) : <EOL> self . check_backward_cpu ( F . cos ) <EOL> @ condition . retry ( <NUM_LIT:3> ) <EOL> def test_sin_backward_cpu ( self ) : <EOL> self . check_backward_cpu ( F . sin ) <EOL> @ attr . gpu <EOL> @ condition . retry ( <NUM_LIT:3> ) <EOL> def test_cos_backward_gpu ( self ) : <EOL> self . check_backward_gpu ( F . cos ) <EOL> @ attr . gpu <EOL> @ condition . retry ( <NUM_LIT:3> ) <EOL> def test_sin_backward_gpu ( self ) : <EOL> self . check_backward_gpu ( F . sin ) <EOL> def test_sin ( self ) : <EOL> self . assertEqual ( F . Sin ( ) . label , '<STR_LIT>' ) <EOL> def test_cos ( self ) : <EOL> self . assertEqual ( F . Cos ( ) . label , '<STR_LIT>' ) <EOL> class TestUnaryFunctionsSimple ( UnaryFunctionsTestBase , unittest . TestCase ) : <EOL> def make_data ( self ) : <EOL> x = numpy . random . uniform ( <NUM_LIT> , <NUM_LIT:1> , ( <NUM_LIT:3> , <NUM_LIT:2> ) ) . astype ( numpy . float32 ) <EOL> gy = numpy . random . uniform ( - <NUM_LIT:1> , <NUM_LIT:1> , ( <NUM_LIT:3> , <NUM_LIT:2> ) ) . astype ( numpy . float32 ) <EOL> return x , gy <EOL> class TestUnaryFunctionsZeroDimension ( UnaryFunctionsTestBase , <EOL> unittest . TestCase ) : <EOL> def make_data ( self ) : <EOL> x = numpy . random . uniform ( <NUM_LIT> , <NUM_LIT:1> , ( ) ) . astype ( numpy . float32 ) <EOL> gy = numpy . random . uniform ( - <NUM_LIT:1> , <NUM_LIT:1> , ( ) ) . astype ( numpy . float32 ) <EOL> return x , gy <EOL> testing . run_module ( __name__ , __file__ ) </s>
