@ -94,6 +94,28 @@ def for_loop_dyfunc2(max_len):
return ret
def for_loop_dyfunc3 ( max_len ) :
ret = fluid . layers . zeros ( shape = [ 1 ] , dtype = ' float32 ' )
for i in range ( 1 , 10 , 2 ) :
fluid . layers . increment ( ret , value = 2.0 , in_place = True )
return ret
def for_loop_dyfunc4 ( max_len ) :
ret = fluid . layers . zeros ( shape = [ 1 ] , dtype = ' float32 ' )
for i in range ( 10 , 1 , - 2 ) :
fluid . layers . increment ( ret , value = 2.0 , in_place = True )
return ret
def for_loop_dyfunc_not_support ( max_len ) :
ret = fluid . layers . zeros ( shape = [ 1 ] , dtype = ' float32 ' )
a = - 2
for i in range ( 10 , 1 , a ) :
fluid . layers . increment ( ret , value = 2.0 , in_place = True )
return ret
def while_loop_bool_op ( x ) :
i = fluid . dygraph . to_variable ( x )
@ -333,6 +355,16 @@ class TestTransformForLoop2(TestTransformForLoop):
self . dyfunc = for_loop_dyfunc2
class TestTransformForLoop3 ( TestTransformForLoop ) :
def _init_dyfunc ( self ) :
self . dyfunc = for_loop_dyfunc3
class TestTransformForLoop4 ( TestTransformForLoop ) :
def _init_dyfunc ( self ) :
self . dyfunc = for_loop_dyfunc4
class TestClassVarInForLoop ( TestTransformForLoop ) :
def _init_dyfunc ( self ) :
self . dyfunc = for_loop_class_var
@ -343,5 +375,17 @@ class TestVarCreateInForLoop(TestTransformForLoop):
self . dyfunc = var_create_in_for_loop
class TestErrorInForLoop ( TestTransformForLoop ) :
def _init_dyfunc ( self ) :
self . dyfunc = for_loop_dyfunc_not_support
def test_ast_to_func ( self ) :
with self . assertRaisesRegexp (
NotImplementedError ,
" Dynamic-to-Static only supports the step value is a constant or negative constant "
) :
self . _run_static ( )
if __name__ == ' __main__ ' :
unittest . main ( )