<s> import unittest <EOL> import numpy <EOL> from cupy import core <EOL> from cupy import get_array_module <EOL> from cupy import testing <EOL> class TestGetSize ( unittest . TestCase ) : <EOL> def test_none ( self ) : <EOL> self . assertEqual ( core . get_size ( None ) , ( ) ) <EOL> def check_collection ( self , a ) : <EOL> self . assertEqual ( core . get_size ( a ) , tuple ( a ) ) <EOL> def test_list ( self ) : <EOL> self . check_collection ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> def test_tuple ( self ) : <EOL> self . check_collection ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> def test_int ( self ) : <EOL> self . assertEqual ( core . get_size ( <NUM_LIT:1> ) , ( <NUM_LIT:1> , ) ) <EOL> def test_float ( self ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> core . get_size ( <NUM_LIT:1.0> ) <EOL> def wrap_take ( array , * args , ** kwargs ) : <EOL> if get_array_module ( array ) == numpy : <EOL> kwargs [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> return array . take ( * args , ** kwargs ) <EOL> @ testing . parameterize ( <EOL> { '<STR_LIT>' : None , '<STR_LIT>' : ( ) } , <EOL> { '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : ( <NUM_LIT:3> , ) } , <EOL> ) <EOL> @ testing . gpu <EOL> class TestNdarrayInit ( unittest . TestCase ) : <EOL> def test_shape ( self ) : <EOL> a = core . ndarray ( self . arg ) <EOL> self . assertTupleEqual ( a . shape , self . shape ) <EOL> @ testing . gpu <EOL> class TestNdarrayInitRaise ( unittest . TestCase ) : <EOL> def test_unsupported_type ( self ) : <EOL> arr = numpy . ndarray ( ( <NUM_LIT:2> , <NUM_LIT:3> ) , dtype = object ) <EOL> with self . assertRaises ( ValueError ) : <EOL> core . array ( arr ) <EOL> @ testing . parameterize ( <EOL> * testing . product ( { <EOL> '<STR_LIT>' : [ ( <NUM_LIT:2> , ) , ( <NUM_LIT:2> , <NUM_LIT:3> ) ] , <EOL> '<STR_LIT>' : [ None , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , - <NUM_LIT:1> , - <NUM_LIT:2> ] , <EOL> } ) <EOL> ) <EOL> @ testing . gpu <EOL> class TestNdarrayTake ( unittest . TestCase ) : <EOL> shape = ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) <EOL> @ testing . for_all_dtypes ( ) <EOL> @ testing . numpy_cupy_array_equal ( accept_error = False ) <EOL> def test_take ( self , xp , dtype ) : <EOL> a = testing . shaped_arange ( self . shape , xp , dtype ) <EOL> if self . axis is None : <EOL> m = a . size <EOL> else : <EOL> m = a . shape [ self . axis ] <EOL> i = testing . shaped_arange ( self . indices_shape , xp , numpy . int32 ) % m <EOL> return wrap_take ( a , i , self . axis ) <EOL> @ testing . parameterize ( <EOL> * testing . product ( { <EOL> '<STR_LIT>' : [ <NUM_LIT:2> , [ <NUM_LIT:0> , <NUM_LIT:1> ] , - <NUM_LIT:1> , [ - <NUM_LIT:1> , - <NUM_LIT:2> ] ] , <EOL> '<STR_LIT>' : [ None , <NUM_LIT:0> , <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:2> ] , <EOL> } ) <EOL> ) <EOL> @ testing . gpu <EOL> class TestNdarrayTakeWithInt ( unittest . TestCase ) : <EOL> shape = ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) <EOL> @ testing . for_all_dtypes ( ) <EOL> @ testing . numpy_cupy_array_equal ( accept_error = False ) <EOL> def test_take ( self , xp , dtype ) : <EOL> a = testing . shaped_arange ( self . shape , xp , dtype ) <EOL> return wrap_take ( a , self . indices , self . axis ) <EOL> @ testing . parameterize ( <EOL> * testing . product ( { <EOL> '<STR_LIT>' : [ <NUM_LIT:2> , [ <NUM_LIT:0> , <NUM_LIT:1> ] , - <NUM_LIT:1> , [ - <NUM_LIT:1> , - <NUM_LIT:2> ] ] , <EOL> '<STR_LIT>' : [ None , <NUM_LIT:0> , <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:2> ] , <EOL> } ) <EOL> ) <EOL> class TestNdarrayTakeWithIntWithOutParam ( unittest . TestCase ) : <EOL> shape = ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) <EOL> @ testing . for_all_dtypes ( ) <EOL> @ testing . numpy_cupy_array_equal ( accept_error = False ) <EOL> def test_take ( self , xp , dtype ) : <EOL> a = testing . shaped_arange ( self . shape , xp , dtype ) <EOL> r1 = wrap_take ( a , self . indices , self . axis ) <EOL> r2 = xp . zeros_like ( r1 ) <EOL> wrap_take ( a , self . indices , self . axis , out = r2 ) <EOL> testing . assert_array_equal ( r1 , r2 ) <EOL> return r2 <EOL> @ testing . parameterize ( <EOL> * testing . product ( { <EOL> '<STR_LIT>' : [ <NUM_LIT:0> , - <NUM_LIT:1> , [ <NUM_LIT:0> ] , [ <NUM_LIT:0> , - <NUM_LIT:1> ] ] , <EOL> '<STR_LIT>' : [ None , <NUM_LIT:0> , - <NUM_LIT:1> ] , <EOL> } ) <EOL> ) <EOL> class TestScalaNdarrayTakeWithIntWithOutParam ( unittest . TestCase ) : <EOL> shape = ( ) <EOL> @ testing . for_all_dtypes ( ) <EOL> @ testing . numpy_cupy_array_equal ( accept_error = False ) <EOL> def test_take ( self , xp , dtype ) : <EOL> a = testing . shaped_arange ( self . shape , xp , dtype ) <EOL> r1 = wrap_take ( a , self . indices , self . axis ) <EOL> r2 = xp . zeros_like ( r1 ) <EOL> wrap_take ( a , self . indices , self . axis , out = r2 ) <EOL> testing . assert_array_equal ( r1 , r2 ) <EOL> return r2 <EOL> @ testing . parameterize ( <EOL> { "<STR_LIT>" : ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) , "<STR_LIT>" : ( <NUM_LIT:2> , ) , "<STR_LIT>" : <NUM_LIT:3> } , <EOL> { "<STR_LIT>" : ( ) , "<STR_LIT>" : ( <NUM_LIT:0> , ) , "<STR_LIT>" : <NUM_LIT:2> } <EOL> ) <EOL> @ testing . gpu <EOL> class TestNdarrayTakeErrorAxisOverRun ( unittest . TestCase ) : <EOL> @ testing . for_all_dtypes ( ) <EOL> @ testing . numpy_cupy_raises ( ) <EOL> def test_axis_overrun ( self , xp , dtype ) : <EOL> a = testing . shaped_arange ( self . shape , xp , dtype ) <EOL> wrap_take ( a , self . indices , axis = self . axis ) <EOL> @ testing . parameterize ( <EOL> { "<STR_LIT>" : ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) , "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:3> ) , "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:4> ) } , <EOL> { "<STR_LIT>" : ( ) , "<STR_LIT>" : <NUM_LIT:0> , "<STR_LIT>" : ( <NUM_LIT:1> , ) } <EOL> ) <EOL> class TestNdarrayTakeErrorShapeMismatch ( unittest . TestCase ) : <EOL> @ testing . for_all_dtypes ( ) <EOL> @ testing . numpy_cupy_raises ( ) <EOL> def test_shape_mismatch ( self , xp , dtype ) : <EOL> a = testing . shaped_arange ( self . shape , xp , dtype ) <EOL> i = testing . shaped_arange ( self . indices , xp , numpy . int32 ) % <NUM_LIT:3> <EOL> o = testing . shaped_arange ( self . out_shape , xp , dtype ) <EOL> wrap_take ( a , i , out = o ) <EOL> @ testing . parameterize ( <EOL> { "<STR_LIT>" : ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) , "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:3> ) , "<STR_LIT>" : ( <NUM_LIT:2> , <NUM_LIT:3> ) } , <EOL> { "<STR_LIT>" : ( ) , "<STR_LIT>" : <NUM_LIT:0> , "<STR_LIT>" : ( ) } <EOL> ) <EOL> class TestNdarrayTakeErrorTypeMismatch ( unittest . TestCase ) : <EOL> @ testing . numpy_cupy_raises ( ) <EOL> def test_output_type_mismatch ( self , xp ) : <EOL> a = testing . shaped_arange ( self . shape , xp , numpy . int32 ) <EOL> i = testing . shaped_arange ( self . indices , xp , numpy . int32 ) % <NUM_LIT:3> <EOL> o = testing . shaped_arange ( self . out_shape , xp , numpy . float32 ) <EOL> wrap_take ( a , i , out = o ) </s>
