condition_blob_or_net is first evaluated or executed. If the condition is true, true_nets_or_steps is then executed, otherwise, false_nets_or_steps is executed. If condition_blob_or_net is Net, the condition is its last external_output that must be a single bool. And this Net w
(name, condition_blob_or_net,
true_nets_or_steps, false_nets_or_steps=None)
| 524 | |
| 525 | |
| 526 | def If(name, condition_blob_or_net, |
| 527 | true_nets_or_steps, false_nets_or_steps=None): |
| 528 | """ |
| 529 | condition_blob_or_net is first evaluated or executed. If the condition is |
| 530 | true, true_nets_or_steps is then executed, otherwise, false_nets_or_steps |
| 531 | is executed. |
| 532 | |
| 533 | If condition_blob_or_net is Net, the condition is its last external_output |
| 534 | that must be a single bool. And this Net will be executred before both |
| 535 | true/false_nets_or_steps so as to get the condition. |
| 536 | """ |
| 537 | if not false_nets_or_steps: |
| 538 | return _RunOnceIf(name + '/If', |
| 539 | condition_blob_or_net, true_nets_or_steps) |
| 540 | |
| 541 | if isinstance(condition_blob_or_net, core.Net): |
| 542 | condition_blob = GetConditionBlobFromNet(condition_blob_or_net) |
| 543 | else: |
| 544 | condition_blob = condition_blob_or_net |
| 545 | |
| 546 | return Do( |
| 547 | name + '/If', |
| 548 | _RunOnceIf(name + '/If-true', |
| 549 | condition_blob_or_net, true_nets_or_steps), |
| 550 | _RunOnceIfNot(name + '/If-false', condition_blob, false_nets_or_steps) |
| 551 | ) |
| 552 | |
| 553 | |
| 554 | def IfNot(name, condition_blob_or_net, |
no test coverage detected