o
    ?e                     @   s   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 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 ddlmZ ddlmZ dddZeddejejdddZdS )z-Assert functions for Control Flow Operations.    )context)dtypes)errors)ops)	array_ops)cond)gen_control_flow_ops)gen_logging_ops)gen_math_ops)dispatch)tf_should_use)	tf_exportNc                 C   s   |du rd}n	|dk rt | }|  r3|  d}dd |d| D }t||jk r2|d nt|drAt	|  g}ng }d
|S )	zReturns a summarized string representation of eager `tensor`.

  Args:
    tensor: EagerTensor to summarize
    summarize: Include these many first elements of `array`
  N   r   )c                 S   s   g | ]}t |qS  )str.0xr   r   j/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/ops/control_flow_assert.py
<listcomp>/   s    z$_summarize_eager.<locals>.<listcomp>z...z, )r   sizeZ_ranknumpyZreshapelenappendr
   	not_equalr   join)Ztensor	summarizeZflatlstr   r   r   _summarize_eager   s   


r   zdebugging.AssertAssertc                    s  t  r% s#t}fdd|D }tjddd d|f ddS t|d gO}t}tdd	 |D rMt	j
 dd
W  d   S tj dd
  fdd}tj tj|dd
}t  rs	 W d   dS |jW  d   S 1 sw   Y  dS )a  Asserts that the given condition is true.

  If `condition` evaluates to false, print the list of tensors in `data`.
  `summarize` determines how many entries of the tensors to print.

  Args:
    condition: The condition to evaluate.
    data: The tensors to print out when condition is false.
    summarize: Print this many entries of each tensor.
    name: A name for this operation (optional).

  Returns:
    assert_op: An `Operation` that, when executed, raises a
    `tf.errors.InvalidArgumentError` if `condition` is not true.
    @compatibility(eager)
    returns None
    @end_compatibility

  Raises:
    @compatibility(TF1)
    When in TF V1 mode (that is, outside `tf.function`) Assert needs a control
    dependency on the output to ensure the assertion executes:

  ```python
  # Ensure maximum element of x is smaller or equal to 1
  assert_op = tf.Assert(tf.less_equal(tf.reduce_max(x), 1.), [x])
  with tf.control_dependencies([assert_op]):
    ... code using x ...
  ```

    @end_compatibility
  c                    s   g | ]}t | qS r   )r   r   )r   r   r   r   e   s    zAssert.<locals>.<listcomp>Nz-Expected '%s' to be true. Summarized data: %s
)Znode_defopmessager    c                 s   s"    | ]}|j tjtjhv V  qd S N)Zdtyper   stringZint32r   r   r   r   	<genexpr>o   s     zAssert.<locals>.<genexpr>name	Conditionc                      s   t j ddS )Nr    r'   )r	   _assertr   	conditiondatar   r   r   true_assertw   s   zAssert.<locals>.true_assertZAssertGuard)r   Zexecuting_eagerlyr   Zconvert_n_to_tensorr   ZInvalidArgumentErrorr   Z
name_scopeallr	   r*   Zconvert_to_tensorr   r   Zno_opr"   )r,   r-   r   r(   ZxsZdata_strr.   Zguarded_assertr   r+   r   r    >   s<   $

$r$   )NN)__doc__Ztensorflow.python.eagerr   Ztensorflow.python.frameworkr   r   r   Ztensorflow.python.opsr   r   r   r	   r
   Ztensorflow.python.utilr   r   Z tensorflow.python.util.tf_exportr   r   Zadd_dispatch_supportZshould_use_resultr    r   r   r   r   <module>   s$   
