
    BVh                     f    d Z ddlmZ  G d de      ZddZd Zd Zd Zea	d	 Z
d
 Zd Zd Zd Zy)zGradient tape utilities.    )
pywrap_tfec                   "    e Zd ZdZdgZd Zd Zy)Tapez(Represents a gradient propagation trace._tapec                     || _         y N)r   )selftapes     L/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/eager/tape.py__init__zTape.__init__   s	    DJ    c                 @    t        j                  | j                        S r   )r   TFE_Py_TapeWatchedVariablesr   )r	   s    r   watched_variableszTape.watched_variables   s    11$**==r   N)__name__
__module____qualname____doc__	__slots__r   r    r   r   r   r      s    0i)>r   r   c                 D    t        j                  | |      }t        |      S )z&Pushes a new tape onto the tape stack.)r   TFE_Py_TapeSetNewr   )
persistentwatch_accessed_variablesr
   s      r   push_new_taper       s    		%	%j2J	K$	dr   c                 B    t        j                  | j                         y)z,Pushes an existing tape onto the tape stack.N)r   TFE_Py_TapeSetAddr   r
   s    r   	push_taper   &   s    tzz*r   c                 D    t        j                  | j                  |       y)z2Marks this tensor to be watched by the given tape.N)r   TFE_Py_TapeWatchr   )r
   tensors     r   watchr#   +   s    djj&1r   c                     | gS r   r   )variables    r   default_get_variablesr&   0   s
    
r   c                 $    t         t        u sJ | a y)zRegisters the resolver to be used to get the list of variables to watch.

  Args:
    resolver: callable, takes a Variable and returns a list of Variables that
      shall be watched.
  N)_variables_overrider&   )resolvers    r   "register_watched_variable_resolverr*   9   s     
 5	55	5 r   c                     t        |      }|D ]7  }t        j                  | j                  |       t        j                  |       9 y)z4Marks this variable to be watched by the given tape.N)r(   r   TFE_Py_TapeWatchVariabler   &TFE_Py_VariableWatcherVariableAccessed)r
   r%   	variablesvars       r   watch_variabler0   E   s=    !(+) ;c''

C855c:;r   c                 |    t        |       }|D ],  }t        j                  |       t        j                  |       . y)ztNotifies all tapes in the stack that a variable has been accessed.

  Args:
    variable: variable to be watched.
  N)r(   r   TFE_Py_TapeVariableAccessedr-   )r%   r.   r/   s      r   variable_accessedr3   M   s9     "(+) ;c**3/55c:;r   c                     g }| D ])  }|j                   s|j                  t        |             + |D ],  }t        j                  |       t        j
                  |       . y)zNotifies all tapes in the stack that variables have been accessed.

  Only trainable variables are marked as accessed.

  Args:
    variables: iterable of variables to mark as accessed.
  N)	trainableextendr(   r   r2   r-   )r.   accessedr%   r/   s       r   variables_accessedr8   Y   s`     ( 5hoo)(345  ;c**3/55c:;r   c                 B    t        j                  | j                         y)z!Pops the given tape in the stack.N)r   TFE_Py_TapeSetRemover   r   s    r   pop_taper;   k   s    !!$**-r   N)FT)r   tensorflow.pythonr   objectr   r   r   r#   r&   r(   r*   r0   r3   r8   r;   r   r   r   <module>r>      sN     (	>6 	>+
2
 , 	!;	;;$.r   