Created by: Aurelius84
- Fix
create_cond_node
bug that raises error whilereturn_name_ids
is empty.
# The repetition code
def bug_test(x):
x = to_variable(x)
a = fluid.layers.fill_constant(shape=[1,2], value=9, dtype="int64")
b = fluid.layers.fill_constant(shape=[3], value=3, dtype="int64")
if x.numpy()[0] > 0:
fluid.layers.assign(x, a)
else:
fluid.layers.assign(b, a)
return a
- Support
and/or
in dygraph_to_static control_flow_if
# dygraph function
def foo(x, y=None):
batch_size = fluid.layers.shape(x)
if batch_size[0] > 1 and y is not None:
x = x + 1
if y or batch_size[0] > 1:
x = x - 1
return x
# After transforming into static
def foo(x, y=None):
batch_size = fluid.layers.shape(x)
def true_fn_0(x):
x = x + 1
return x
def false_fn_0(x):
return x
bool_tensor_0 = fluid.layers.fill_constant(shape=[1], value=bool(y is not None), dtype='bool')
logic_and_0 = fluid.layers.logic_and(x=batch_size[0] > 1, y=bool_tensor_0)
x = fluid.layers.cond(logic_and_0, lambda: true_fn_0(x), false_fn_0(x))
def true_fn_1(x):
x = x - 1
return x
def false_fn_1(x):
return x
bool_tensor_1 = fluid.layers.fill_constant(shape=[1], value=bool(y), dtype='bool')
logic_or_0 = fluid.layers.logic_or(x=bool_tensor_1, y=batch_size[0] > 1)
x = fluid.layers.cond(logic_or_0, lambda: true_fn_1(x), false_fn_1(x))
return x
- Support complicate joined
and/or
syntax.
# more than two `and`
if x and batch_size[0] > 1 and y is not None and mean_res.numpy()[0] > 0:
# joined `and/or`
if (x and batch_size[0] > 1) or (y is not None and mean_res.numpy()[0] > 0):