
    AVh                        d Z ddlZddlZddlZddl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 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 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 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'  G d d      Z( G d d      Z) G d d      Z* e'd        G d! d              Z+d" Z,d# Z- e'd$       ej\                  d%       G d& d$ej^                                      Z0 e!jb                   e!jd                  e0ejf                  jh                                G d' d(e#jj                        Z6 ejn                  e+e0jp                  d)*       y)+z2TensorArray: a dynamically sized array of Tensors.    N)
struct_pb2)context)constant_op)dtypes)errors_impl)ops)tensor)tensor_shape)tensor_util)	type_spec)type_spec_registry)	array_ops)array_ops_stack)control_flow_util)gen_control_flow_ops)gen_data_flow_ops)list_ops)math_ops)
tf_logging)nested_structure_coder)trace)tf_should_use)	tf_exportc                   l   e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZed        Zed        Zed        Zed        Z	d Z
ej                  d	        Zd
 ZddZddZddZddZddZddZej,                  dd       Zej,                  dd       Zej,                  dd       ZddZej,                  dd       Zy)_GraphTensorArrayz)Graph-mode implementation of TensorArray.Nc           	         	 |rt        d      |5t        |t        j                        st	        d| dt        |       d      |t        d      |t        d      |	t        d      ||t        d	      |t        d
      d|xs d _        t        j                        j                   _
        |
 _        |
rg  _        nd _        t        j                  	      g _         _         _        t%        j&                  |d||g      5 || _        |t        d      | _        nu	 fd}|
rSt%        j,                  d      5  t%        j.                  dd      5   |       \   _         _        ddd       ddd       n |       \   _         _        ddd       y# 1 sw Y   /xY w# 1 sw Y   xY w# 1 sw Y   yxY w)a  Constructs a graph mode TensorArray.

    Args:
      dtype: (required) data type of the TensorArray.
      size: (optional) int32 scalar `Tensor`: the size of the TensorArray.
        Required if handle is not provided.
      dynamic_size: (optional) Python bool: If true, writes to the TensorArray
        can grow the TensorArray past its initial size.  Default: False.
      clear_after_read: Boolean (optional, default: True).  If True, clear
        TensorArray values after reading them.  This disables read-many
        semantics, but allows early release of memory.
      tensor_array_name: (optional) Python string: the name of the TensorArray.
        This is used when creating the TensorArray handle.  If this value is
        set, handle should be None.
      handle: (optional) A `Tensor` handle to an existing TensorArray.  If this
        is set, tensor_array_name should be None. Only supported in graph mode.
      flow: (optional) A float `Tensor` scalar coming from an existing
        `TensorArray.flow`. Only supported in graph mode.
      infer_shape: (optional, default: True) If True, shape inference is
        enabled.  In this case, all elements must have the same shape.
      element_shape: (optional, default: None) A `TensorShape` object specifying
        the shape constraints of each of the elements of the TensorArray. Need
        not be fully defined.
      colocate_with_first_write_call: If `True`, the TensorArray will be
        colocated on the same device as the Tensor used on its first write
        (write operations include `write`, `unstack`, and `split`).  If `False`,
        the TensorArray will be placed on the device determined by the device
        context available during its initialization.
      name: A name for the operation (optional).

    Raises:
      ValueError: if both handle and tensor_array_name are provided.
      TypeError: if handle is provided but is not a Tensor.
    NzPCannot provide both `handle` and `tensor_array_name` arguments at the same time.z+Expected `handle` to be a Tensor, but got `z` of type `
` instead.z;Argument `size` must be provided if handle is not provided.zECannot provide both a `handle` and `size` arguments at the same time.zLCannot provide both `handle` and `element_shape` arguments at the same time.zKCannot provide both `handle` and `dynamic_size` arguments at the same time.zOCannot provide both `handle` and `clear_after_read` arguments at the same time.TFTensorArrayz,flow must not be None if handle is not None.c            
      R    t        j                  j                         S )zCreate the TensorArray op.)dtypesizeelement_shapeidentical_element_shapesdynamic_sizeclear_after_readtensor_array_namename)r   tensor_array_v3_dynamic_size)r%   r    r"   infer_shapescopeselfr!   r&   s   V/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/tensor_array_ops.pycreatez*_GraphTensorArray.__init__.<locals>.create   s4    "22)'2--/ 1     )ignore_existing)
ValueError
isinstance
tensor_libTensor	TypeErrortyper)   r   as_dtype
base_dtype_dtype_colocate_with_first_write_call_colocate_withr
   as_shape_element_shape_infer_shape_sizer   
name_scope_handle_flowdevicecolocate_with)r,   r    r!   r$   r%   r&   handleflowr*   r"   colocate_with_first_write_callr'   r.   r+   s   ``` ``  ``   @r-   __init__z_GraphTensorArray.__init__8   sA   \ /  *VZ5F5F"G7x @6l^:'( ( ~$,
GI Id. + , ,m7  l6  .:  %.D//%(33DK
 ,JD(%d d (00?@D#DDJ	mfdD-A	B .e		<IJ
J


	 
	 *zz$ 0!2!24!N 0'-x$DL$*0 0 0 &,X
"$,
5. ..0 0 0 0/. .s=   (AG*GGGGG
GG	GG&c                     | j                   S NrB   r,   s    r-   rF   z_GraphTensorArray.flow       ::r/   c                     | j                   S rJ   r9   rL   s    r-   r    z_GraphTensorArray.dtype       ;;r/   c                     | j                   S rJ   rA   rL   s    r-   rE   z_GraphTensorArray.handle   s    <<r/   c                      | j                   d   S Nr   r=   rL   s    r-   r"   z_GraphTensorArray.element_shape       q!!r/   c                     |j                  | j                        st        d|d| j                  d      | j                  r)| j                  j	                  |      | j
                  d<   yya
  Changes the element shape of the array given a shape to merge with.

    Args:
      shape: A `TensorShape` object to merge with.

    Raises:
      ValueError: if the provided shape is incompatible with the current
          element shape of the `TensorArray`.
    zInconsistent shapes: saw z but expected  r   Nis_compatible_withr"   r1   r>   
merge_withr=   r,   shapes     r-   _check_element_shapez&_GraphTensorArray._check_element_shape   d     ##D$6$67t113 4 4#11<<UCd! r/   c              #      K   | j                   sd y| j                  s| j                  j                  |       t        j                  | j                  d         5  d ddd       y# 1 sw Y   yxY ww)a_  Colocate operations with an internal colocation group or `value`.

    Args:
      value: `Tensor`, the tensor to try to colocate with.

    Yields:
      Does not yield anything, but the new context is a colocation context.

    If no internal colocation group is set, colocate with `value` and set
    the internal colocation group to be value.
    Nr   )r:   r;   appendr   rD   r,   values     r-   _maybe_colocate_withz&_GraphTensorArray._maybe_colocate_with   sa      //  ""5)T0034   s   AA7A+"	A7+A40A7c                 X    t        j                  | j                        }t        | |      S See TensorArray.r   identityrB   build_ta_with_new_flowr,   rF   s     r-   rj   z_GraphTensorArray.identity   #    djj)D!$--r/   c           	      ^   || j                   }t        j                  |d| j                  g      5  t        j                  | j                        5  t        j                  | j                  |||      \  }}t        j                  |g      5  t        j                  |d      }ddd       t        | j                  ||| j                  d      }| j                  |j                  _        |cddd       cddd       S # 1 sw Y   \xY w# 1 sw Y   nxY w	 ddd       y# 1 sw Y   yxY w)rh   NTensorArrayGrad)rE   sourceflow_inr'   gradient_flowr'   Fr    rE   rF   r*   rG   )rF   r   r@   rA   rD   r   tensor_array_grad_v3control_dependenciesr   rj   r   r9   r>   r=   _implementation)r,   rp   rF   r'   g_handleunused_flowgs          r-   gradz_GraphTensorArray.grad   s    |YYd	/$,,	@ T\\*  1 F F<<4!I+%%xj1 	@##D?$	@++))+02 ,0+>+>(  	@ 	@    s<    D#=DD&AD.	D#D
DD	D##D,c                     t        j                  | j                  || j                  | j                  |      }| j
                  r(|j                  | j
                  d   j                         |S )rh   )rE   indexrq   r    r'   r   )r   tensor_array_read_v3rA   rB   r9   r=   	set_shapedimsr,   r}   r'   rd   s       r-   readz_GraphTensorArray.read  sZ    22||

kkE ood))!,112Lr/   c           	         t        j                  |d| j                  ||g      5  t        j                  || j                  d      }t        || j                         | j                  |j                         | j                  |      5  t        j                  | j                  ||| j                  |      }ddd       t        |       cddd       S # 1 sw Y   xY w# 1 sw Y   yxY w)rh   TensorArrayWriterd   preferred_dtyper'   )rE   r}   rd   rq   r'   N)r   r@   rA   convert_to_tensorr9   _check_dtypesr_   r^   re   r   tensor_array_write_v3rB   rk   r,   r}   rd   r'   flow_outs        r-   writez_GraphTensorArray.write  s    	04<<2N	O 4##
7<eE4;;'
,$$U+ $::<<JJ $D(34 4 4 4s$   A%C"
/C9C"C	C""C+c           	      2   t        j                  | j                        5  t        j                  |d| j                  g      5  | j	                  t        j                  d| j                               |      }| j                  r^| j                  sR| j                  F|j                  t        j                  | j                        g| j                  j                  z          |cddd       cddd       S # 1 sw Y   nxY w	 ddd       y# 1 sw Y   yxY w)rh   TensorArrayStackr   rs   N)r   rD   rA   r@   gatherr   ranger!   r"   r)   r?   r   r   constant_valuer   )r,   r'   rd   s      r-   stackz_GraphTensorArray.stack"  s    			4<<	( >>$ 2T\\NC HNN1diik:Ft'9'9JJ"
//;55djjAB,,112 3      s$   #DB!C7$	D7D 	<DDc                 D   | j                   r| j                   d   }nt        j                  d      }t        j                  | j
                  || j                  | j                  ||      }| j                  r)|j                  dg| j                  j                  z          |S )rh   r   N)rE   indicesrq   r    r'   r"   )r=   r
   unknown_shaper   tensor_array_gather_v3rA   rB   r9   r"   r   r   )r,   r   r'   r"   rd   s        r-   r   z_GraphTensorArray.gather-  s    ))!,m"006m44||

kk#%E ootft116667Lr/   c           	         t        j                  | j                  | j                  | j                  || j
                  dd       \  }}| j
                  rd}| j                  rFt        j                  | j                               }|!| j
                  d   || j
                  d   z  }|j                  |g| j
                  j                  dd z          |S )rh      N)rE   rq   r    r'   element_shape_except0r   )r   tensor_array_concat_v3rA   rB   r9   r"   r>   r   r   r!   r   r   )r,   r'   rd   _dim0r!   s         r-   concatz_GraphTensorArray.concat>  s     77||

kk"0046HE1 d			))$))+6 2 21 5 A**1--$ootft1166qr::;Lr/   c                     t        j                  |d| j                  |g      5  t        j                  |      d   }| j                  t        j                  d|      ||      cddd       S # 1 sw Y   yxY w)rh   TensorArrayUnstackr   )r   rd   r'   N)r   r@   rA   r   r^   scatterr   r   )r,   rd   r'   num_elementss       r-   unstackz_GraphTensorArray.unstackO  sn     
2T\\54I	J K__U+A.l\\..L1T  KK K Ks   A A..A7c           	      
   t        j                  |d| j                  ||g      5  t        j                  || j                  d      }t        || j                         t        j                         s| j                  |j                  dd        | j                  |      5  t        j                  | j                  ||| j                  |      }ddd       t        |       cddd       S # 1 sw Y   xY w# 1 sw Y   yxY w)rh   TensorArrayScatterrd   r   r   N)rE   r   rd   rq   r'   )r   r@   rA   r   r9   r   r   executing_eagerlyr_   r^   re   r   tensor_array_scatter_v3rB   rk   r,   r   rd   r'   r   s        r-   r   z_GraphTensorArray.scatterW  s     
2ug6
8 4 ##
7<eE4;;'&&(!!%++ab/2$$U+ $<<<<JJ $D(34 4 4 4s$   A<C9!/C-C9-C6	2C99Dc           	      &   t        j                  |d| j                  ||g      5  t        j                  || j                  d      }| j                  |      5  t        j                  |t        j                        }t        j                         st        j                  |      }|j                  j                  s|q|j                  re|j!                         |j#                         k(  rD| j%                  t'        j(                  |d   g      j+                  |j                  dd              t-        j.                  | j                  ||| j0                  |      }ddd       t3        |       cddd       S # 1 sw Y   xY w# 1 sw Y   yxY w)rh   TensorArraySplitrd   )r    r'   Nr   r   )rE   rd   lengthsrq   r'   )r   r@   rA   r   r9   re   r   castr   int64r   r   r   r   r^   r   maxminr_   r
   TensorShapeconcatenater   tensor_array_split_v3rB   rk   r,   rd   r   r'   
