In an if_op, only inputs with condition satisfied will be run. The op could have multiple inputs and multiple outputs.
We should have the following design:
IfOp should have only one branch. An IfOp operator takes a `cond` variable whose value must be a vector of N boolean elements. Its return value has M (M<=N) instances, each corresponds to a true element in `cond`.
```python
# A 1-d bool vector
cond=Var()
# create an op
if=pd.if_op()
withif.true_block()asblock:
x1=if.input(x1)
x2=if.input(x2)
y=pd.add(x1,x2)
y2=pd.fc(x1)# contains (w,b)
if.output(y)
if.output(y2)
o1,o2=if(cond)
importpaddleaspd
x=var()
y=var()
cond=var()
b=pd.create_ifop_builder(inputs=[x],output_num=1)
withb.true_block():
x=b.inputs(0)
z=operator.add(x,y)
b.set_output(0,operator.softmax(z))
out=b(cond)
```
In an if_op, only inputs with condition satisfied will be run.
We should have the following design:
If we want the output still has N instances, we can use IfElseOp with a default value, whose minibatch size must be N: