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

Function If

caffe2/python/control.py:526–551  ·  view source on GitHub ↗

condition_blob_or_net is first evaluated or executed. If the condition is true, true_nets_or_steps is then executed, otherwise, false_nets_or_steps is executed. If condition_blob_or_net is Net, the condition is its last external_output that must be a single bool. And this Net w

(name, condition_blob_or_net,
       true_nets_or_steps, false_nets_or_steps=None)

Source from the content-addressed store, hash-verified

524
525
526def If(name, condition_blob_or_net,
527 true_nets_or_steps, false_nets_or_steps=None):
528 """
529 condition_blob_or_net is first evaluated or executed. If the condition is
530 true, true_nets_or_steps is then executed, otherwise, false_nets_or_steps
531 is executed.
532
533 If condition_blob_or_net is Net, the condition is its last external_output
534 that must be a single bool. And this Net will be executred before both
535 true/false_nets_or_steps so as to get the condition.
536 """
537 if not false_nets_or_steps:
538 return _RunOnceIf(name + '/If',
539 condition_blob_or_net, true_nets_or_steps)
540
541 if isinstance(condition_blob_or_net, core.Net):
542 condition_blob = GetConditionBlobFromNet(condition_blob_or_net)
543 else:
544 condition_blob = condition_blob_or_net
545
546 return Do(
547 name + '/If',
548 _RunOnceIf(name + '/If-true',
549 condition_blob_or_net, true_nets_or_steps),
550 _RunOnceIfNot(name + '/If-false', condition_blob, false_nets_or_steps)
551 )
552
553
554def IfNot(name, condition_blob_or_net,

Callers 1

build_IfMethod · 0.85

Calls 5

_RunOnceIfFunction · 0.85
isinstanceFunction · 0.85
GetConditionBlobFromNetFunction · 0.85
DoFunction · 0.85
_RunOnceIfNotFunction · 0.85

Tested by

no test coverage detected