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`.
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 N instances. If cond[i] == True, input instance input[i] will go through true_block() and generate output[i]; otherwise it will produce output from false_bloack().
```python
import paddle as pd
x = var()
y = var()
cond = var()
b = pd.create_ifop(inputs=[x], output_num=1)
with b.true_block():
x = b.inputs(0)
z = operator.add(x, y)
b.set_output(0, operator.softmax(z))
out = b(cond)
```
If we want the output still has N instances, we can use IfElseOp with a default value, whose minibatch size must be N:
```python
```python
import paddle as pd
import paddle as pd
...
@@ -39,7 +21,7 @@ with b.false_block():
...
@@ -39,7 +21,7 @@ with b.false_block():
out = b(cond)
out = b(cond)
```
```
If only true_block is set in an IfElseOp, we can have a default value for false as:
If only true_block is set in an IfElseOp, a special case is that we can have a default value for false as:
<p>IfOp should have only one branch. An IfOp operator takes a <codeclass="docutils literal"><spanclass="pre">cond</span></code> 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 <codeclass="docutils literal"><spanclass="pre">cond</span></code>.</p>
<p>IfOp should have only one branch. An IfOp operator takes a <codeclass="docutils literal"><spanclass="pre">cond</span></code> variable whose value must be a vector of N boolean elements. Its return value has N instances. If cond[i] == True, input instance input[i] will go through true_block() and generate output[i]; otherwise it will produce output from false_bloack().</p>
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`.
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 N instances. If cond[i] == True, input instance input[i] will go through true_block() and generate output[i]; otherwise it will produce output from false_bloack().
```python
import paddle as pd
x = var()
y = var()
cond = var()
b = pd.create_ifop(inputs=[x], output_num=1)
with b.true_block():
x = b.inputs(0)
z = operator.add(x, y)
b.set_output(0, operator.softmax(z))
out = b(cond)
```
If we want the output still has N instances, we can use IfElseOp with a default value, whose minibatch size must be N:
```python
```python
import paddle as pd
import paddle as pd
...
@@ -39,7 +21,7 @@ with b.false_block():
...
@@ -39,7 +21,7 @@ with b.false_block():
out = b(cond)
out = b(cond)
```
```
If only true_block is set in an IfElseOp, we can have a default value for false as:
If only true_block is set in an IfElseOp, a special case is that we can have a default value for false as:
<p>IfOp should have only one branch. An IfOp operator takes a <codeclass="docutils literal"><spanclass="pre">cond</span></code> 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 <codeclass="docutils literal"><spanclass="pre">cond</span></code>.</p>
<p>IfOp should have only one branch. An IfOp operator takes a <codeclass="docutils literal"><spanclass="pre">cond</span></code> variable whose value must be a vector of N boolean elements. Its return value has N instances. If cond[i] == True, input instance input[i] will go through true_block() and generate output[i]; otherwise it will produce output from false_bloack().</p>