
    BVh                     t    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  edg       dd
       Z	d Z
ddZy	)z!smart_cond and related utilities.    )tensor)tensor_util)cond)control_flow_case)	tf_exportz"__internal__.smart_cond.smart_cond)v1Nc                     t        |      st        d|       t        |      st        d|       t        |       }||r |       S  |       S t        j                  | |||      S )a  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.
  z.Argument `true_fn` must be callable. Received z/Argument `false_fn` must be callable. Received )true_fnfalse_fnname)callable	TypeErrorsmart_constant_valuer   )predr
   r   r   
pred_values        V/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/framework/smart_cond.py
smart_condr      s    ( 
'	
DWIN
OO	(	

9(DF F $D)*YZ99T7X       c                 $   t        | t        j                        r.t        j                  |       }|t        j
                  |       }|S | dv rt        |       }|S t        | t              r| }|S t        d|  dt        |       j                         )a  Return the bool value for `pred`, or None if `pred` had a dynamic value.

  Args:
    pred: A scalar, either a Python bool or tensor.

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

  Raises:
    TypeError: If `pred` is not a Tensor or bool.
  >   r      zNArgument `pred` must be a Tensor, or a Python bool, or 1 or 0. Received: pred=z	 of type )

isinstancer   Tensorr   constant_valuetry_evaluate_constantboolr   type__name__)r   r   s     r   r   r   =   s     fmm$++D1J 44T:j 
 v~dJ 
 $J 
	  ,,06Dz**+- . .r   c                 @    t        j                  t        | |||d      S )a  Like tf.case, except attempts to statically evaluate predicates.

  If any predicate in `pred_fn_pairs` is a bool or has a constant value, the
  associated callable will be called or omitted depending on its value.
  Otherwise this functions like tf.case.

  Args:
    pred_fn_pairs: Dict or list of pairs of a boolean scalar tensor and a
                   callable which returns a list of tensors.
    default: Optional callable that returns a list of tensors.
    exclusive: True iff at most one predicate is allowed to evaluate to `True`.
    name: A name for this operation (optional).

  Returns:
    The tensors returned by the first pair whose predicate evaluated to True, or
    those returned by `default` if none does.

  Raises:
    TypeError: If `pred_fn_pairs` is not a list/dictionary.
    TypeError: If `pred_fn_pairs` is a list but does not contain 2-tuples.
    TypeError: If `fns[i]` is not callable for any i, or `default` is not
               callable.
  T)allow_python_preds)r   _case_helperr   )pred_fn_pairsdefault	exclusiver   s       r   
smart_caser$   \   s)    0 
	'	'

 r   )NNN)NFr$   )__doc__tensorflow.python.frameworkr   r   tensorflow.python.opsr   r    tensorflow.python.util.tf_exportr   r   r   r$    r   r   <module>r*      s@    ( . 3 & 3 6 /B7!  8! H>r   