MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / CondContext

Class CondContext

tensorflow/python/ops/control_flow_ops.py:808–1083  ·  view source on GitHub ↗

The context for the conditional construct.

Source from the content-addressed store, hash-verified

806
807
808class CondContext(ControlFlowContext):
809 """The context for the conditional construct."""
810
811 def __init__(self,
812 pred=None,
813 pivot=None,
814 branch=None,
815 name="cond_text",
816 context_def=None,
817 import_scope=None):
818 """Creates a `CondContext`.
819
820 Args:
821 pred: The `boolean` tensor for the conditional predicate.
822 pivot: The predicate tensor in this branch.
823 branch: 0 or 1 representing this branch.
824 name: Name of the `CondContext` python object.
825 context_def: Optional `ContextDef` protocol buffer to initialize the
826 `CondContext` object from.
827 import_scope: Optional `string`. Name scope to add. Only used when
828 initialing from protocol buffer.
829 """
830 self._name = ops.get_default_graph().unique_name(name)
831
832 if context_def:
833 self._init_from_proto(context_def, import_scope=import_scope)
834 else:
835 # Initializes the default fields.
836 ControlFlowContext.__init__(self)
837 self._pred = pred # The boolean tensor for the cond predicate
838 self._pivot = pivot # The predicate tensor in this branch
839 self._branch = branch # 0 or 1 representing this branch
840
841 # Values considered to have been already seen in this context. pred is not
842 # included in this context.
843 self._values.add(pred.name)
844 self._external_values[pred.name] = pred
845 self._values.add(pivot.name)
846 pivot.op._set_control_flow_context(self) # pylint: disable=protected-access
847
848 def _init_from_proto(self, context_def, import_scope=None):
849 """Creates a new `CondContext` from protocol buffer.
850
851 Args:
852 context_def: `CondContextDef` protocol buffer.
853 import_scope: Optional `string`. Name scope to add.
854 """
855 assert isinstance(context_def, control_flow_pb2.CondContextDef)
856 # Create from context_def.
857 g = ops.get_default_graph()
858 self._name = ops.prepend_name_scope(context_def.context_name, import_scope)
859 self._pred = g.as_graph_element(
860 ops.prepend_name_scope(context_def.pred_name, import_scope))
861 self._pivot = g.as_graph_element(
862 ops.prepend_name_scope(context_def.pivot_name, import_scope))
863 self._branch = context_def.branch
864 super(CondContext, self).__init__(
865 values_def=context_def.values_def, import_scope=import_scope)

Callers 2

from_protoMethod · 0.85
condFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected