<s> import unittest <EOL> import numpy <EOL> import chainer <EOL> from chainer import cuda <EOL> from chainer import functions <EOL> from chainer import gradient_check <EOL> from chainer import testing <EOL> from chainer . testing import attr <EOL> @ testing . parameterize ( <EOL> { '<STR_LIT>' : ( <NUM_LIT:2> , <NUM_LIT:7> , <NUM_LIT:3> ) , '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : [ [ slice ( None ) , slice ( None , <NUM_LIT:2> ) ] , [ slice ( None ) , slice ( <NUM_LIT:2> , <NUM_LIT:5> ) ] , <EOL> [ slice ( None ) , slice ( <NUM_LIT:5> , None ) ] ] } , <EOL> { '<STR_LIT>' : ( <NUM_LIT:7> , <NUM_LIT:3> ) , '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : [ slice ( None , <NUM_LIT:2> ) , slice ( <NUM_LIT:2> , <NUM_LIT:5> ) , slice ( <NUM_LIT:5> , None ) ] } , <EOL> { '<STR_LIT>' : ( <NUM_LIT:2> , ) , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : [ slice ( None , <NUM_LIT:1> ) , slice ( <NUM_LIT:1> , None ) ] } , <EOL> { '<STR_LIT>' : ( <NUM_LIT:2> , ) , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : [ ( ) ] } , <EOL> ) <EOL> class ConcatTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . y = numpy . arange ( <EOL> numpy . prod ( self . shape ) , dtype = numpy . float32 ) . reshape ( self . shape ) <EOL> self . xs = [ self . y [ s ] for s in self . slices ] <EOL> def check_forward ( self , xs_data , y_data , axis ) : <EOL> xs = tuple ( chainer . Variable ( x_data ) for x_data in xs_data ) <EOL> y = functions . concat ( xs , axis = axis ) <EOL> gradient_check . assert_allclose ( y_data , y . data , atol = <NUM_LIT:0> , rtol = <NUM_LIT:0> ) <EOL> self . assertIsInstance ( y . data . shape , tuple ) <EOL> def test_forward_cpu ( self ) : <EOL> self . check_forward ( self . xs , self . y , axis = self . axis ) <EOL> @ attr . gpu <EOL> def test_forward_gpu ( self ) : <EOL> self . check_forward ( <EOL> [ cuda . to_gpu ( x . copy ( ) ) for x in self . xs ] , <EOL> cuda . to_gpu ( self . y ) , axis = self . axis ) <EOL> def check_backward ( self , xs_data , axis ) : <EOL> xs = tuple ( chainer . Variable ( x_data ) for x_data in xs_data ) <EOL> y = functions . concat ( xs , axis = axis ) <EOL> y . grad = y . data <EOL> y . backward ( ) <EOL> for x in xs : <EOL> gradient_check . assert_allclose ( x . data , x . grad , atol = <NUM_LIT:0> , rtol = <NUM_LIT:0> ) <EOL> def test_backward_cpu ( self ) : <EOL> self . check_backward ( self . xs , axis = self . axis ) <EOL> @ attr . gpu <EOL> def test_backward_gpu ( self ) : <EOL> self . check_backward ( [ cuda . to_gpu ( x . copy ( ) ) for x in self . xs ] , <EOL> axis = self . axis ) <EOL> testing . run_module ( __name__ , __file__ ) </s>
