Similar to DoWhile() but execute nets_or_steps when condition_blob_or_net returns false. It will execute nets_or_steps before evaluating condition_blob_or_net. Special case: if condition_blob_or_net is a blob and is pre-set to true, then only the first net/step of nets_or_steps
(name, condition_blob_or_net, nets_or_steps)
| 460 | |
| 461 | |
| 462 | def DoUntil(name, condition_blob_or_net, nets_or_steps): |
| 463 | """ |
| 464 | Similar to DoWhile() but execute nets_or_steps when |
| 465 | condition_blob_or_net returns false. It will execute |
| 466 | nets_or_steps before evaluating condition_blob_or_net. |
| 467 | |
| 468 | Special case: if condition_blob_or_net is a blob and is pre-set to |
| 469 | true, then only the first net/step of nets_or_steps will be executed and |
| 470 | loop is exited. So you need to be careful about the initial value the |
| 471 | condition blob when using DoUntil(), esp when DoUntil() is called twice. |
| 472 | """ |
| 473 | if not isinstance(condition_blob_or_net, core.Net): |
| 474 | stop_blob = core.BlobReference(condition_blob_or_net) |
| 475 | return core.scoped_execution_step( |
| 476 | _get_next_step_name('DoUntil', name), |
| 477 | nets_or_steps, |
| 478 | should_stop_blob=stop_blob) |
| 479 | |
| 480 | nets_or_steps = _AppendNets(nets_or_steps, condition_blob_or_net) |
| 481 | stop_blob = GetConditionBlobFromNet(condition_blob_or_net) |
| 482 | |
| 483 | # If stop_blob is pre-set to True (this may happen when DoWhile() is |
| 484 | # called twice), the loop will exit after executing the first net/step |
| 485 | # in nets_or_steps. This is not what we want. So we use BootNet to |
| 486 | # set stop_blob to False. |
| 487 | bool_net = BoolNet((stop_blob, False)) |
| 488 | return Do(name + '/DoUntil', bool_net, core.scoped_execution_step( |
| 489 | _get_next_step_name('DoUntil-inner', name), |
| 490 | nets_or_steps, |
| 491 | should_stop_blob=stop_blob, |
| 492 | )) |
| 493 | |
| 494 | |
| 495 | def Switch(name, *conditions): |
nothing calls this directly
no test coverage detected
searching dependent graphs…