o
    ?e                     @   sl   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 Z
d	d
 Zdd Zdd Zdd ZdS )z3Decorator to overrides the gradient for a function.    )pywrap_tf_session)cpp_shape_inference_pb2)dtypes)core)compatc                 C   sl   t | tjrt | tjrJ | jj }t|| 	 }W d    n1 s'w   Y  t
jjt|S )N)
isinstancer   SymbolValuegraph_c_graphgetr   ZGetHandleShapeAndType_as_tf_outputr   CppShapeInferenceResult
HandleDataZ
FromStringr   as_bytes)Zgraph_opc_graphhandle_data r   g/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/ops/handle_data_util.pyget_resource_handle_data   s   
r   c                 C   s   t | tjr	| jS t| S )z!Obtains HandleData from a tensor.)r   r   r	   _handle_datar   )source_tr   r   r   get_handle_data$   s   r   c                 C   s2   |j tjks|j tjkrt| }t|| dS dS )a  Copies HandleData for variant and resource type tensors if available.

  The CppShapeInferenceResult::HandleData proto contains information about the
  shapes and types of the element tensors of resource/variant type tensors.
  We need to copy this across function boundaries, i.e., when capturing a
  placeholder or when returning a function tensor as output. If we don't do this
  the element tensors will have unknown shapes, e.g., if a TensorList variant
  tensor is captured as a placeholder, elements popped from that list would have
  unknown shape.

  Args:
    source_t: The tensor to copy HandleData from.
    target_t: The tensor to copy HandleData to.
  N)dtyper   resourcevariantr   set_handle_data)r   target_tr   r   r   r   copy_handle_data+   s   
r   c                 C   sv   |du s
|j r
|jsdS t| tjr|| _dS | jj }t	
||  |  W d   dS 1 s4w   Y  dS )z%Sets handle data on the giver tensor.N)is_setshape_and_typer   r   r	   r   r
   r   r   r   ZSetHandleShapeAndTyper   ZSerializeToString)r   r   r   r   r   r   r   @   s   "r   c                 C   s2   t j }d|_|jt jj|  |jd |S )NT)shaper   )	r   r   r   r   r    appendZHandleShapeAndTypeZas_protoZas_datatype_enum)r!   r   r   r   r   r   create_handle_dataS   s   

r#   N)__doc__Ztensorflow.python.clientr   Ztensorflow.python.frameworkr   r   Ztensorflow.python.typesr   Ztensorflow.python.utilr   r   r   r   r   r#   r   r   r   r   <module>   s   