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

Function GetContainingWhileContext

tensorflow/python/ops/control_flow_util.py:191–210  ·  view source on GitHub ↗

Returns the first ancestor WhileContext of `ctxt`. Returns `ctxt` if `ctxt` is a WhileContext, or None if `ctxt` is not in a while loop. Args: ctxt: ControlFlowContext stop_ctxt: ControlFlowContext, optional. If provided, the search will end if it sees stop_ctxt. Returns:

(ctxt, stop_ctxt=None)

Source from the content-addressed store, hash-verified

189
190
191def GetContainingWhileContext(ctxt, stop_ctxt=None):
192 """Returns the first ancestor WhileContext of `ctxt`.
193
194 Returns `ctxt` if `ctxt` is a WhileContext, or None if `ctxt` is not in a
195 while loop.
196
197 Args:
198 ctxt: ControlFlowContext
199 stop_ctxt: ControlFlowContext, optional. If provided, the search will end
200 if it sees stop_ctxt.
201
202 Returns:
203 `ctxt` if `ctxt` is a WhileContext, the most nested WhileContext containing
204 `ctxt`, or None if `ctxt` is not in a while loop. If `stop_ctxt` is not
205 `None`, this returns `ctxt` if it matches `stop_ctxt` in its traversal.
206 """
207 while ctxt:
208 if ctxt.IsWhileContext() or ctxt == stop_ctxt: return ctxt
209 ctxt = ctxt.outer_context
210 return None
211
212
213def GetContainingXLAContext(ctxt):

Callers 2

IsInWhileLoopFunction · 0.85

Calls 1

IsWhileContextMethod · 0.45

Tested by

no test coverage detected