lengths_64clengthsr   s          r-   splitz_GraphTensorArray.splitk  sH    
0ug6
8 4##E7Ke$$U+ ]]7FLL9
((* //
;([[)h.B~~(,,.HLLN"B''**HQK ,- ..9k%++ab/.JL %::<<JJ $D(3%4 4 4 4s$   4FDE;F;F	 FFc                     | j                   s;| j                  /t        j                  | j                  t        j
                        S t        j                  | j                  | j                  |      S )rh   r    )rE   rq   r'   )
r)   r?   r   r   r   int32r   tensor_array_size_v3rA   rF   r,   r'   s     r-   r!   z_GraphTensorArray.size  sQ    $**"8""4::V\\BB33tyyt= =r/   c                 D    t        j                  | j                  |      S )rh   )rE   r'   )r   tensor_array_close_v3rA   r   s     r-   closez_GraphTensorArray.close  s      22||$( (r/   
NNNNNNTNTNNNrJ   )__name__
__module____qualname____doc__rH   propertyrF   r    rE   r"   r_   
contextlibcontextmanagerre   rj   r{   r   r   r   r   r   r   should_use_resultr   r   r   r!   r    r/   r-   r   r   5   s.   1   $!%!.2x.t       " "D   (.
2
4"	"" ""K #K ""4 #4& ""4 #4,= ""( #(r/   r   c                   *   e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZed        Zed        Zed        Zed        Z	d Z
d	 Zdd
ZddZddZddZddZddZej&                  dd       Zej&                  dd       Zej&                  dd       ZddZddZy)_GraphTensorArrayV2aO  Graph-mode implementation of TensorArray backed by TensorLists.

  The backing tensor of this TensorArray is a TensorList variant tensor which is
  stored in the `flow`. The `handle` is always none here. The reason we use the
  `flow` field and not the `handle` field is to ensure backwards compatibility
  with legacy control flow.
  Nc                    |J ~~~~
|| _         || _        |Pt        |t        j                        r|j
                  t        j                  k7  rt        d|j
                   d      ||t        d      ||t        d      ||	t        d      t        j                  |      j                  | _        t        j                  |	      g| _        || _        t#        j$                  |d||g      5 }|t'        j(                  |	|||      | _        n|| _        ddd       d| _        d| _        y# 1 sw Y   xY w)	a  Constructs a graph mode TensorArray.

    Args:
      dtype: (required) data type of the TensorArray.
      size: (optional) int32 scalar `Tensor`: the size of the TensorArray.
        Required if flow is not provided.
      dynamic_size: (optional) Python bool: If true, writes to the TensorArray
        can grow the TensorArray past its initial size.  Default: False.
      clear_after_read: (optional) unused. Not supported in TensorLists.
      tensor_array_name: (optional) unused.
      handle: (optional) Must always be None.
      flow: (optional) A variant `Tensor` scalar for a TensorList.
      infer_shape: (optional, default: True) If True, shape inference is
        enabled.  In this case, all elements must have the same shape.
      element_shape: (optional, default: None) A `TensorShape` object specifying
        the shape constraints of each of the elements of the TensorArray. Need
        not be fully defined.
      colocate_with_first_write_call: (optional). unused.
      name: (optional) A name for the operation.

    Raises:
      ValueError: if both handle and tensor_array_name are provided.
      TypeError: if handle is provided but is not a Tensor.
    Nz6Expected `flow` to be a variant tensor, but received `r   zDArgument `size` must be provided if argument `flow` is not provided.zACannot provide both `flow` and `size` arguments at the same time.zICannot provide both `flow` and `element_shape` argumentsat the same time.TensorArrayV2)r"   r   element_dtyper'   )r)   r?   r2   r3   r4   r    r   variantr5   r1   r7   r8   r9   r
   r<   r=   r>   r   r@   r   tensor_list_reserverB   r:   r;   )r,   r    r!   r$   r%   r&   rE   rF   r*   r"   rG   r'   r+   s                r-   rH   z_GraphTensorArrayV2.__init__  sj   H >>&%DDJtZ../4::3OB4::, O   |
P  D,
M  M5 
 //%(33DK (00?@D#D	od|	< 	11'	
 
 ,0D(D s   5)D55D>c                     | j                   S rJ   rK   rL   s    r-   rF   z_GraphTensorArrayV2.flow  rM   r/   c                     | j                   S rJ   rO   rL   s    r-   r    z_GraphTensorArrayV2.dtype  rP   r/   c                      | j                   d   S rT   rU   rL   s    r-   r"   z!_GraphTensorArrayV2.element_shape  rV   r/   c                      y rJ   r   rL   s    r-   rE   z_GraphTensorArrayV2.handle  s     r/   c                     |j                  | j                        st        d|d| j                  d      | j                  r)| j                  j	                  |      | j
                  d<   yyrX   rZ   r]   s     r-   r_   z(_GraphTensorArrayV2._check_element_shape  r`   r/   c                 X    t        j                  | j                        }t        | |      S rg   ri   rl   s     r-   rj   z_GraphTensorArrayV2.identity  rm   r/   c                     t               )zNot supported.NotImplementedErrorr,   rp   rF   r'   s       r-   r{   z_GraphTensorArrayV2.grad  s    

r/   c                     t        j                  |d| j                  |g      5  t        j                  | j                  || j
                  | j                  |      }|cddd       S # 1 sw Y   yxY w)rh   TensorArrayV2Read)input_handler}   r   r"   r'   N)r   r@   rB   r   tensor_list_get_itemr9   r"   r   s       r-   r   z_GraphTensorArrayV2.read  sc    	1DJJ3F	G ++zz**e   s   :A((A1c                    t        j                  |d| j                  ||g      5  t        j                  || j                  d      }t        || j                         | j                  |j                         t        j                  | j                  ||| j                  |      }t        | |      cddd       S # 1 sw Y   yxY w)rh   TensorArrayV2Writerd   r   )r   r}   itemresize_if_index_out_of_boundsr'   N)r   r@   rB   r   r9   r   r_   r^   r   tensor_list_set_itemr)   rk   r   s        r-   r   z_GraphTensorArrayV2.write(  s    	2TZZ4N	O 4##
7<eE4;;'
,..zz(,(:(:h $D(34 4 4s   BB<<Cc                 X   t        j                  |d| j                  g      5  | j                  s,| j                   t        j                  | j                        }nd}t        j                  | j                  | j                  || j                        }|cddd       S # 1 sw Y   yxY w)rh   TensorArrayV2StackN)r   r   r   r"   )r   r@   rB   r)   r?   r   r   r   tensor_list_stackr9   r"   )r,   r'   ta_sizerd   s       r-   r   z_GraphTensorArrayV2.stack8  s    	2TZZL	A DJJ$:,,TZZ8((zz**	,e
   s   A3B  B)c                 v    t        j                  | j                  || j                  | j                  |      }|S )rh   )r   r   r   r"   r'   )r   tensor_list_gatherrB   r9   r"   )r,   r   r'   rd   s       r-   r   z_GraphTensorArrayV2.gatherG  s6    ''ZZkk((E Lr/   c                     | j                   rdg| j                   j                  dd z   }nd}t        j                  | j                  | j
                  ||      }|S )rh   Nr   )r   r   r"   r'   )r"   r   r   tensor_list_concatrB   r9   )r,   r'   r"   rd   s       r-   r   z_GraphTensorArrayV2.concatQ  sZ    ft1166qr::mm''ZZkk#	E
 Lr/   c                    t        j                  |d| j                  |g      5  t        j                  || j                  d      }t        || j                         | j                  |j                  dd        t        j                  ||j                  dd       }t        | |      cddd       S # 1 sw Y   yxY w)rh   r   rd   r   r   Nr	   r"   )r   r@   rB   r   r9   r   r_   r^   r   tensor_list_from_tensorrk   )r,   rd   r'   r   s       r-   r   z_GraphTensorArrayV2.unstack_  s     
