未验证 提交 080d37a5 编写于 作者: L liym27 提交者: GitHub

fix bug in LogicalOpTransformer: Create logic node recursively (#24785)

上级 f66594a5
...@@ -109,8 +109,10 @@ class LogicalOpTransformer(gast.NodeTransformer): ...@@ -109,8 +109,10 @@ class LogicalOpTransformer(gast.NodeTransformer):
len(nodes)) len(nodes))
if len(nodes) > 2: if len(nodes) > 2:
# Creates logic_and/logic_or node recursively. # Creates logic_and/logic_or node recursively.
pre_assign_node = self._create_bool_op_node(nodes[:2], api_type) pre_logic_node = self._create_bool_op_node(nodes[:2], api_type)
nodes = [pre_assign_node] + nodes[2:] post_logic_node = self._create_bool_op_node(nodes[2:], api_type)
nodes = [pre_logic_node] + [post_logic_node]
args = [ast_to_source_code(child) for child in nodes] args = [ast_to_source_code(child) for child in nodes]
new_node_str = "fluid.layers.logical_{}(x={}, y={})".format( new_node_str = "fluid.layers.logical_{}(x={}, y={})".format(
api_type, args[0], args[1]) api_type, args[0], args[1])
......
...@@ -85,7 +85,7 @@ def while_loop_bool_op(x): ...@@ -85,7 +85,7 @@ def while_loop_bool_op(x):
# Use `to_variable` so that static analysis can analyze the type of X is Tensor # Use `to_variable` so that static analysis can analyze the type of X is Tensor
x = fluid.dygraph.to_variable( x = fluid.dygraph.to_variable(
x) # TODO(liym27): Delete it if the type of parameter x can be resolved x) # TODO(liym27): Delete it if the type of parameter x can be resolved
while (x >= 0 and x < 10) or x <= -1 or x < -3 or (x < -7 or x < -5): while x <= -1 or x < -3 or (x < -7 or x < -5) or (x >= 0 and x < 10):
i = i + x i = i + x
x = x + 1 x = x + 1
return i return i
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册