Creates a NetBuilder that will execute in a loop as the next step of the current NetBuilder. If `iters` is provided, the loop will execute for `iters` iterations and then stop. `iters` can be a constant or a BlobReference. If `iters` is not provided, the loop will ex
(self, iters=None, name=None)
| 273 | return NetBuilder.current().stop_if(blob) |
| 274 | |
| 275 | def loop(self, iters=None, name=None): |
| 276 | """ |
| 277 | Creates a NetBuilder that will execute in a loop as the next step of |
| 278 | the current NetBuilder. If `iters` is provided, the loop will execute |
| 279 | for `iters` iterations and then stop. `iters` can be a constant or a |
| 280 | BlobReference. If `iters` is not provided, the loop will execute |
| 281 | until `ops.stop` or `ops.stop_if` is called. |
| 282 | Examples: |
| 283 | a = ops.Const(5) |
| 284 | with ops.loop(): |
| 285 | ops.stop_if(ops.LE([a, ops.Const(0)])) |
| 286 | ops.Print(a, 0) |
| 287 | ops.Add([a, ops.Const(-1)], [a]) |
| 288 | Above, 'a' will be printed 5 times, with values 5 to 1. |
| 289 | |
| 290 | with ops.loop(10) as loop: |
| 291 | ops.LogInfo(loop.iter()) |
| 292 | This will print the numbers from 0 to 9. |
| 293 | |
| 294 | x = ops.Add([ops.Const(10), ops.Const(10)]) |
| 295 | with ops.loop(x) as loop: |
| 296 | ops.LogInfo(loop.iter()) |
| 297 | This will print the numbers from 0 to 19. |
| 298 | """ |
| 299 | return NetBuilder.current().add(_Loop(iters, name=name)) |
| 300 | |
| 301 | def stop_guard(self, has_stopped_blob=None, name=None): |
| 302 | """ |