2TZZ4G	H 4##
7<eE4;;'
AB011ekk!"o7h#D(34 4 4s   BB44B=c                    t        j                  |d| j                  ||g      5  t        j                  || j                  d      }t        || j                         | j                  |j                  dd        t        j                  ||| j                  | j                        }t        | |      cddd       S # 1 sw Y   yxY w)rh   r   rd   r   r   N)r	   r   r"   r   )r   r@   rB   r   r9   r   r_   r^   r   tensor_list_scatterr"   rk   r   s        r-   r   z_GraphTensorArrayV2.scatterl  s     
2UG4
6 4 ##
7<eE4;;'
AB0--**zz	#h
 $D(34 4 4s   BB>>Cc                    t        j                  |d| j                  ||g      5  t        j                  || j                  d      }t        || j                         t        j                  |t        j                        }t        j                         st        j                  |      }|j                  j                  s|q|j                  re|j!                         |j#                         k(  rD| j%                  t'        j(                  |d   g      j+                  |j                  dd              t-        j.                  ||| j0                  |      }t3        | |      cddd       S # 1 sw Y   yxY w)rh   r   rd   r   Nr   r   )r	   r   r"   r'   )r   r@   rB   r   r9   r   r   r   r   r   r   r   r   r   r^   r   r   r   r_   r
   r   r   r   tensor_list_splitr"   rk   r   s          r-   r   z_GraphTensorArrayV2.split}  s)    
04::ug2N	O 4##
7<eE4;;'==&,,7j&&(--j9;;'H,@^^(,,. @%%(((1+ *+ ,,7KAB,HJ ++**	h
 $D(3%4 4 4s   D=E,,E5c                     | j                   s;| j                  /t        j                  | j                  t        j
                        S t        j                  | j                  |      S )rh   r   )r   r'   )	r)   r?   r   r   r   r   r   tensor_list_lengthrB   r   s     r-   r!   z_GraphTensorArrayV2.size  sF    $**"8""4::V\\BB((djjtLLr/   c                 .    t        j                  |      S )rh   rs   )r   no_opr   s     r-   r   z_GraphTensorArrayV2.close  s    %%400r/   r   r   rJ   )r   r   r   r   rH   r   rF   r    r"   rE   r_   rj   r{   r   r   r   r   r   r   r   r   r   r   r!   r   r   r/   r-   r   r     s       $!%!.2Vp     " "  
D .
 	4  ""
4 #
4 ""4 #4  ""4 #4,M1r/   r   c                       e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZed        Zed        Zed        Zed        Z	d Z
dd	Zdd
Zd ZddZd ZddZddZddZddZddZddZddZddZy)_EagerTensorArrayz/Eager-compatible implementation of TensorArray.Nc                    ~~~|t        d      |t        d      d| _        t        j                  dt        j
                        | _        || _        t        j                  |	      | _
        |
| _        t	        j                  |      j                  | _        |xs d| _        |dn|| _        g | _        t%        |t&        j(                        r|j+                         }t-        |      D cg c]  }d c}| _        yc c}w )a  Constructs a TensorArray compatible with eager execution.

    Args:
      dtype: (required) data type of the TensorArray.
      size: (optional) int32 scalar `Tensor`: the size of the TensorArray.
        Required if handle is not provided.
      dynamic_size: (optional) Python bool: If true, writes to the TensorArray
        can grow the TensorArray past its initial size.  Default: False.
      clear_after_read: Boolean (optional, default: True).  If True, clear
        TensorArray values after reading them.  This disables read-many
        semantics, but allows early release of memory.
      tensor_array_name: unused.
      handle: unsupported.
      flow: unsupported.
      infer_shape: used for error checking, same semantics as TensorArray.
      element_shape: used for error checking, same semantics as TensorArray.
      colocate_with_first_write_call: unsupported.
      name: unsupported.

    Raises:
      ValueError: handle or flow are supplied, or if size is not supplied.
    NzFTensorArray handles are not supported when eager execution is enabled.zGSize must be declared for TensorArrays when eager execution is enabled.r   r   FT)r1   rA   r   constantr   r   rB   r>   r
   r<   r=   r:   r7   r8   r9   r)   _clear_after_read_previously_read_indicesr2   r   EagerTensornumpyr   _tensor_array)r,   r    r!   r$   r%   r&   rE   rF   r*   r"   rG   r'   r   s                r-   rH   z_EagerTensorArray.__init__  s    F 
 $ / 0 0| / 0 0 DL %%av||<DJ#D&//>D+ID(//%(33DK%.D!1!9 #?O 	$&D!$(ZZ\d(-d41$4D4s   /	Dc                     | j                   S )zBFor compatibility; flows are not meaningful when eager is enabled.rK   rL   s    r-   rF   z_EagerTensorArray.flow  s     ::r/   c                     | j                   S rJ   rO   rL   s    r-   r    z_EagerTensorArray.dtype  rP   r/   c                     | j                   S )zDFor compatibility; handles are not meaningful when eager is enabled.rR   rL   s    r-   rE   z_EagerTensorArray.handle  s     <<r/   c                     | j                   S rJ   rU   rL   s    r-   r"   z_EagerTensorArray.element_shape  s    r/   c                 "    | j                         S rg   )parentrL   s    r-   rj   z_EagerTensorArray.identity  s    ;;=r/   c                     t        d      )NzTensorArray.grad is not supported when executing eagerly; eager's gradient implementation does not use/need this function to compute gradients of operations that use TensorArrays.r   r   s       r-   r{   z_EagerTensorArray.grad  s    
	9: :r/   c           	      (   ~t        |t        j                        r|j                         }|dk  rt	        j
                  ddd|z        |t        | j                        k\  r/t	        j
                  ddd|t        | j                        fz        | j                  |   }|9|| j                  v rt	        j                  ddd|z        | j                  |      }| j                  r*d| j                  |<   | j                  j                  |       |S )rh   r   Nz8Reading from negative indices (index %d) is not allowed.z2Tried to read from index %d but array size is: %d zzCould not read index %d twice because it was cleared after a previous read (perhaps try setting clear_after_read = false?))r2   r   r   r   r   OutOfRangeErrorlenr   r   InvalidArgumentError_maybe_zeror   rb   )r,   r}   r'   r	   s       r-   r   z_EagerTensorArray.read  s   %)kkmeqy''

