Execute nets_or_steps once if condition_blob_or_net evaluates as true. If condition_blob_or_net is Net, the condition is its last external_output that must be a single bool. And this net will be executed before nets_or_steps so as to get the condition.
(name, condition_blob_or_net, nets_or_steps)
| 293 | |
| 294 | |
| 295 | def _RunOnceIf(name, condition_blob_or_net, nets_or_steps): |
| 296 | """ |
| 297 | Execute nets_or_steps once if condition_blob_or_net evaluates as true. |
| 298 | |
| 299 | If condition_blob_or_net is Net, the condition is its last external_output |
| 300 | that must be a single bool. And this net will be executed before |
| 301 | nets_or_steps so as to get the condition. |
| 302 | """ |
| 303 | condition_not_net, stop_blob = NotNet(condition_blob_or_net) |
| 304 | if isinstance(condition_blob_or_net, core.Net): |
| 305 | nets_or_steps = _PrependNets( |
| 306 | nets_or_steps, condition_blob_or_net, condition_not_net) |
| 307 | else: |
| 308 | nets_or_steps = _PrependNets(nets_or_steps, condition_not_net) |
| 309 | |
| 310 | def if_step(control_name): |
| 311 | return core.scoped_execution_step( |
| 312 | _get_next_step_name(control_name, name), |
| 313 | nets_or_steps, |
| 314 | should_stop_blob=stop_blob, |
| 315 | only_once=True, |
| 316 | ) |
| 317 | |
| 318 | if _IsNets(nets_or_steps): |
| 319 | bool_net = BoolNet((stop_blob, False)) |
| 320 | return Do(name + '/_RunOnceIf', |
| 321 | bool_net, if_step('_RunOnceIf-inner')) |
| 322 | else: |
| 323 | return if_step('_RunOnceIf') |
| 324 | |
| 325 | |
| 326 | def _RunOnceIfNot(name, condition_blob_or_net, nets_or_steps): |
no test coverage detected
searching dependent graphs…