未验证 提交 c2852610 编写于 作者: A Aurelius84 提交者: GitHub

[Dy2Stat]BugFix StaticAanlysis with gast.Subscript (#32969)

* BugFix StaticAanlysis with gast.Subscript

* remove codes
上级 56008aa1
......@@ -368,5 +368,8 @@ class StaticAnalysisVisitor(object):
if isinstance(node.func, gast.Name):
return self.var_env.get_var_type(node.func.id)
if isinstance(node, gast.Subscript):
if self.is_tensor_node(node.value):
return {NodeVarType.TENSOR}
return {NodeVarType.STATEMENT}
......@@ -16,6 +16,7 @@ from __future__ import print_function
import unittest
import paddle
import numpy as np
import paddle.fluid as fluid
from paddle.fluid.dygraph.jit import declarative
......@@ -61,6 +62,33 @@ def test_list_append_in_for_loop(x, iter_num):
return a[0]
paddle.jit.set_code_level(100)
def test_list_append_in_for_subscript(x):
x = fluid.dygraph.to_variable(x)
iter_num = paddle.shape(x)[0]
a = []
for i in range(iter_num):
x = x + 1
a.append(x)
out = paddle.concat(a)
return out[0]
def test_list_append_in_while_loop_subscript(x):
x = fluid.dygraph.to_variable(x)
iter_num = paddle.shape(x)[0]
a = []
i = 0
while i < iter_num:
x = x + 1
a.append(x)
i += 1
out = paddle.concat(a)
return out[0]
def test_list_append_in_for_loop_with_concat(x, iter_num):
x = fluid.dygraph.to_variable(x)
a = []
......@@ -261,5 +289,16 @@ class TestListInForLoopWithConcat(TestListInWhileLoopWithStack):
self.all_dygraph_funcs = [test_list_append_in_for_loop_with_concat, ]
class TestListInForLoopWithSubscript(TestListWithoutControlFlow):
def init_dygraph_func(self):
self.all_dygraph_funcs = [
test_list_append_in_for_subscript,
test_list_append_in_while_loop_subscript
]
def init_data(self):
self.input = np.random.random((3, 4)).astype('float32')
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册