Computes loop's condition, used in the context of WhileNet. Last operator must have a single scalar boolean output that will be used as a condition value, no other blobs created in the condition net are visible outside of it
| 707 | |
| 708 | |
| 709 | class _RunWhileCondition(NetBuilder): |
| 710 | """ |
| 711 | Computes loop's condition, used in the context of WhileNet. |
| 712 | Last operator must have a single scalar boolean output that will be used |
| 713 | as a condition value, no other blobs created in the condition net are |
| 714 | visible outside of it |
| 715 | """ |
| 716 | def __init__(self, name=None): |
| 717 | NetBuilder.__init__(self, name=name, _use_control_ops=True) |
| 718 | parent = NetBuilder.current(required=False) |
| 719 | assert parent and isinstance(parent, _RunWhileNet), \ |
| 720 | 'Invalid use of loop condition builder' |
| 721 | assert not parent._cond_builder, \ |
| 722 | 'Multiple loop condition builders specified' |
| 723 | assert len(parent._children) == 0, \ |
| 724 | 'Condition definition must be specified before the loop\'s body' |
| 725 | parent._cond_builder = self |
| 726 | self._cond_blob = None |
| 727 | self._cond_net = None |
| 728 | |
| 729 | def __exit__(self, type, *args): |
| 730 | if type is None: |
| 731 | condition_body = self._children |
| 732 | self._reset_children() |
| 733 | self._cond_net = NetBuilder.merge_nets( |
| 734 | condition_body, self._lexical_scope) |
| 735 | assert self._cond_net, 'Invalid loop condition specified' |
| 736 | assert len(self._cond_net.Proto().op) > 0, 'Invalid condition net' |
| 737 | last_op = self._cond_net.Proto().op[-1] |
| 738 | assert len(last_op.output) == 1, 'Invalid condition net' |
| 739 | self._cond_blob = core.BlobReference(name=last_op.output[0], net=None) |
| 740 | |
| 741 | self._current_net = self._cond_net |
| 742 | self._children = [self._cond_net] |
| 743 | NetBuilder.__exit__(self, type, *args) |
no outgoing calls
no test coverage detected
searching dependent graphs…