o
    ?e                     @   sl   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d
dZ	dd Z
dddZd	S )z!smart_cond and related utilities.    )tensor)tensor_util)cond)control_flow_case)	tf_exportz"__internal__.smart_cond.smart_cond)v1Nc                 C   s^   t |std| t |std| t| }|dur&|r#| S | S tj| |||d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 N)true_fnfalse_fnname)callable	TypeErrorsmart_constant_valuer   )predr   r	   r
   
pred_value r   g/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/framework/smart_cond.py
smart_cond   s   
r   c                 C   sl   t | tjrt| }|du rt| }|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.
  N>   r      zNArgument `pred` must be a Tensor, or a Python bool, or 1 or 0. Received: pred=z	 of type )

isinstancer   ZTensorr   Zconstant_valueZtry_evaluate_constantboolr   type__name__)r   r   r   r   r   r   =   s    


r   F
smart_casec                 C   s   t jt| |||d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)Zallow_python_preds)r   Z_case_helperr   )Zpred_fn_pairsdefaultZ	exclusiver
   r   r   r   r   \   s   )NNN)NFr   )__doc__Ztensorflow.python.frameworkr   r   Ztensorflow.python.opsr   r   Z tensorflow.python.util.tf_exportr   r   r   r   r   r   r   r   <module>   s   
$