Created by: Aurelius84
In dygraph, if tensor:
is supported as followed when numel of tensor
is 1:
if tensor:
.....
# it is equivalent to:
if tensor != 0:
.....
In this PR, we fix the bug when node.if
contains statement as above in IfConditionVisitor
and support to transform if tensor
into layers.cond
.
if tensor:
.....
# it will be transformed into:
bool_tensor_0 = fluid.layers.cast(x=tensor, dtype='bool')
res = fluid.layers.cond(bool_tensor_0, lambda :true_fn_0(x), lambda : false_fn_0(x))