o
    ®Ÿ?e“  ã                   @   sr   d Z ddlmZ G dd„ deƒZddd„Zd	d
„ Zdd„ Zdd„ Zea	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )zGradient tape utilities.é    )Ú
pywrap_tfec                   @   s&   e Zd ZdZdgZdd„ Zdd„ ZdS )ÚTapez(Represents a gradient propagation trace.Ú_tapec                 C   s
   || _ d S ©N)r   )ÚselfÚtape© r   ú]/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/eager/tape.pyÚ__init__   s   
zTape.__init__c                 C   s   t  | j¡S r   )r   ZTFE_Py_TapeWatchedVariablesr   )r   r   r   r	   Úwatched_variables   s   zTape.watched_variablesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r
   r   r   r   r   r	   r      s
    r   FTc                 C   s   t  | |¡}t|ƒS )z&Pushes a new tape onto the tape stack.)r   ZTFE_Py_TapeSetNewr   )Ú
persistentZwatch_accessed_variablesr   r   r   r	   Úpush_new_tape    s   r   c                 C   ó   t  | j¡ dS )z,Pushes an existing tape onto the tape stack.N)r   ZTFE_Py_TapeSetAddr   ©r   r   r   r	   Ú	push_tape&   ó   r   c                 C   s   t  | j|¡ dS )z2Marks this tensor to be watched by the given tape.N)r   ZTFE_Py_TapeWatchr   )r   Ztensorr   r   r	   Úwatch+   s   r   c                 C   s   | gS r   r   )Úvariabler   r   r	   Údefault_get_variables0   s   r   c                 C   s   t tu sJ ‚| a dS )zºRegisters 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   )Úresolverr   r   r	   Ú"register_watched_variable_resolver9   s   r   c                 C   s.   t |ƒ}|D ]}t | j|¡ t |¡ qdS )z4Marks this variable to be watched by the given tape.N)r   r   ZTFE_Py_TapeWatchVariabler   Ú&TFE_Py_VariableWatcherVariableAccessed)r   r   Ú	variablesÚvarr   r   r	   Úwatch_variableE   s
   þr    c                 C   s*   t | ƒ}|D ]}t |¡ t |¡ qdS )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   r   r   r	   Úvariable_accessedM   s
   
þr"   c                 C   sD   g }| D ]}|j r| t|ƒ¡ q|D ]}t |¡ t |¡ qdS )z¼Notifies 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)Z	trainableÚextendr   r   r!   r   )r   Zaccessedr   r   r   r   r	   Úvariables_accessedY   s   €
þr$   c                 C   r   )z!Pops the given tape in the stack.N)r   ZTFE_Py_TapeSetRemover   r   r   r   r	   Úpop_tapek   r   r%   N)FT)r   Ztensorflow.pythonr   Úobjectr   r   r   r   r   r   r   r    r"   r$   r%   r   r   r   r	   Ú<module>   s   