Du
LN N D&&''''
J#d(()
*+, , &F~	$//	/..$N 	 !!%("&d
##**51Mr/   c           	         t        |t        j                        r|j                         }|dk  rt	        j
                  ddd|z        t        | j                        }||k\  rY| j                  st	        j
                  ddd||fz        | j                  j                  d t        ||z
  dz         D               t        |t        j                        s"t        j                  || j                  d      }| j                  |j                  k7  rFt	        j                  ddd	| j                  j                  d
|j                  j                  d      | j                   j#                  |j$                        s&t'        d|j$                  d| j                   d      | j(                  r*| j                   j+                  |j$                        | _        || j                  |<   y)a  Writes `value` into index named by `index`.

    Args:
      index: 0-D.  int32 scalar with the index to write to.
      value: N-D.  Tensor of type `dtype`.  The `Tensor` to write to `index`.

    Raises:
      errors_impl.InvalidArgumentError: `value` dtype does not match dtype.
      errors_impl.OutOfRangeError: `index` is out of bounds.
      ValueError: shape of `value` is not consistent with inferred shape.
    r   Nz6Writing to negative indices (index %d) is not allowed.zGTried to write to index %d but array is not resizeable and size is: %d c              3       K   | ]  }d   y wrJ   r   ).0r   s     r-   	<genexpr>z+_EagerTensorArray._write.<locals>.<genexpr>A  s     FFs   r   rd   r   zTensorArray dtype is z! but Op is trying to write dtype rY   zIncompatible shape for value (z), expected ())r2   r   r   r   r   r  r	  r   r)   extendr   r   r9   r    r
  r'   r=   r[   r^   r1   r>   r\   )r,   r}   rd   r!   s       r-   _writez_EagerTensorArray._write%  s    %)kkmeqy''

BU
JL L t!!"D}))$&' 	' FeEDL14D.EFFeS__-##
7<e {{ekk!,,
;;U[[--/0 0
 11%++>T%8%8: ; ;  //::5;;Gd %Dur/   c                 H    ~| j                  ||       | j                         S rg   )r  r  r,   r}   rd   r'   s       r-   r   z_EagerTensorArray.writeW  s    KKu;;=r/   c                     | j                   |   }|:t        j                  | j                  | j                        x}| j                   |<   |S )N)r^   r    )r   r   zerosr=   r9   )r,   ixvals      r-   r  z_EagerTensorArray._maybe_zero]  sK    


R
 C
{%.__##4;;&8 8cDr"Jr/   c                    | j                   r4t        t        | j                               D ]  }| j                  |        | j                   s]| j                  j                         rCt        j                  t        j                  dg| j                  z         || j                        S t        j                  | j                   || j                        S )rh   r   )r'   r    )r   r   r	  r  r=   is_fully_definedr   r   npndarrayr9   )r,   r'   r  s      r-   r   z_EagerTensorArray.stackd  s    c$,,-. "$"5"5"F"F"H""
**aS4...
/d$++O O ""


4t{{< <r/   c                     ~t        |t        j                        r|j                         }t	        j
                  |D cg c]  }| j                  |       c}      S c c}w rg   )r2   r   r   r   r   r   r  )r,   r   r'   is       r-   r   z_EagerTensorArray.gatherp  sH    '3??+g  w!G!$"2"21"5!GHH!Gs   Ac                    	 t        j                  t        t        | j                              D cg c]  }| j                  |       c}d|      S c c}w # t        j                  $ ry | j                  D cg c]  }|j                   nc c}w }}|D cg c]  }|j                   nc c}w }}d|v r+|j                  d      }t        j                  ddd|z         w xY w)rh   r   rs   NzDConcat saw a scalar shape at index %d but requires at least vectors.)r   r   r   r	  r   r  r   OpErrorr^   ndimsr}   r
  )r,   r'   r  tshapessr!  idxs           r-   r   z_EagerTensorArray.concatw  s    */D4F4F0G*H
IB4B
I
 
I  
!%!3!34A44f4 &'1qww''e'	
ekk!n..$  "%&' 	' 	
s4   /A A		A A !C$9BC$B,+9C$c                    t        j                  ||      }t        |      t        | j                        kD  r8| j                  s,t        dt        |      t        | j                        fz        || _        | j                         S )rh   rs   z?Cannot unstack %d tensors into a TensorArray of static size %d )r   r   r	  r   r)   r1   r  )r,   rd   r'   tensorss       r-   r   z_EagerTensorArray.unstack  su    %%e$7G
7|c$,,--d6H6H
Kw<T//0
123 3 !D;;=r/   c                     ~t        |t        j                        r|j                         }t	        |t        j                  |            D ]  \  }}| j                  ||        | j                         S rg   )	r2   r   r   r   zipr   r   r  r  )r,   r   rd   r'   r}   r  s         r-   r   z_EagerTensorArray.scatter  s]    '3??+g'?#:#:5#AB 
s
kk%;;=r/   c                    t        j                  || j                  d      }t        || j                         t        j                  |      }t	        j
                  |      }|j                  j                  dk7  r2t        j                  ddd|j                  j                         z        |j                  j                  dk(  r2t        j                  ddd|j                  j                         z        |j                         |j                  j                         d   k7  rBt        j                  ddd|j                         |j                  j                         fz        | j                  sa|j                  d   t        | j                        k7  r<t        j                  ddd	t        | j                        |j                  d   fz        t        j                   |||
      | _        | j#                         S )rh   rd   r   r   Nz4Expected lengths to be a vector, received shape: %s r   z?Expected value to be at least a vector, but received shape: %s zjExpected sum of lengths to be equal to values.shape[0], but sum of lengths is %d and value's shape is: %s zTensorArray's size is not equal to the size of lengths (%d vs. %d), and the TensorArray is not marked as dynamically resizeable.rs   )r   r   r9   r   r   
reduce_sumr^   r!  r   r
  as_listr   r)   r	  r   r   r   r  )r,   rd   r   r'   sum_lengthss        r-   r   z_EagerTensorArray.split  s    !!t{{:E%%##G,G%%g.K}}a,,
L
--


!"# # 
		a	,,
 $&+kk&9&9&;<= = 
			 3 3 5a 8	8,,
 "%0%6%6%8%*[[%8%8%:%<<= =
 GMM!$4D<N<N8O$O,,
 $ t!!"GMM!$4
567 7 %??5'Ed[[]r/   c                 T    ~t        j                  t        | j                              S rg   )r   r   r	  r   r   s     r-   r!   z_EagerTensorArray.size  s!    D$6$6 788r/   c                 $    ~| j                   d d = y rJ   )r   r   s     r-   r   z_EagerTensorArray.close  s    1r/   r   r   rJ   )r   r   r   r   rH   r   rF   r    rE   r"   rj   r{   r   r  r   r  r   r   r   r   r   r   r!   r   r   r/   r-   r   r     s    7   $!%!.2@5D        :B0&d
<I&@9
r/   r   r   c                      e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZed        Zed        Zed        Zed        Z	ed	        Z
ed
        Zd ZddZddZ ej                   d      dd       ZddZddZddZej                   dd       Zej                   dd       Zej                   dd       ZddZej                   dd       Zd Zy)r   a  Class wrapping dynamic-sized, per-time-step, Tensor arrays.

  This class is meant to be used with dynamic iteration primitives such as
  `while_loop` and `map_fn`.  It supports gradient back-propagation via special
  "flow" control flow dependencies.

  Note that although the array can be read multiple times and positions can be
  overwritten, behavior may be undefined when storing multiple references to
  the same array and clear_after_read is False. In particular, avoid using
  methods like concat() to convert an intermediate TensorArray to a Tensor,
  then further modifying the TensorArray, particularly if you need to backprop
  through it later.

  Example 1: Plain reading and writing.

  >>> ta = tf.TensorArray(tf.float32, size=0, dynamic_size=True, clear_after_read=False)
  >>> ta = ta.write(0, 10)
  >>> ta = ta.write(1, 20)
  >>> ta = ta.write(2, 30)
  >>>
  >>> ta.read(0)
  <tf.Tensor: shape=(), dtype=float32, numpy=10.0>
  >>> ta.read(1)
  <tf.Tensor: shape=(), dtype=float32, numpy=20.0>
  >>> ta.read(2)
  <tf.Tensor: shape=(), dtype=float32, numpy=30.0>
  >>> ta.stack()
  <tf.Tensor: shape=(3,), dtype=float32, numpy=array([10., 20., 30.],
  dtype=float32)>

  Example 2: Fibonacci sequence algorithm that writes in a loop then returns.

  >>> @tf.function
  ... def fibonacci(n):
  ...   ta = tf.TensorArray(tf.float32, size=0, dynamic_size=True)
  ...   ta = ta.unstack([0., 1.])
  ...
  ...   for i in range(2, n):
  ...     ta = ta.write(i, ta.read(i - 1) + ta.read(i - 2))
  ...
  ...   return ta.stack()
  >>>
  >>> fibonacci(7)
  <tf.Tensor: shape=(7,), dtype=float32,
  numpy=array([0., 1., 1., 2., 3., 5., 8.], dtype=float32)>

  Example 3: A simple loop interacting with a `tf.Variable`.

  >>> v = tf.Variable(1)
  >>> @tf.function
  ... def f(x):
  ...   ta = tf.TensorArray(tf.int32, size=0, dynamic_size=True)
  ...   for i in tf.range(x):
  ...     v.assign_add(i)
  ...     ta = ta.write(i, v)
  ...   return ta.stack()
  >>> f(5)
  <tf.Tensor: shape=(5,), dtype=int32, numpy=array([ 1,  2,  4,  7, 11],
  dtype=int32)>
  NTc                    t        j                         r&||j                  t        j                  k7  rt
        }nS||j                  t        j                  k(  s't        j                  t        j                               rt        }nt        } ||||||||||	|
|      | _        t        j                  |       | j                  _        y)a  Construct a new TensorArray or wrap an existing TensorArray handle.

    A note about the parameter `name`:

    The name of the `TensorArray` (even if passed in) is uniquified: each time
    a new `TensorArray` is created at runtime it is assigned its own name for
    the duration of the run.  This avoids name collisions if a `TensorArray`
    is created within a `while_loop`.

    Args:
      dtype: (required) data type of the TensorArray.
      size: (optional) int32 scalar `Tensor`: the size of the TensorArray.
        Required if handle is not provided.
      dynamic_size: (optional) Python bool: If true, writes to the TensorArray
        can grow the TensorArray past its initial size.  Default: False.
      clear_after_read: Boolean (optional, default: True).  If True, clear
        TensorArray values after reading them.  This disables read-many
        semantics, but allows early release of memory.
      tensor_array_name: (optional) Python string: the name of the TensorArray.
        This is used when creating the TensorArray handle.  If this value is
        set, handle should be None.
      handle: (optional) A `Tensor` handle to an existing TensorArray.  If this
        is set, tensor_array_name should be None. Only supported in graph mode.
      flow: (optional) A float `Tensor` scalar coming from an existing
        `TensorArray.flow`. Only supported in graph mode.
      infer_shape: (optional, default: True) If True, shape inference is
        enabled.  In this case, all elements must have the same shape.
      element_shape: (optional, default: None) A `TensorShape` object specifying
        the shape constraints of each of the elements of the TensorArray. Need
        not be fully defined.
      colocate_with_first_write_call: If `True`, the TensorArray will be
        colocated on the same device as the Tensor used on its first write
        (write operations include `write`, `unstack`, and `split`).  If `False`,
        the TensorArray will be placed on the device determined by the device
        context available during its initialization.
      name: A name for the operation (optional).

    Raises:
      ValueError: if both handle and tensor_array_name are provided.
      TypeError: if handle is provided but is not a Tensor.
    N)
r!   r$   r%   r&   rE   rF   r*   r"   rG   r'   )r   r   r    r   r   r   r   EnableControlFlowV2r   get_default_graphr   r   rw   weakrefrefr  )r,   r    r!   r$   r%   r&   rE   rF   r*   r"   rG   r'   implementations                r-   rH   zTensorArray.__init__
  s    j 	!!#	v~~5 )n

tzzV^^;

/
/0E0E0G
H*n(n)!)+#'ED #*++d"3Dr/   c                 .    | j                   j                  S )z@The flow `Tensor` forcing ops leading to this TensorArray state.)rw   rB   rL   s    r-   rF   zTensorArray.flow[  s     %%%r/   c                 .    | j                   j                  S )z"The data type of this TensorArray.)rw   r9   rL   s    r-   r    zTensorArray.dtype`       &&&r/   c                 .    | j                   j                  S )z!The reference to the TensorArray.)rw   rE   rL   s    r-   rE   zTensorArray.handlee  r9  r/   c                 .    | j                   j                  S )z5The `tf.TensorShape` of elements in this TensorArray.)rw   r"   rL   s    r-   r"   zTensorArray.element_shapej       ---r/   c                 .    | j                   j                  S )z<Python bool; if `True` the TensorArray can grow dynamically.)rw   r)   rL   s    r-   r$   zTensorArray.dynamic_sizeo  r<  r/   c                 .    | j                   j                  S rJ   )rw   r>   rL   s    r-   r>   zTensorArray._infer_shapet  s    
 ,,,r/   c                 6    | j                   j                         S )a#  Returns a TensorArray with the same content and properties.

    Returns:
      A new TensorArray object with flow that ensures the control dependencies
      from the contexts will become control dependencies for writes, reads, etc.
      Use this object for all subsequent operations.
    )rw   rj   rL   s    r-   rj   zTensorArray.identity{  s     ((**r/   c                 >    | j                   j                  |||      S )N)rF   r'   )rw   r{   r   s       r-   r{   zTensorArray.grad  s     $$V$T$BBr/   c                 <    | j                   j                  ||      S )zRead the value at location `index` in the TensorArray.

    Args:
      index: 0-D.  int32 tensor with the index to read from.
      name: A name for the operation (optional).

    Returns:
      The tensor at index `index`.
    rs   )rw   r   )r,   r}   r'   s      r-   r   zTensorArray.read  s      $$U$66r/   )warn_in_eagerc                 >    | j                   j                  |||      S )a  Write `value` into index `index` of the TensorArray.

    Args:
      index: 0-D.  int32 scalar with the index to write to.
      value: N-D.  Tensor of type `dtype`.  The Tensor to write to this index.
      name: A name for the operation (optional).

    Returns:
      A new TensorArray object with flow that ensures the write occurs.
      Use this object for all subsequent operations.

    Raises:
      ValueError: if there are more writers than specified.
    rs   )rw   r   r  s       r-   r   zTensorArray.write  s"      %%eU%>>r/   c                 :    | j                   j                  |      S )a  Return the values in the TensorArray as a stacked `Tensor`.

    All of the values must have been written and their shapes must all match.
    If input shapes have rank-`R`, then output shape will have rank-`(R+1)`.

    For example:


    >>> ta = tf.TensorArray(tf.int32, size=3)
    >>> ta = ta.write(0, tf.constant([1, 2]))
    >>> ta = ta.write(1, tf.constant([3, 4]))
    >>> ta = ta.write(2, tf.constant([5, 6]))
    >>> ta.stack()
    <tf.Tensor: shape=(3, 2), dtype=int32, numpy=
    array([[1, 2],
           [3, 4],
           [5, 6]], dtype=int32)>


    Args:
      name: A name for the operation (optional).

    Returns:
      All the tensors in the TensorArray stacked into one tensor.
    rs   )rw   r   r   s     r-   r   zTensorArray.stack  s    4 %%4%00r/   c                 <    | j                   j                  ||      S )a  Return selected values in the TensorArray as a packed `Tensor`.

    All of selected values must have been written and their shapes
    must all match.

    Args:
      indices: A `1-D` `Tensor` taking values in `[0, max_value)`.  If the
        `TensorArray` is not dynamic, `max_value=size()`.
      name: A name for the operation (optional).

    Returns:
      The tensors in the `TensorArray` selected by `indices`, packed into one
      tensor.
    rs   )rw   r   )r,   r   r'   s      r-   r   zTensorArray.gather  s      &&wT&::r/   c                 :    | j                   j                  |      S )aj  Return the values in the TensorArray as a concatenated `Tensor`.

    All of the values must have been written, their ranks must match, and
    and their shapes must all match for all dimensions except the first.

    Args:
      name: A name for the operation (optional).

    Returns:
      All the tensors in the TensorArray concatenated into one tensor.
    rs   )rw   r   r   s     r-   r   zTensorArray.concat  s     &&D&11r/   c                 <    | j                   j                  ||      S )a  Unstack the values of a `Tensor` in the TensorArray.

    If input value shapes have rank-`R`, then the output TensorArray will
    contain elements whose shapes are rank-`(R-1)`.

    Args:
      value: (N+1)-D.  Tensor of type `dtype`.  The Tensor to unstack.
      name: A name for the operation (optional).

    Returns:
      A new TensorArray object with flow that ensures the unstack occurs.
      Use this object for all subsequent operations.

    Raises:
      ValueError: if the shape inference fails.
    rs   )rw   r   )r,   rd   r'   s      r-   r   zTensorArray.unstack  s     $ ''D'99r/   c                 >    | j                   j                  |||      S )a  Scatter the values of a `Tensor` in specific indices of a `TensorArray`.

    Args:
      indices: A `1-D` `Tensor` taking values in `[0, max_value)`.  If the
        `TensorArray` is not dynamic, `max_value=size()`.
      value: (N+1)-D.  Tensor of type `dtype`.  The Tensor to unpack.
      name: A name for the operation (optional).

    Returns:
      A new TensorArray object with flow that ensures the scatter occurs.
      Use this object for all subsequent operations.

    Raises:
      ValueError: if the shape inference fails.
    rs   )rw   r   )r,   r   rd   r'   s       r-   r   zTensorArray.scatter  s"    " ''T'BBr/   c                 >    | j                   j                  |||      S )a  Split the values of a `Tensor` into the TensorArray.

    Args:
      value: (N+1)-D.  Tensor of type `dtype`.  The Tensor to split.
      lengths: 1-D.  int32 vector with the lengths to use when splitting `value`
        along its first dimension.
      name: A name for the operation (optional).

    Returns:
      A new TensorArray object with flow that ensures the split occurs.
      Use this object for all subsequent operations.

    Raises:
      ValueError: if the shape inference fails.
    rs   )rw   r   )r,   rd   r   r'   s       r-   r   zTensorArray.split  s"    " %%eW4%@@r/   c                 :    | j                   j                  |      S )z#Return the size of the TensorArray.rs   )rw   r!   r   s     r-   r!   zTensorArray.size  s    $$$$//r/   c                 :    | j                   j                  |      S )zClose the current TensorArray.rs   )rw   r   r   s     r-   r   zTensorArray.close  s     %%4%00r/   c                     t        |       S rJ   )TensorArrayTraceType)r,   r   s     r-   __tf_tracing_type__zTensorArray.__tf_tracing_type__$  s    %%r/   r   r   rJ   )r   r   r   r   rH   r   rF   r    rE   r"   r$   r>   rj   r{   r   r   r   r   r   r   r   r   r   r   r!   r   rN  r   r/   r-   r   r     s]   ;~   $!%!.2O4b & & ' ' ' ' . . . . - -+C
7 #=""6? 7?"18;"2 "": #:& ""C #C$ ""A #A$0 ""1 #1&r/   c                    t        | t              r| j                  n| }t        j                         sBt        |t
              s2t        j                  t        j                               rt        d      t        |j                  |j                  ||j                  |j                        }|j                  }|j                  |_        |j                   |_        |j"                  |_        |j$                  |_        |S )z.Builds a TensorArray with a new `flow` tensor.a2  Attempting to build a graph-mode TF2-style TensorArray from either an eager-mode TensorArray or a TF1-style TensorArray.  This is not currently supported.  You may be attempting to capture a TensorArray inside a tf.function or tf.data map function. Instead, construct a new TensorArray inside the function.rt   )r2   r   rw   r   r   r   r   r2  r   r3  r   r    rE   r>   r:   r)   r?   r;   r=   )old_tarF   implnew_tanew_impls        r-   rk   rk   (  s     %/v{$C&
 
 $		"	"	$t01--c.C.C.EF !0 1 1 JJ[[##%)%I%IK& ##(--(::(. //( //(	-r/   c                     | j                   |k7  ret        j                  dj                  | t	        | j                         t	        |      dj                  t        j                                            y y )NzError: Input value {} has dtype {}, but expected dtype {}.  This leads to undefined behavior and will be an error in future versions of TensorFlow.  Traceback:
{} )r    loggingerrorformatstrjoin	tracebackformat_stack)rd   r    s     r-   r   r   J  sY    
[[EMM FFLfS-s5zggi4467G9: r/   TensorArraySpecztf.TensorArraySpecc                       e Zd ZdZg dZ ed       Zdej                  ddfdZ	d Z
d	 Zd
 Zd Zed        Zd Zd Zed        Zd Zd Zd Zy)r]  z*Type specification for a `tf.TensorArray`.r=   r9   r)   r>   c                     t         S rJ   r   rL   s    r-   <lambda>zTensorArraySpec.<lambda>Z  s    [ r/   NFTc                     t        j                  |      | _        t        j                  |      | _        || _        || _        y)a>  Constructs a type specification for a `tf.TensorArray`.

    Args:
      element_shape: The shape of each element in the `TensorArray`.
      dtype: Data type of the `TensorArray`.
      dynamic_size: Whether the `TensorArray` can grow past its initial size.
      infer_shape: Whether shape inference is enabled.
    N)r
   r<   r=   r   r7   r9   r)   r>   )r,   r"   r    r$   r*   s        r-   rH   zTensorArraySpec.__init__\  s7     '//>D//%(DK%D#Dr/   c                     t        |t              xr4 | j                  |j                  k(  xr | j                  |j                  k(  S rJ   )r2   r]  r9   r)   r,   others     r-   is_subtype_ofzTensorArraySpec.is_subtype_ofn  s?    uo. 6KK5<<'6%"5"557r/   c                 L    t        d |D              sy j                  j                  d |D              }|yt         fd|D              syt         fd|D              sy j                  xr t        d |D              }t	        | j
                   j                  |      S )zReturns the most specific supertype of `self` and `others`.

    Args:
      others: A Sequence of `TypeSpec`.

    Returns `None` if a supertype does not exist.
    c              3   <   K   | ]  }t        |t                y wrJ   )r2   r]  r  rf  s     r-   r  zATensorArraySpec.most_specific_common_supertype.<locals>.<genexpr>}  s     Fez%1Fs   Fc              3   4   K   | ]  }|j                     y wrJ   rU   rj  s     r-   r  zATensorArraySpec.most_specific_common_supertype.<locals>.<genexpr>  s      F2!&F2   Nc              3   P   K   | ]  }j                   |j                   k(    y wrJ   rO   r  rf  r,   s     r-   r  zATensorArraySpec.most_specific_common_supertype.<locals>.<genexpr>  s     ?ut{{ell*?   #&c              3   P   K   | ]  }j                   |j                   k(    y wrJ   )r)   rn  s     r-   r  zATensorArraySpec.most_specific_common_supertype.<locals>.<genexpr>  s"     MUt!!U%8%88Mro  c              3   4   K   | ]  }|j                     y wrJ   )r>   rj  s     r-   r  zATensorArraySpec.most_specific_common_supertype.<locals>.<genexpr>  s      ,0$,0rl  )allr=   most_specific_common_supertyper>   r]  r9   r)   )r,   otherscommon_shaper*   s   `   r-   rs  z.TensorArraySpec.most_specific_common_supertypet  s     FvFF&&EE F2*0F2 2L???MfMM## 0 ,0(.,0 )0K <d6H6H&( (r/   c                 R   t        |t        j                        st        j                  |      }t        |t              xrg | j
                  j                  |j
                        xr@ | j                  j                  |j                        xr | j                  |j                  k(  S rJ   )	r2   r   TypeSpectype_spec_from_valuer]  r9   r[   r=   r)   re  s     r-   r[   z"TensorArraySpec.is_compatible_with  s    eY//0,,U3e uo. 6KK**5<<862253G3GH6 %"5"557r/   c                 ^    | j                   | j                  | j                  | j                  fS rJ   r_  rL   s    r-   
_serializezTensorArraySpec._serialize  s,    d.@.@ r/   c                 L    t        j                  g t        j                        gS rJ   r3   
TensorSpecr   r   rL   s    r-   _component_specsz TensorArraySpec._component_specs  s    !!"fnn566r/   c                    t        |t              s#t        dj                  t	        |                  |j
                  4|j
                  j                  t        j                  k(  r|j
                  gS t        j                  d      5  t        j                  |j                         |j                        }d d d        |gS # 1 sw Y   gS xY w)N1Expected value to be a TensorArray, but got: `{}`convert_tensor_arrayr   )r2   r   r5   rX  r6   rF   r    r   r   r   r@   r   r   r   r"   )r,   rd   rF   s      r-   _to_componentszTensorArraySpec._to_components  s    e[)IPP
u+  zz%**"2"2fnn"Djj\
 >>01 E//;;=0C0CEE VmE Vms   	0CCc                     t        | j                  |d   | j                  | j                        }| j                  g|j
                  _        |S )Nr   )r    rF   r$   r*   )r   r9   r)   r>   r=   rw   )r,   tensor_listrets      r-   _from_componentsz TensorArraySpec._from_components  sL     kk^''%%	'C
 +/*=*=)>C&Jr/   c                     t        | t              s#t        dj                  t	        |                   t        | j                  | j                  | j                  | j                        S )Nr  )r    r"   r$   r*   )
r2   r   r5   rX  r6   r]  r    r"   r$   r>   )rd   s    r-   
from_valuezTensorArraySpec.from_value  s_    e[)IPP
u+   kk))''&&	( (r/   c                     | j                   S rJ   rO   rL   s    r-   _to_legacy_output_typesz'TensorArraySpec._to_legacy_output_types      ;;r/   c                     t        j                  | j                  | j                  g      j	                  | j
                        S rJ   )r
   r   r)   r>   r   r=   rL   s    r-   _to_legacy_output_shapesz(TensorArraySpec._to_legacy_output_shapes  s;    $$d&8&8$:K:K &' ((3D4G4G(HJr/   c                     t         S rJ   ra  rL   s    r-   _to_legacy_output_classesz)TensorArraySpec._to_legacy_output_classes  s    r/   )r   r   r   r   	__slots__r   
value_typer   float32rH   rg  rs  r[   rz  r~  r  r  staticmethodr  r  r  r  r   r/   r-   r]  r]  S  s     3K)01* "^^!	$$7(:	7 7 7	 	( 	(J
r/   c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)rM  z$Represents TraceType of TensorArray.c                     || _         y rJ   _valuerc   s     r-   rH   zTensorArrayTraceType.__init__  s	    DKr/   c                     | |k(  S rJ   r   re  s     r-   rg  z"TensorArrayTraceType.is_subtype_of  s    5=r/   c                 4     t         fd|D              r S d S )Nc              3   (   K   | ]	  }|k(    y wrJ   r   rn  s     r-   r  zFTensorArrayTraceType.most_specific_common_supertype.<locals>.<genexpr>  s     8tu}8s   )rr  )r,   typess   ` r-   rs  z3TensorArrayTraceType.most_specific_common_supertype  s    8%884BdBr/   c                     | j                   S rJ   r  )r,   placeholder_contexts     r-   placeholder_valuez&TensorArrayTraceType.placeholder_value  r  r/   c                 L    t        j                  g t        j                        gS rJ   r|  rL   s    r-   flattenzTensorArrayTraceType.flatten  s    !!"fnn566r/   c                     t        |      S rJ   )next)r,   r'  s     r-   from_tensorsz!TensorArrayTraceType.from_tensors  s    =r/   c                     t        |t        j                        st        S t        |t              sy| j
                  |j
                  u S )NF)r2   r   	TraceTypeNotImplementedrM  r  re  s     r-   __eq__zTensorArrayTraceType.__eq__  s9    eU__-e12 ;;%,,&&r/   c                 ,    t        | j                        S rJ   )idr  rL   s    r-   __hash__zTensorArrayTraceType.__hash__  s    dkk?r/   c                 N    | j                   j                   d| j                  dS )Nz(value=r  )	__class__r   r  rL   s    r-   __repr__zTensorArrayTraceType.__repr__  s$    nn%%&gdkk_A>>r/   N)r   r   r   r   rH   rg  rs  r  r  r  r  r  r  r   r/   r-   rM  rM    s3    ,C7	'?r/   rM  T)allow_subclass)9r   r   r[  r4  r   r  tensorflow.core.protobufr   tensorflow.python.eagerr   tensorflow.python.frameworkr   r   r   r   r	   r3   r
   r   r   r   tensorflow.python.opsr   r   r   r   r   r   r   tensorflow.python.platformr   rV  tensorflow.python.saved_modelr   tensorflow.python.typesr   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   r   r   r   r   rk   r   registerrw  r]  register_codecBuiltInTypeSpecCodecTypeSpecProtoTENSOR_ARRAY_SPECr  rM  'register_type_spec_from_value_converterr  r   r/   r-   <module>r     sY   9     / + 3 . 3 + < 4 3 1 : + 1 3 6 3 * * < @ ) 0 6Y( Y(x
L1 L1da aP	 =Y& Y& Y&x
D: 12~i(( ~ 3 ~B &  % %///11CC$?5?? $?R 2	 1 1++DBr/   