
    6biB                     L    S r SSKJs  Jr  S rS rS rS
S jrS r	SS jr
S	 rg)zjUtility functions for control flow.

This file is copied from tensorflow/python/ops/control_flow_util.py.
    Nc                 <    U R                  5       n[        U5      S L$ N)_get_control_flow_contextGetContainingXLAContext)graphctxts     ^/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/utils/control_flow_util.pyInXlaContextr
      s     **,D"4(44    c                 d     [        U 5      (       a  g U R                  n M   ! [         a     gf = f)NTF)r
   outer_graphAttributeError)r   s    r	   GraphOrParentsInXlaContextr      s<    
	%%E	 
  		s   " 
//c                 <    U R                  5       n[        U5      S L$ r   )r   GetContainingWhileContext)opr   s     r	   IsInWhileLoopr   &   s     '')D$T*$66r   c                 t    U (       a1  U R                  5       (       d  X:X  a  U $ U R                  n U (       a  M1  g)a  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` if `ctxt` is a WhileContext, the most nested WhileContext
  containing `ctxt`, or None if `ctxt` is not in a while loop.  If
  `stop_ctxt` is not `None`, this returns `ctxt` if it matches `stop_ctxt`
  in its traversal.
N)IsWhileContextouter_context)r   	stop_ctxts     r	   r   r   +   s7    "   D$5K!! $ r   c                 j    U (       a,  U R                  5       (       a  U $ U R                  n U (       a  M,  g)a0  Returns the first ancestor XLAContext of `ctxt`.

Returns `ctxt` if `ctxt` is a XLAContext, or None if `ctxt` is not in a
while loop.

Args:
  ctxt: ControlFlowContext

Returns:
  `ctxt` if `ctxt` is a XLAContext, the most nested XLAContext containing
  `ctxt`, or None if `ctxt` is not in a while loop.
N)IsXLAContextr   )r   s    r	   r   r   C   s2     K!! $ r   c                     [        U [        R                  5      (       a  [        R                  " XX#S9$ [        R                  R
                  R                  XX#S9$ )at  Return either `true_fn()` if predicate `pred` is true else `false_fn()`.

If `pred` is a bool or has a constant value, we return either `true_fn()`
or `false_fn()`, otherwise we use `tf.cond` to dynamically route to both.

Args:
  pred: A scalar determining whether to return the result of `true_fn` or
    `false_fn`.
  true_fn: The callable to be performed if pred is true.
  false_fn: The callable to be performed if pred is false.
  name: Optional name prefix when using `tf.cond`.

Returns:
  Tensors returned by the call to either `true_fn` or `false_fn`.

Raises:
  TypeError: If `true_fn` or `false_fn` is not callable.
)true_fnfalse_fnname)
isinstancetfVariablecond__internal__
smart_cond)predr   r   r   s       r	   r#   r#   W   sM    & $$$wwtxKK??%%00 1  r   c                 *   [        U [        R                  5      (       a  [        R                  " U 5      $ U S;   a  [	        U 5      $ [        U [        5      (       a  U $ [        U [        R
                  5      (       a  g[        S[        U 5       35      e)ax  Return the bool value for `pred`, or None if `pred` had a dynamic value.

Args:
  pred: A scalar, either a Python bool or a TensorFlow boolean variable
    or tensor, or the Python integer 1 or 0.

Returns:
  True or False if `pred` has a constant boolean value, None otherwise.

Raises:
  TypeError: If `pred` is not a Variable, Tensor or bool, or Python
    integer 1 or 0.
>   r      Nz@`pred` must be a Tensor, or a Python bool, or 1 or 0. Received: )r   r   Tensorget_static_valueboolr    	TypeErrortype)r$   s    r	   constant_valuer,   q   s}     $		""""4((v~Dz$$$$
	$ZL	" r   r   )NNN)__doc__tensorflow.compat.v2compatv2r   r
   r   r   r   r   r#   r,    r   r	   <module>r2      s5   
 " !5
7
0(4r   