Execute nets_or_steps when condition_blob_or_net returns true. Args: condition_blob_or_net: If it is an instance of Net, its last external_output must be a single bool. nets_or_steps: a ExecutionStep or a Net or a list of ExecutionSteps or a list nets.
(name, condition_blob_or_net, nets_or_steps)
| 370 | |
| 371 | |
| 372 | def While(name, condition_blob_or_net, nets_or_steps): |
| 373 | """ |
| 374 | Execute nets_or_steps when condition_blob_or_net returns true. |
| 375 | |
| 376 | Args: |
| 377 | condition_blob_or_net: If it is an instance of Net, its last |
| 378 | external_output must be a single bool. |
| 379 | nets_or_steps: a ExecutionStep or a Net or a list of ExecutionSteps or |
| 380 | a list nets. |
| 381 | |
| 382 | Returns: |
| 383 | A ExecutionStep instance. |
| 384 | """ |
| 385 | condition_not_net, stop_blob = NotNet(condition_blob_or_net) |
| 386 | if isinstance(condition_blob_or_net, core.Net): |
| 387 | nets_or_steps = _PrependNets( |
| 388 | nets_or_steps, condition_blob_or_net, condition_not_net) |
| 389 | else: |
| 390 | nets_or_steps = _PrependNets(nets_or_steps, condition_not_net) |
| 391 | |
| 392 | def while_step(control_name): |
| 393 | return core.scoped_execution_step( |
| 394 | _get_next_step_name(control_name, name), |
| 395 | nets_or_steps, |
| 396 | should_stop_blob=stop_blob, |
| 397 | ) |
| 398 | |
| 399 | if _IsNets(nets_or_steps): |
| 400 | # In this case, while_step has sub-nets: |
| 401 | # [condition_blob_or_net, condition_not_net, nets_or_steps] |
| 402 | # If stop_blob is pre-set to True (this may happen when While() is |
| 403 | # called twice), the loop will exit after executing |
| 404 | # condition_blob_or_net. So we use BootNet to set stop_blob to |
| 405 | # False. |
| 406 | bool_net = BoolNet((stop_blob, False)) |
| 407 | return Do(name + '/While', bool_net, while_step('While-inner')) |
| 408 | else: |
| 409 | return while_step('While') |
| 410 | |
| 411 | |
| 412 | def Until(name, condition_blob_or_net, nets_or_steps): |
no test coverage detected
searching dependent graphs…