
    AVh#                     4   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  ed
dg      ej                   e
j                  d      dd                     Z ed
g       ej                  dd              Z edg      d        Zy)z?Connects all half, float and double tensors to CheckNumericsOp.    )context)dtypes)ops)	array_ops)control_flow_ops)deprecation)dispatch)	tf_exportzdebugging.assert_all_finiteverify_tensor_all_finite)v1Nc                 |    t        j                  d|d|       }t        j                  d|d|      }t        |||      S )a  Assert that the tensor does not contain any NaN's or Inf's.

  Args:
    t: Tensor to check.
    msg: Message to log on failure.
    name: A name for this operation (optional).
    x: Alias for t.
    message: Alias for msg.

  Returns:
    Same tensor as `t`.
  xtmessagemsg)r   deprecated_argument_lookupverify_tensor_all_finite_v2)r   r   namer   r   s        N/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/numerics.pyr   r      sB      ,,S!S!<!22%&'	$Q	66    c                 @   t        j                  |d| g      5 }t        j                  | d      } t        j                  |       5  t	        j
                  | |      }t        j                  |g|       }ddd       ddd       S # 1 sw Y   xY w# 1 sw Y   S xY w)a  Assert that the tensor does not contain any NaN's or Inf's.

  >>> @tf.function
  ... def f(x):
  ...   x = tf.debugging.assert_all_finite(x, 'Input x must be all finite')
  ...   return x + 1

  >>> f(tf.constant([np.inf, 1, 2]))
  Traceback (most recent call last):
     ...
  InvalidArgumentError: ...

  Args:
    x: Tensor to check.
    message: Message to log on failure.
    name: A name for this operation (optional).

  Returns:
    Same tensor as `x`.
  VerifyFiniter   )r   r   N)r   
name_scopeconvert_to_tensorcolocate_withr   check_numericsr   with_dependencies)r   r   r   verify_inputouts        r   r   r   2   s    . ~~dNQC0 BDac*A			1	 B--aAl..~qAcBB
 
*B BB
 
*s#   -B/B5BB	BBadd_check_numerics_opsc                  T   t        j                         rt        d      g } t        j                         j                         D ]  }|j                  D ]  }|j                  t        j                  t        j                  t        j                  fv s?|j                         t        d      |j                  dz   t        |j                         z   }t        j"                  |       5  t%        j&                  ||      g} ddd         t)        j*                  |  S # 1 sw Y   xY w)a  Connect a `tf.debugging.check_numerics` to every floating point tensor.

  `check_numerics` operations themselves are added for each `half`, `float`,
  or `double` tensor in the current default graph. For all ops in the graph, the
  `check_numerics` op for all of its (`half`, `float`, or `double`) inputs
  is guaranteed to run before the `check_numerics` op on any of its outputs.

  Note: This API is not compatible with the use of `tf.cond` or
  `tf.while_loop`, and will raise a `ValueError` if you attempt to call it
  in such a graph.

  Returns:
    A `group` op depending on all `check_numerics` ops added.

  Raises:
    ValueError: If the graph contains any numeric operations in a control flow
      structure.
    RuntimeError: If called with eager execution enabled.

  @compatibility(eager)
  Not compatible with eager execution. To check for `Inf`s and `NaN`s under
  eager execution, call `tf.debugging.enable_check_numerics()` once before
  executing the checked operations.
  @end_compatibility
  zadd_check_numerics_ops() is not compatible with eager execution. To check for Inf's and NaN's under eager execution, call tf.debugging.enable_check_numerics() once before executing the checked operations.Nz`tf.add_check_numerics_ops() is not compatible with TensorFlow control flow operations such as `tf.cond()` or `tf.while_loop()`.:r   )r   executing_eagerlyRuntimeErrorr   get_default_graphget_operationsoutputsdtyper   float16float32float64_get_control_flow_context
ValueErrorr   strvalue_indexcontrol_dependenciesr   r   r   group)check_opopoutputr   s       r   r!   r!   Q   s   6  
	  (
 !!#224 
Ib** 	I	&..&..&..I	I'')5 ? @ @ ''C-#f&8&8"99%%h/ 	I..vwGH(	I 	I	I
I 
			**	I 	Is   'DD')NNNNN)N)__doc__tensorflow.python.eagerr   tensorflow.python.frameworkr   r   tensorflow.python.opsr   r   tensorflow.python.utilr   r	    tensorflow.python.util.tf_exportr
   add_dispatch_supportdeprecated_endpointsr   r   r!    r   r   <module>r?      s     F + . + + 2 . + 6 ,.HIJ	!!!"<=7 >  K7& (R0	  1: '()1+ *1+r   