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

v1.8
liym27 5 years ago committed by GitHub
parent f66594a558
commit 080d37a501
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -109,8 +109,10 @@ class LogicalOpTransformer(gast.NodeTransformer):
len(nodes))
if len(nodes) > 2:
# Creates logic_and/logic_or node recursively.
pre_assign_node = self._create_bool_op_node(nodes[:2], api_type)
nodes = [pre_assign_node] + nodes[2:]
pre_logic_node = self._create_bool_op_node(nodes[:2], api_type)
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]
new_node_str = "fluid.layers.logical_{}(x={}, y={})".format(
api_type, args[0], args[1])

@ -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
x = fluid.dygraph.to_variable(
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
x = x + 1
return i

Loading…
Cancel
Save