<s> from __future__ import print_function <EOL> from collections import namedtuple <EOL> import contextlib <EOL> import itertools <EOL> import math <EOL> import sys <EOL> from numba . compiler import compile_isolated , Flags <EOL> from numba import jit , types <EOL> import numba . unittest_support as unittest <EOL> from numba import testing <EOL> from . support import TestCase , MemoryLeakMixin , tag <EOL> enable_pyobj_flags = Flags ( ) <EOL> enable_pyobj_flags . set ( "<STR_LIT>" ) <EOL> force_pyobj_flags = Flags ( ) <EOL> force_pyobj_flags . set ( "<STR_LIT>" ) <EOL> Point = namedtuple ( '<STR_LIT>' , ( '<STR_LIT:a>' , '<STR_LIT:b>' ) ) <EOL> def noop ( x ) : <EOL> pass <EOL> def unbox_usecase ( x ) : <EOL> """<STR_LIT>""" <EOL> res = <NUM_LIT:0> <EOL> for v in x : <EOL> res += v <EOL> return res <EOL> def unbox_usecase2 ( x ) : <EOL> """<STR_LIT>""" <EOL> res = <NUM_LIT:0> <EOL> for v in x : <EOL> res += len ( v ) <EOL> return res <EOL> def unbox_usecase3 ( x ) : <EOL> """<STR_LIT>""" <EOL> a , b = x <EOL> res = a <EOL> for v in b : <EOL> res += v <EOL> return res <EOL> def unbox_usecase4 ( x ) : <EOL> """<STR_LIT>""" <EOL> a , b = x <EOL> res = a <EOL> for v in b : <EOL> res += len ( v ) <EOL> return res <EOL> def create_list ( x , y , z ) : <EOL> return [ x , y , z ] <EOL> def create_nested_list ( x , y , z , a , b , c ) : <EOL> return [ [ x , y , z ] , [ a , b , c ] ] <EOL> def list_comprehension1 ( ) : <EOL> return sum ( [ x ** <NUM_LIT:2> for x in range ( <NUM_LIT:10> ) ] ) <EOL> def list_comprehension2 ( ) : <EOL> return sum ( [ x for x in range ( <NUM_LIT:10> ) if x % <NUM_LIT:2> == <NUM_LIT:0> ] ) <EOL> def list_comprehension3 ( ) : <EOL> return sum ( [ math . pow ( x , <NUM_LIT:2> ) for x in range ( <NUM_LIT:10> ) ] ) <EOL> def list_comprehension4 ( ) : <EOL> return sum ( [ x * y for x in range ( <NUM_LIT:10> ) for y in range ( <NUM_LIT:10> ) ] ) <EOL> def list_comprehension5 ( ) : <EOL> return [ x * <NUM_LIT:2> for x in range ( <NUM_LIT:10> ) ] <EOL> def list_comprehension6 ( ) : <EOL> return [ [ x for x in range ( y ) ] for y in range ( <NUM_LIT:3> ) ] <EOL> def list_constructor ( n ) : <EOL> return list ( range ( n ) ) <EOL> def list_append ( n ) : <EOL> l = [ ] <EOL> l . append ( <NUM_LIT> ) <EOL> for i in range ( n ) : <EOL> l . append ( i ) <EOL> return l <EOL> def list_append_heterogenous ( n ) : <EOL> l = [ ] <EOL> l . append ( <NUM_LIT> ) <EOL> for i in range ( n ) : <EOL> l . append ( i ) <EOL> return l <EOL> def list_extend ( n ) : <EOL> l = [ ] <EOL> l . extend ( range ( n ) ) <EOL> l . extend ( l [ : - <NUM_LIT:1> ] ) <EOL> l . extend ( range ( n , <NUM_LIT:0> , - <NUM_LIT:1> ) ) <EOL> return l <EOL> def list_extend_heterogenous ( n ) : <EOL> l = [ ] <EOL> l . extend ( range ( n ) ) <EOL> l . extend ( l [ : - <NUM_LIT:1> ] ) <EOL> l . extend ( ( <NUM_LIT:5> , <NUM_LIT> ) ) <EOL> l . extend ( [ <NUM_LIT> ] ) <EOL> return l <EOL> def list_pop0 ( n ) : <EOL> l = list ( range ( n ) ) <EOL> res = <NUM_LIT:0> <EOL> while len ( l ) > <NUM_LIT:0> : <EOL> res += len ( l ) * l . pop ( ) <EOL> return res <EOL> def list_pop1 ( n , i ) : <EOL> l = list ( range ( n ) ) <EOL> x = l . pop ( i ) <EOL> return x , l <EOL> def list_len ( n ) : <EOL> l = list ( range ( n ) ) <EOL> return len ( l ) <EOL> def list_getitem ( n ) : <EOL> l = list ( range ( n ) ) <EOL> res = <NUM_LIT:0> <EOL> for i in range ( len ( l ) ) : <EOL> res += i * l [ i ] <EOL> for i in range ( - len ( l ) , <NUM_LIT:0> ) : <EOL> res -= i * l [ i ] <EOL> return res <EOL> def list_setitem ( n ) : <EOL> l = list ( range ( n ) ) <EOL> res = <NUM_LIT:0> <EOL> for i in range ( len ( l ) ) : <EOL> l [ i ] = i * l [ i ] <EOL> for i in range ( - len ( l ) , <NUM_LIT:0> ) : <EOL> l [ i ] = i * l [ i ] <EOL> for i in range ( len ( l ) ) : <EOL> res += l [ i ] <EOL> return res <EOL> def list_getslice2 ( n , start , stop ) : <EOL> l = list ( range ( n ) ) <EOL> return l [ start : stop ] <EOL> def list_getslice3 ( n , start , stop , step ) : <EOL> l = list ( range ( n ) ) <EOL> return l [ start : stop : step ] <EOL> def list_setslice2 ( n , n_source , start , stop ) : <EOL> l = list ( range ( n ) ) <EOL> v = list ( range ( <NUM_LIT:100> , <NUM_LIT:100> + n_source ) ) <EOL> l [ start : stop ] = v <EOL> return l <EOL> def list_setslice3 ( n , start , stop , step ) : <EOL> l = list ( range ( n ) ) <EOL> v = l [ start : stop : step ] <EOL> for i in range ( len ( v ) ) : <EOL> v [ i ] += <NUM_LIT:100> <EOL> l [ start : stop : step ] = v <EOL> return l <EOL> def list_setslice3_arbitrary ( n , n_src , start , stop , step ) : <EOL> l = list ( range ( n ) ) <EOL> l [ start : stop : step ] = list ( range ( <NUM_LIT:100> , <NUM_LIT:100> + n_src ) ) <EOL> return l <EOL> def list_delslice0 ( n ) : <EOL> l = list ( range ( n ) ) <EOL> del l [ : ] <EOL> return l <EOL> def list_delslice1 ( n , start , stop ) : <EOL> l = list ( range ( n ) ) <EOL> del l [ start : ] <EOL> del l [ : stop ] <EOL> return l <EOL> def list_delslice2 ( n , start , stop ) : <EOL> l = list ( range ( n ) ) <EOL> del l [ start : stop ] <EOL> return l <EOL> def list_clear ( n ) : <EOL> l = list ( range ( n ) ) <EOL> l . clear ( ) <EOL> return l <EOL> def list_copy ( n ) : <EOL> l = list ( range ( n ) ) <EOL> ll = l . copy ( ) <EOL> l . append ( <NUM_LIT> ) <EOL> return l , ll <EOL> def list_iteration ( n ) : <EOL> l = list ( range ( n ) ) <EOL> res = <NUM_LIT:0> <EOL> for i , v in enumerate ( l ) : <EOL> res += i * v <EOL> return res <EOL> def list_contains ( n ) : <EOL> l = list ( range ( n ) ) <EOL> return ( <NUM_LIT:0> in l , <NUM_LIT:1> in l , n - <NUM_LIT:1> in l , n in l , <EOL> <NUM_LIT:0> not in l , <NUM_LIT:1> not in l , n - <NUM_LIT:1> not in l , n not in l , <EOL> ) <EOL> def list_index1 ( n , v ) : <EOL> l = list ( range ( n , <NUM_LIT:0> , - <NUM_LIT:1> ) ) <EOL> return l . index ( v ) <EOL> def list_index2 ( n , v , start ) : <EOL> l = list ( range ( n , <NUM_LIT:0> , - <NUM_LIT:1> ) ) <EOL> return l . index ( v , start ) <EOL> def list_index3 ( n , v , start , stop ) : <EOL> l = list ( range ( n , <NUM_LIT:0> , - <NUM_LIT:1> ) ) <EOL> return l . index ( v , start , stop ) <EOL> def list_remove ( n , v ) : <EOL> l = list ( range ( n - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) ) <EOL> l . remove ( v ) <EOL> return l <EOL> def list_insert ( n , pos , v ) : <EOL> l = list ( range ( <NUM_LIT:0> , n ) ) <EOL> l . insert ( pos , v ) <EOL> return l <EOL> def list_count ( n , v ) : <EOL> l = [ ] <EOL> for x in range ( n ) : <EOL> l . append ( x & <NUM_LIT:3> ) <EOL> return l . count ( v ) <EOL> def list_reverse ( n ) : <EOL> l = list ( range ( n ) ) <EOL> l . reverse ( ) <EOL> return l <EOL> def list_add ( m , n ) : <EOL> a = list ( range ( <NUM_LIT:0> , m ) ) <EOL> b = list ( range ( <NUM_LIT:100> , <NUM_LIT:100> + n ) ) <EOL> res = a + b <EOL> res . append ( <NUM_LIT> ) <EOL> return a , b , res <EOL> def list_add_heterogenous ( ) : <EOL> a = [ <NUM_LIT:1> ] <EOL> b = [ <NUM_LIT> ] <EOL> c = a + b <EOL> d = b + a <EOL> a . append ( <NUM_LIT:3> ) <EOL> b . append ( <NUM_LIT> ) <EOL> return a , b , c , d <EOL> def list_add_inplace ( m , n ) : <EOL> a = list ( range ( <NUM_LIT:0> , m ) ) <EOL> b = list ( range ( <NUM_LIT:100> , <NUM_LIT:100> + n ) ) <EOL> a += b <EOL> return a , b <EOL> def list_add_inplace_heterogenous ( ) : <EOL> a = [ <NUM_LIT:1> ] <EOL> b = [ <NUM_LIT> ] <EOL> a += b <EOL> b += a <EOL> return a , b <EOL> def list_mul ( n , v ) : <EOL> a = list ( range ( n ) ) <EOL> return a * v <EOL> def list_mul_inplace ( n , v ) : <EOL> a = list ( range ( n ) ) <EOL> a *= v <EOL> return a <EOL> def list_bool ( n ) : <EOL> a = list ( range ( n ) ) <EOL> return bool ( a ) , ( True if a else False ) <EOL> def eq_usecase ( a , b ) : <EOL> return list ( a ) == list ( b ) <EOL> def ne_usecase ( a , b ) : <EOL> return list ( a ) != list ( b ) <EOL> def gt_usecase ( a , b ) : <EOL> return list ( a ) > list ( b ) <EOL> def ge_usecase ( a , b ) : <EOL> return list ( a ) >= list ( b ) <EOL> def lt_usecase ( a , b ) : <EOL> return list ( a ) < list ( b ) <EOL> def le_usecase ( a , b ) : <EOL> return list ( a ) <= list ( b ) <EOL> def identity_usecase ( n ) : <EOL> a = list ( range ( n ) ) <EOL> b = a <EOL> c = a [ : ] <EOL> return ( a is b ) , ( a is not b ) , ( a is c ) , ( a is not c ) <EOL> def bool_list_usecase ( ) : <EOL> l = [ False ] <EOL> l [ <NUM_LIT:0> ] = True <EOL> x = False <EOL> for v in l : <EOL> x = x ^ v <EOL> return l , x <EOL> def reflect_simple ( l , ll ) : <EOL> x = l . pop ( ) <EOL> y = l . pop ( ) <EOL> l [ <NUM_LIT:0> ] = <NUM_LIT> <EOL> l . extend ( ll ) <EOL> return l , x , y <EOL> def reflect_conditional ( l , ll ) : <EOL> if ll [ <NUM_LIT:0> ] : <EOL> l = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> x = l . pop ( ) <EOL> y = l . pop ( ) <EOL> l [ <NUM_LIT:0> ] = <NUM_LIT> <EOL> l . extend ( ll ) <EOL> return l , x , y <EOL> def reflect_exception ( l ) : <EOL> l . append ( <NUM_LIT> ) <EOL> raise ZeroDivisionError <EOL> def reflect_dual ( l , ll ) : <EOL> l . append ( ll . pop ( ) ) <EOL> return l is ll <EOL> class TestLists ( MemoryLeakMixin , TestCase ) : <EOL> def test_create_list ( self ) : <EOL> pyfunc = create_list <EOL> cr = compile_isolated ( pyfunc , ( types . int32 , types . int32 , types . int32 ) ) <EOL> cfunc = cr . entry_point <EOL> self . assertEqual ( cfunc ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) , pyfunc ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> def test_create_nested_list ( self ) : <EOL> pyfunc = create_nested_list <EOL> with self . assertTypingError ( ) : <EOL> cr = compile_isolated ( pyfunc , ( types . int32 , types . int32 , types . int32 , <EOL> types . int32 , types . int32 , types . int32 ) ) <EOL> cfunc = cr . entry_point <EOL> self . assertEqual ( cfunc ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ) , pyfunc ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ) ) <EOL> @ testing . allow_interpreter_mode <EOL> def test_list_comprehension ( self ) : <EOL> list_tests = [ list_comprehension1 , <EOL> list_comprehension2 , <EOL> list_comprehension3 , <EOL> list_comprehension4 , <EOL> list_comprehension5 , <EOL> list_comprehension6 ] <EOL> for test in list_tests : <EOL> pyfunc = test <EOL> cr = compile_isolated ( pyfunc , ( ) ) <EOL> cfunc = cr . entry_point <EOL> self . assertEqual ( cfunc ( ) , pyfunc ( ) ) <EOL> def check_unary_with_size ( self , pyfunc , precise = True ) : <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> for n in [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> ] : <EOL> eq = self . assertPreciseEqual if precise else self . assertEqual <EOL> eq ( cfunc ( n ) , pyfunc ( n ) ) <EOL> def test_constructor ( self ) : <EOL> self . check_unary_with_size ( list_constructor ) <EOL> def test_append ( self ) : <EOL> self . check_unary_with_size ( list_append ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_append_heterogenous ( self ) : <EOL> self . check_unary_with_size ( list_append_heterogenous , precise = False ) <EOL> def test_extend ( self ) : <EOL> self . check_unary_with_size ( list_extend ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_extend_heterogenous ( self ) : <EOL> self . check_unary_with_size ( list_extend_heterogenous , precise = False ) <EOL> def test_pop0 ( self ) : <EOL> self . check_unary_with_size ( list_pop0 ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_pop1 ( self ) : <EOL> pyfunc = list_pop1 <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> for n in [ <NUM_LIT:5> , <NUM_LIT> ] : <EOL> for i in [ <NUM_LIT:0> , <NUM_LIT:1> , n - <NUM_LIT:2> , n - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:2> , - n + <NUM_LIT:3> , - n + <NUM_LIT:1> ] : <EOL> expected = pyfunc ( n , i ) <EOL> self . assertPreciseEqual ( cfunc ( n , i ) , expected ) <EOL> def test_pop_errors ( self ) : <EOL> self . disable_leak_check ( ) <EOL> cfunc = jit ( nopython = True ) ( list_pop1 ) <EOL> with self . assertRaises ( IndexError ) as cm : <EOL> cfunc ( <NUM_LIT:0> , <NUM_LIT:5> ) <EOL> self . assertEqual ( str ( cm . exception ) , "<STR_LIT>" ) <EOL> with self . assertRaises ( IndexError ) as cm : <EOL> cfunc ( <NUM_LIT:1> , <NUM_LIT:5> ) <EOL> self . assertEqual ( str ( cm . exception ) , "<STR_LIT>" ) <EOL> def test_insert ( self ) : <EOL> pyfunc = list_insert <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> for n in [ <NUM_LIT:5> , <NUM_LIT> ] : <EOL> indices = [ <NUM_LIT:0> , <NUM_LIT:1> , n - <NUM_LIT:2> , n - <NUM_LIT:1> , n + <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:2> , - n + <NUM_LIT:3> , - n - <NUM_LIT:1> ] <EOL> for i in indices : <EOL> expected = pyfunc ( n , i , <NUM_LIT> ) <EOL> self . assertPreciseEqual ( cfunc ( n , i , <NUM_LIT> ) , expected ) <EOL> def test_len ( self ) : <EOL> self . check_unary_with_size ( list_len ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_getitem ( self ) : <EOL> self . check_unary_with_size ( list_getitem ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_setitem ( self ) : <EOL> self . check_unary_with_size ( list_setitem ) <EOL> def check_slicing2 ( self , pyfunc ) : <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> sizes = [ <NUM_LIT:5> , <NUM_LIT> ] <EOL> for n in sizes : <EOL> indices = [ <NUM_LIT:0> , <NUM_LIT:1> , n - <NUM_LIT:2> , - <NUM_LIT:1> , - <NUM_LIT:2> , - n + <NUM_LIT:3> , - n - <NUM_LIT:1> , - n ] <EOL> for start , stop in itertools . product ( indices , indices ) : <EOL> expected = pyfunc ( n , start , stop ) <EOL> self . assertPreciseEqual ( cfunc ( n , start , stop ) , expected ) <EOL> def test_getslice2 ( self ) : <EOL> self . check_slicing2 ( list_getslice2 ) <EOL> def test_setslice2 ( self ) : <EOL> pyfunc = list_setslice2 <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> sizes = [ <NUM_LIT:5> , <NUM_LIT> ] <EOL> for n , n_src in itertools . product ( sizes , sizes ) : <EOL> indices = [ <NUM_LIT:0> , <NUM_LIT:1> , n - <NUM_LIT:2> , - <NUM_LIT:1> , - <NUM_LIT:2> , - n + <NUM_LIT:3> , - n - <NUM_LIT:1> , - n ] <EOL> for start , stop in itertools . product ( indices , indices ) : <EOL> expected = pyfunc ( n , n_src , start , stop ) <EOL> self . assertPreciseEqual ( cfunc ( n , n_src , start , stop ) , expected ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_getslice3 ( self ) : <EOL> pyfunc = list_getslice3 <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> for n in [ <NUM_LIT:10> ] : <EOL> indices = [ <NUM_LIT:0> , <NUM_LIT:1> , n - <NUM_LIT:2> , - <NUM_LIT:1> , - <NUM_LIT:2> , - n + <NUM_LIT:3> , - n - <NUM_LIT:1> , - n ] <EOL> steps = [ <NUM_LIT:4> , <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:2> , - <NUM_LIT:3> ] <EOL> for start , stop , step in itertools . product ( indices , indices , steps ) : <EOL> expected = pyfunc ( n , start , stop , step ) <EOL> self . assertPreciseEqual ( cfunc ( n , start , stop , step ) , expected ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_setslice3 ( self ) : <EOL> pyfunc = list_setslice3 <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> for n in [ <NUM_LIT:10> ] : <EOL> indices = [ <NUM_LIT:0> , <NUM_LIT:1> , n - <NUM_LIT:2> , - <NUM_LIT:1> , - <NUM_LIT:2> , - n + <NUM_LIT:3> , - n - <NUM_LIT:1> , - n ] <EOL> steps = [ <NUM_LIT:4> , <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:2> , - <NUM_LIT:3> ] <EOL> for start , stop , step in itertools . product ( indices , indices , steps ) : <EOL> expected = pyfunc ( n , start , stop , step ) <EOL> self . assertPreciseEqual ( cfunc ( n , start , stop , step ) , expected ) <EOL> def test_setslice3_resize ( self ) : <EOL> self . disable_leak_check ( ) <EOL> pyfunc = list_setslice3_arbitrary <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> cfunc ( <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> with self . assertRaises ( ValueError ) as cm : <EOL> cfunc ( <NUM_LIT:5> , <NUM_LIT:100> , <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:2> ) <EOL> self . assertIn ( "<STR_LIT>" , str ( cm . exception ) ) <EOL> def test_delslice0 ( self ) : <EOL> self . check_unary_with_size ( list_delslice0 ) <EOL> def test_delslice1 ( self ) : <EOL> self . check_slicing2 ( list_delslice1 ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_delslice2 ( self ) : <EOL> self . check_slicing2 ( list_delslice2 ) <EOL> def test_invalid_slice ( self ) : <EOL> self . disable_leak_check ( ) <EOL> pyfunc = list_getslice3 <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> with self . assertRaises ( ValueError ) as cm : <EOL> cfunc ( <NUM_LIT:10> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> self . assertEqual ( str ( cm . exception ) , "<STR_LIT>" ) <EOL> def test_iteration ( self ) : <EOL> self . check_unary_with_size ( list_iteration ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_reverse ( self ) : <EOL> self . check_unary_with_size ( list_reverse ) <EOL> def test_contains ( self ) : <EOL> self . check_unary_with_size ( list_contains ) <EOL> def check_index_result ( self , pyfunc , cfunc , args ) : <EOL> try : <EOL> expected = pyfunc ( * args ) <EOL> except ValueError : <EOL> with self . assertRaises ( ValueError ) : <EOL> cfunc ( * args ) <EOL> else : <EOL> self . assertPreciseEqual ( cfunc ( * args ) , expected ) <EOL> def test_index1 ( self ) : <EOL> self . disable_leak_check ( ) <EOL> pyfunc = list_index1 <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> for v in ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT> ) : <EOL> self . check_index_result ( pyfunc , cfunc , ( <NUM_LIT:16> , v ) ) <EOL> def test_index2 ( self ) : <EOL> self . disable_leak_check ( ) <EOL> pyfunc = list_index2 <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> n = <NUM_LIT:16> <EOL> for v in ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT> ) : <EOL> indices = [ <NUM_LIT:0> , <NUM_LIT:1> , n - <NUM_LIT:2> , n - <NUM_LIT:1> , n + <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:2> , - n + <NUM_LIT:3> , - n - <NUM_LIT:1> ] <EOL> for start in indices : <EOL> self . check_index_result ( pyfunc , cfunc , ( <NUM_LIT:16> , v , start ) ) <EOL> def test_index3 ( self ) : <EOL> self . disable_leak_check ( ) <EOL> pyfunc = list_index3 <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> n = <NUM_LIT:16> <EOL> for v in ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT> ) : <EOL> indices = [ <NUM_LIT:0> , <NUM_LIT:1> , n - <NUM_LIT:2> , n - <NUM_LIT:1> , n + <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:2> , - n + <NUM_LIT:3> , - n - <NUM_LIT:1> ] <EOL> for start , stop in itertools . product ( indices , indices ) : <EOL> self . check_index_result ( pyfunc , cfunc , ( <NUM_LIT:16> , v , start , stop ) ) <EOL> def test_remove ( self ) : <EOL> pyfunc = list_remove <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> n = <NUM_LIT:16> <EOL> for v in ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:15> ) : <EOL> expected = pyfunc ( n , v ) <EOL> self . assertPreciseEqual ( cfunc ( n , v ) , expected ) <EOL> def test_remove_error ( self ) : <EOL> self . disable_leak_check ( ) <EOL> pyfunc = list_remove <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> with self . assertRaises ( ValueError ) as cm : <EOL> cfunc ( <NUM_LIT:10> , <NUM_LIT> ) <EOL> self . assertEqual ( str ( cm . exception ) , "<STR_LIT>" ) <EOL> def test_count ( self ) : <EOL> pyfunc = list_count <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> for v in range ( <NUM_LIT:5> ) : <EOL> self . assertPreciseEqual ( cfunc ( <NUM_LIT> , v ) , pyfunc ( <NUM_LIT> , v ) ) <EOL> @ unittest . skipUnless ( sys . version_info >= ( <NUM_LIT:3> , <NUM_LIT:3> ) , <EOL> "<STR_LIT>" ) <EOL> def test_clear ( self ) : <EOL> self . check_unary_with_size ( list_clear ) <EOL> @ unittest . skipUnless ( sys . version_info >= ( <NUM_LIT:3> , <NUM_LIT:3> ) , <EOL> "<STR_LIT>" ) <EOL> def test_copy ( self ) : <EOL> self . check_unary_with_size ( list_copy ) <EOL> def check_add ( self , pyfunc ) : <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> sizes = [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:50> , <NUM_LIT> ] <EOL> for m , n in itertools . product ( sizes , sizes ) : <EOL> expected = pyfunc ( m , n ) <EOL> self . assertPreciseEqual ( cfunc ( m , n ) , expected ) <EOL> def test_add ( self ) : <EOL> self . check_add ( list_add ) <EOL> def test_add_heterogenous ( self ) : <EOL> pyfunc = list_add_heterogenous <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> expected = pyfunc ( ) <EOL> self . assertEqual ( cfunc ( ) , expected ) <EOL> def test_add_inplace ( self ) : <EOL> self . check_add ( list_add_inplace ) <EOL> def test_add_inplace_heterogenous ( self ) : <EOL> pyfunc = list_add_inplace_heterogenous <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> expected = pyfunc ( ) <EOL> self . assertEqual ( cfunc ( ) , expected ) <EOL> def check_mul ( self , pyfunc ) : <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> for n in [ <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:50> , <NUM_LIT> ] : <EOL> for v in [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:0> , - <NUM_LIT:1> , - <NUM_LIT> ] : <EOL> expected = pyfunc ( n , v ) <EOL> self . assertPreciseEqual ( cfunc ( n , v ) , expected ) <EOL> def test_mul ( self ) : <EOL> self . check_mul ( list_mul ) <EOL> def test_mul_inplace ( self ) : <EOL> self . check_mul ( list_mul_inplace ) <EOL> @ unittest . skipUnless ( sys . maxsize >= <NUM_LIT:2> ** <NUM_LIT:32> , <EOL> "<STR_LIT>" ) <EOL> def test_mul_error ( self ) : <EOL> self . disable_leak_check ( ) <EOL> pyfunc = list_mul <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> with self . assertRaises ( MemoryError ) : <EOL> cfunc ( <NUM_LIT:1> , <NUM_LIT:2> ** <NUM_LIT> ) <EOL> with self . assertRaises ( MemoryError ) : <EOL> cfunc ( <NUM_LIT:1> , <NUM_LIT:2> ** <NUM_LIT> ) <EOL> def test_bool ( self ) : <EOL> pyfunc = list_bool <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> for n in [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> ] : <EOL> expected = pyfunc ( n ) <EOL> self . assertPreciseEqual ( cfunc ( n ) , expected ) <EOL> def test_list_passing ( self ) : <EOL> @ jit ( nopython = True ) <EOL> def inner ( lst ) : <EOL> return len ( lst ) , lst [ - <NUM_LIT:1> ] <EOL> @ jit ( nopython = True ) <EOL> def outer ( n ) : <EOL> l = list ( range ( n ) ) <EOL> return inner ( l ) <EOL> self . assertPreciseEqual ( outer ( <NUM_LIT:5> ) , ( <NUM_LIT:5> , <NUM_LIT:4> ) ) <EOL> def _test_compare ( self , pyfunc ) : <EOL> def eq ( args ) : <EOL> self . assertIs ( cfunc ( * args ) , pyfunc ( * args ) , <EOL> "<STR_LIT>" % ( args , ) ) <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> eq ( ( ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) ) <EOL> eq ( ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) ) <EOL> eq ( ( ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) ) <EOL> eq ( ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) ) <EOL> eq ( ( ( <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) ) <EOL> eq ( ( ( <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) ) <EOL> def test_eq ( self ) : <EOL> self . _test_compare ( eq_usecase ) <EOL> def test_ne ( self ) : <EOL> self . _test_compare ( ne_usecase ) <EOL> def test_le ( self ) : <EOL> self . _test_compare ( le_usecase ) <EOL> def test_lt ( self ) : <EOL> self . _test_compare ( lt_usecase ) <EOL> def test_ge ( self ) : <EOL> self . _test_compare ( ge_usecase ) <EOL> def test_gt ( self ) : <EOL> self . _test_compare ( gt_usecase ) <EOL> def test_identity ( self ) : <EOL> pyfunc = identity_usecase <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> self . assertPreciseEqual ( cfunc ( <NUM_LIT:3> ) , pyfunc ( <NUM_LIT:3> ) ) <EOL> def test_bool_list ( self ) : <EOL> pyfunc = bool_list_usecase <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> self . assertPreciseEqual ( cfunc ( ) , pyfunc ( ) ) <EOL> class TestUnboxing ( MemoryLeakMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ contextlib . contextmanager <EOL> def assert_type_error ( self , msg ) : <EOL> with self . assertRaises ( TypeError ) as raises : <EOL> yield <EOL> if msg is not None : <EOL> self . assertRegexpMatches ( str ( raises . exception ) , msg ) <EOL> def check_unary ( self , pyfunc ) : <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> def check ( arg ) : <EOL> expected = pyfunc ( arg ) <EOL> got = cfunc ( arg ) <EOL> self . assertPreciseEqual ( got , expected ) <EOL> return check <EOL> def test_numbers ( self ) : <EOL> check = self . check_unary ( unbox_usecase ) <EOL> check ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> check ( [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_tuples ( self ) : <EOL> check = self . check_unary ( unbox_usecase2 ) <EOL> check ( [ ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:3> , <NUM_LIT:4> ) ] ) <EOL> check ( [ ( <NUM_LIT:1> , <NUM_LIT> ) , ( <NUM_LIT:3> , <NUM_LIT> ) ] ) <EOL> check ( [ ( ) , ( ) , ( ) ] ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_list_inside_tuple ( self ) : <EOL> check = self . check_unary ( unbox_usecase3 ) <EOL> check ( ( <NUM_LIT:1> , [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) ) <EOL> def test_list_of_tuples_inside_tuple ( self ) : <EOL> check = self . check_unary ( unbox_usecase4 ) <EOL> check ( ( <NUM_LIT:1> , [ ( <NUM_LIT:2> , ) , ( <NUM_LIT:3> , ) ] ) ) <EOL> def test_errors ( self ) : <EOL> msg = "<STR_LIT>" <EOL> pyfunc = noop <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> lst = [ <NUM_LIT:1> , <NUM_LIT> ] <EOL> with self . assert_type_error ( msg ) : <EOL> cfunc ( lst ) <EOL> self . assertEqual ( lst , [ <NUM_LIT:1> , <NUM_LIT> ] ) <EOL> with self . assert_type_error ( msg ) : <EOL> cfunc ( [ <NUM_LIT:1> , <NUM_LIT> ] ) <EOL> with self . assert_type_error ( msg ) : <EOL> cfunc ( ( <NUM_LIT:1> , [ <NUM_LIT:1> , <NUM_LIT> ] ) ) <EOL> with self . assert_type_error ( msg ) : <EOL> cfunc ( Point ( <NUM_LIT:1> , [ <NUM_LIT:1> , <NUM_LIT> ] ) ) <EOL> lst = [ ( <NUM_LIT:1> , ) , ( <NUM_LIT:2> , <NUM_LIT:3> ) ] <EOL> with self . assertRaises ( ValueError ) as raises : <EOL> cfunc ( lst ) <EOL> self . assertEqual ( str ( raises . exception ) , <EOL> "<STR_LIT>" ) <EOL> class TestListReflection ( MemoryLeakMixin , TestCase ) : <EOL> """<STR_LIT>""" <EOL> def check_reflection ( self , pyfunc ) : <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> samples = [ ( [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT:0.> ] ) , <EOL> ( [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) , <EOL> ] <EOL> for dest , src in samples : <EOL> expected = list ( dest ) <EOL> got = list ( dest ) <EOL> pyres = pyfunc ( expected , src ) <EOL> with self . assertRefCount ( got , src ) : <EOL> cres = cfunc ( got , src ) <EOL> self . assertPreciseEqual ( cres , pyres ) <EOL> self . assertPreciseEqual ( expected , got ) <EOL> self . assertEqual ( pyres [ <NUM_LIT:0> ] is expected , cres [ <NUM_LIT:0> ] is got ) <EOL> del pyres , cres <EOL> def test_reflect_simple ( self ) : <EOL> self . check_reflection ( reflect_simple ) <EOL> def test_reflect_conditional ( self ) : <EOL> self . check_reflection ( reflect_conditional ) <EOL> def test_reflect_exception ( self ) : <EOL> """<STR_LIT>""" <EOL> pyfunc = reflect_exception <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> l = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> with self . assertRefCount ( l ) : <EOL> with self . assertRaises ( ZeroDivisionError ) : <EOL> cfunc ( l ) <EOL> self . assertPreciseEqual ( l , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT> ] ) <EOL> @ tag ( '<STR_LIT>' ) <EOL> def test_reflect_same_list ( self ) : <EOL> """<STR_LIT>""" <EOL> pyfunc = reflect_dual <EOL> cfunc = jit ( nopython = True ) ( pyfunc ) <EOL> pylist = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> clist = pylist [ : ] <EOL> expected = pyfunc ( pylist , pylist ) <EOL> got = cfunc ( clist , clist ) <EOL> self . assertPreciseEqual ( expected , got ) <EOL> self . assertPreciseEqual ( pylist , clist ) <EOL> self . assertPreciseEqual ( sys . getrefcount ( pylist ) , sys . getrefcount ( clist ) ) <EOL> def test_reflect_clean ( self ) : <EOL> """<STR_LIT>""" <EOL> cfunc = jit ( nopython = True ) ( noop ) <EOL> l = [ <NUM_LIT> ] <EOL> ids = [ id ( x ) for x in l ] <EOL> cfunc ( l ) <EOL> self . assertEqual ( [ id ( x ) for x in l ] , ids ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
