
    BVhb
              	           d Z ddlZddlZddlmZ  G d d ej
                  dddg            Zd Zej                  d	        Z	y)
z}Utilities for managing forward accumulators.

A separate file from forwardprop.py so that functions can use these utilities.
    N)
pywrap_tfec                   $     e Zd ZdZd fd	Z xZS )TangentInfozFPacked forward accumulator state. The return value of `pack_tangents`.c                 >    |d}|g }t         t        |   | ||      S )N )superr   __new__)clsindicestangents	__class__s      X/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/eager/forwardprop_util.pyr	   zTangentInfo.__new__   s.    ghc*3BB    )NN)__name__
__module____qualname____doc__r	   __classcell__)r   s   @r   r   r      s    NC Cr   r   r   r   c                 8    t        t        j                  |        S )a$  Packs forward accumulator state into a TangentInfo tuple.

  Args:
    tensors: A flat list of Tensors to pack forward accumulator state for.

  Returns:
    A tuple of (indices, tangents):
      indices: A sequence of sequences of two-element tuples. Each forward
        accumulator is represented as a sequence of tuples with (primal_index,
        jvp_index). Both integers index into the concatenated `tensors + jvps`
        array.
      tangents: A flat list of Tensors. Best interpreted as a sequence to be
        appended to `tensors`.
  )r   r   TFE_Py_PackJVPs)tensorss    r   pack_tangentsr   &   s     
j009	::r   c               #      K   	 t        j                          d t        j                          y# t        j                          w xY ww)a  Temporarily push or pop transient state for accumulators in the active set.

  Allows an accumulator which is currently processing an operation to
  temporarily reset its state. This is useful when building forwardprop versions
  of functions, where an accumulator will trigger function building and then
  must process captured symbolic tensors while building it. Without pushing and
  popping, accumulators ignore operations executed as a direct result of their
  own jvp computations.

  Yields:
    None (used for its side effect).
  N)r   "TFE_Py_ForwardAccumulatorPushState!TFE_Py_ForwardAccumulatorPopStater   r   r   push_forwardprop_stater   8   s2     3113	002J002s   A
1 A
AA
)
r   collections
contextlibtensorflow.pythonr   
namedtupler   r   contextmanagerr   r   r   r   <module>r"      sW   
   (	CK=9j*AB	C;$ 3 3r   