MCPcopy Index your code
hub / github.com/pytorch/pytorch / loop

Method loop

caffe2/python/net_builder.py:275–299  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers 9

_test_loopFunction · 0.45
_actual_loopMethod · 0.45
test_multi_instanceMethod · 0.45
test_loopMethod · 0.45
example_loopFunction · 0.45
procMethod · 0.45

Calls 3

_LoopClass · 0.85
currentMethod · 0.80
addMethod · 0.45

Tested by 9

_test_loopFunction · 0.36
_actual_loopMethod · 0.36
test_multi_instanceMethod · 0.36
test_loopMethod · 0.36
example_loopFunction · 0.36
procMethod · 0.36