
    AVh3                         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  edg 	      d
        Zd Zd Zd Zd Zy)z3Decorator to overrides the gradient for a function.    )pywrap_tf_session)cpp_shape_inference_pb2)dtypes)core)compat)	tf_exportz)__internal__.ops.get_resource_handle_data)v1c                    t        | t        j                        rt        | t        j                        rJ | j                  j
                  j                         5 }t        j                  || j                               }d d d        t        j                  j                  j                  t        j                              S # 1 sw Y   ExY w)N)
isinstancer   SymbolValuegraph_c_graphgetr   GetHandleShapeAndType_as_tf_outputr   CppShapeInferenceResult
HandleData
FromStringr   as_bytes)graph_opc_graphhandle_datas      V/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/handle_data_util.pyget_resource_handle_datar      s    
Xt{{
+Xtzz24 3 ~~""$ +#99'')+K+ 
!	8	8	C	C	N	Nook"
$ $	+ +s   %CCc                 d    t        | t        j                        r| j                  S t	        |       S )z!Obtains HandleData from a tensor.)r   r   r   _handle_datar   )source_ts    r   get_handle_datar   &   s'    $**%   	!(	++    c                     |j                   t        j                  k(  s|j                   t        j                  k(  rt	        |       }t        ||       yy)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   s      r   copy_handle_datar'   -   s=     nn'nn&!(+KHk* 'r    c                 V   ||j                   r|j                  syt        | t        j                        r|| _        y| j                  j                  j                         5 }t        j                  || j                         |j                                ddd       y# 1 sw Y   yxY w)z%Sets handle data on the giver tensor.N)is_setshape_and_typer   r   r   r   r   r   r   r   SetHandleShapeAndTyper   SerializeToString)r&   r   r   s      r   r%   r%   B   s     ''
 $**%'H
~~""$ M++GX5K5K5M,7,I,I,KMM M Ms   "4BB(c                     t         j                  j                         }d|_        |j                  j                  t         j                  j                  | j                         |j                               |S )NT)shaper"   )	r   r   r   r)   r*   appendHandleShapeAndTypeas_protoas_datatype_enum)r.   r"   r   s      r   create_handle_datar3   U   sh    '??JJL++##55HH (>(> I @A 
r    N)__doc__tensorflow.python.clientr   tensorflow.python.frameworkr   r   tensorflow.python.typesr   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   r   r   r'   r%   r3    r    r   <module>r;      sM    : 6 ? . ( ) 6 62>	$ ?	$,+*M&r    