
    BVhY                     L   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	 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 Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d  Z&d! Z'd" Z(d# Z)d$ Z*d% Z+ejX                  d&        Z-d;d(Z.d) Z/d* Z0d+ Z1d, Z2d- Z3d. Z4d/ Z5d0 Z6d1 Z7d;d2Z8d3 Z9 ejt                  d4ejv                          ejt                  d5ejx                          ejt                  d6ejz                          ejt                  d7ej|                          ejt                  d8ej~                          ejt                  d9ej                          ejt                  d:ej                         y')<zHClass to hold a library of OpDefs and use it to create Brain operations.    )text_format)flags)attr_value_pb2)
tensor_pb2)tensor_shape_pb2)	types_pb2)dtypes)op_callbacks)op_def_library_pybind)op_def_registry)ops)tensor)tensor_shape)
tf_logging)_pywrap_utils)compat)tf_contextlibc                     | j                   D ]  }|j                  |k(  s|c S  t        d| j                   d| d      )NInconsistent OpDef for '', missing attr '')attrname	TypeError)op_defr   r   s      Z/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/framework/op_def_library.py_Attrr   %   sQ    kk dyyDk 	,V[[M :V1 	     c           	      >    || v r| |   S t        d| d| d|  d      )Nr   r   z' from ''.)r   )attr_protosr   op_type_names      r   
_AttrValuer#   -   s@    	[t,\N ;V8K=4 	5 5r   c                    |j                  d      rn|j                  j                  j                  }dj	                  d |D              }| |vr1t        d| dt        j                  |       j                   d|       y y )Nallowed_values, c              3   Z   K   | ]#  }t        j                  |      j                   % y wNr	   as_dtyper   .0xs     r   	<genexpr>z+_SatisfiesTypeConstraint.<locals>.<genexpr>7   s     M1vq166M   )+zValue passed to parameter 'z' has DataType z  not in list of allowed values: )	HasFieldr%   listtypejoinr   r	   r*   r   )dtypeattr_def
param_nameallowed_listr%   s        r   _SatisfiesTypeConstraintr8   4   s    '(**//44LYYMMMNL '
|?__U#(())I  ! )r   c                     |j                   r2| |j                  k  r"t        d| d| d|  d|j                   d	      y y )NAttr '' of 'z' Op passed list of length  less than minimum .)has_minimumminimum
ValueError)lengthr5   r6   r"   s       r   _SatisfiesLengthConstraintrB   ?   sY    fx'7'77
vj\~ >""()< ((), - - 8r   c                 ,   | |j                   j                  j                  vrrdj                  t	        t
        j                  |j                   j                  j                              }t        d| d| dt        j                  |        d| d	      y )Nz", "r:   r;   z' Op passed string 'z' not in: "z".)r%   r1   sr3   mapr   as_textr@   )valuer5   arg_namer"   r%   s        r   "_SatisfiesAllowedStringsConstraintrI   F   s    
())..000[[FNNH3388::;=N
vhZvl^ <./|N;K3P Q Q 1r   c                 f    | |j                   k  r"t        d| d| d|  d|j                    d	      y )Nr:   r;   z' Op passed r<   r=   )r?   r@   )rG   r5   rH   r"   s       r   _SatisfiesIntMinimumConstraintrK   N   sM    
X
vhZvl^<w O**2*:*:);1> ? ? r   c                 8    | j                   ry| j                  ryy)NTF)number_attrtype_list_attr)args    r   _IsListParameterrP   T   s    __
	r   c                     d}| j                   t        j                  k7  r|dz  }| j                  r|dz  }| j                  r|dz  }|S )Nr      )r2   r   
DT_INVALID	type_attrrN   )rO   nums     r   _NumTypeFieldsrV   \   sF    	#XX%%%saxs]]C1HC	*r   c                 .    t        | t        t        f      S r(   )
isinstancer1   tuple)vs    r   _IsListValuer[   d   s    	Ae}	%%r   c                     | D cg c]  }t        |      r|n|g }}|D cg c]  }|D ]  }|  c}}S c c}w c c}}w )z0Converts [1, 2, [3, 4], [5]] to [1, 2, 3, 4, 5].)r[   )lr-   l_of_lsublistitems        r   _Flattenra   h   sI     455aaAqc)5&5$	97	9$	9$	99 6	9s   7<c                     g }d}|D ]:  }||j                  | |          |dz  }|j                  | |||z           ||z  }< t        |      dk(  r|d   S t        |      S )aP  Returns the elements of list l structured according to the given structure.

  A structure is represented by a list whose elements are either
  `None` or a non-negative integer. `None` corresponds to a single
  element in the output list, and an integer N corresponds to a nested
  list of length N.

  The function returns a data structure whose shape is given by
  `structure`, and whose elements are taken from `l`. If `structure`
  is a singleton, the function returns the single data structure
  implied by the 0th element of `structure`. For example:

      _Restructure(["foo", "bar", "baz", "qux"], [None, 2, None])
        -> ["foo", ["bar", "baz"], "qux"]

      _Restructure(["foo"], [None]) -> "foo"

      _Restructure(["foo"], [1]) -> ["foo"]

      _Restructure([], [0]) -> []

  Args:
    l: A list.
    structure: A list whose elements are either `None` or a non-negative
      integer.

  Returns:
    The elements of `l`, restructured according to `structure`. If
    `structure` is a list of length 1, this function returns the
    single data structure implied by `structure[0]`.

  r   rR   )appendlenrY   )r]   	structureresultcurrent_indexelements        r   _Restructureri   p   s    B &- gmmAm$%qmmmAmM'$9:;wm 	[A!9=r   c                     t        | t        j                        st        d| dt	        |        d      t        |       S )NzExpected float for argument '' not r=   )rX   r   
real_typesr   reprfloatrZ   rH   s     r   
_MakeFloatrp      s:    	Av((	)
3H:VDG9AN
OO	q/r   c           	          t        | t              rt        d| dt        |        d      	 t	        |       S # t
        t        f$ r t        d| dt        |        d      w xY w)NzExpected int for argument 'rk   r=   )rX   strr   rm   intr@   ro   s     r   _MakeIntrt      so    3
1(6$q'!L
MMNq6M
i	  N
1(6$q'!L
MMNs	   
8 +A#c                     t        | t        j                        st        d| dt	        |        d      t        j
                  |       S )NzExpected string for argument 'rk   r=   )rX   r   bytes_or_text_typesr   rm   as_bytesro   s     r   _MakeStrrx      s@    	Av11	2
4XJfT!WIQO
PP		r   c                 \    t        | t              st        d| dt        |        d      | S )NzExpected bool for argument 'rk   r=   )rX   boolr   rm   ro   s     r   	_MakeBoolr{      s0    	At	
28*F47)1M
NN	
(r   c           	          	 t        j                  |       j                  } | j
                  S # t        $ r t        d| dt	        |        d      w xY w)Nz Expected DataType for argument 'rk   r=   )r	   r*   
base_dtyper   rm   as_datatype_enumro   s     r   	_MakeTyper      s`    #%%A 
		 
 #
6xjAwiq" # ##s	   - %Ac           	         t        | t        j                        rA| j                  D ]0  }|j                  st        j                  dt        |               | S  | S 	 t        j                  |       j                         S # t        $ r"}t        dt        |        d| d|       d}~wt        $ r"}t        dt        |        d| d|       d}~ww xY w)z"Convert v into a TensorShapeProto.z4Warning: TensorShapeProto with a named dimension: %szError converting z (arg name = z) to a TensorShape: N)rX   r   TensorShapeProtodimr   loggingwarningrr   r   as_shapeas_protor   rm   r@   )rZ   rH   des       r   
_MakeShaper      s     #445UU 	
NA	 H
 H)  #,,..	 )
'QyhZ H$$%3( ) )	 )
'QyhZ H$$%3( ) ))s$   "B   	C	B&&C2CCc                 p    t        | t        j                        r| S t        dt	        |        d| d      )zEnsure v is a TensorProto.Don't know how to convert z  to a TensorProto for argument 'r   )rX   r   TensorProtor   rm   ro   s     r   _MakeTensorr      s@    :))*H"47) ,

1	 r   c                    t        | t        j                        r| S t        | t        j                        rt        j                  |       }|S t        | d      r_| j                  t        j                                t        | d      r| j                  }|S t        j                  | j                        }|S t        dt        |        d|       )zEnsure v is a func.)r   add_to_graph_as_name_attr_listr   z to a func for argument )rX   r   NameAttrListr   rv   hasattrr   r   get_default_graphr   r   r   rm   )rZ   rH   fn_attrs      r   	_MakeFuncr      s    >../H6--.))q1G 
. q.!NN3((*+q&'$$g 
.	 ++8g 
. 0a	 :  (z+ , ,r   c              #      K   | sd yt        j                  | d         5  t        | dd       5  d ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY ww)zA context manager for (maybe) colocating with a list of input tensors.

  Args:
    inputs: A list of `Tensor` or `Operation` objects.

  Returns:
    A context manager.
  Nr   rR   )r   colocate_with_MaybeColocateWith)inputss    r   r   r      s\      
	 
		6!9	% '9&*'E      s1    AAAA	AA	AAANc                     t        | |fi |\  }}}}|r7t        t        j                  |      |      }t	        |t
              r|s|r|S |S |S )a  Add a node invoking a registered Op to a graph.

  Example usage:
     # input1 and input2 can be Tensors or anything ops.convert_to_tensor()
     # will convert to a Tensor.
     op_def_library.apply_op("op", input1=input1, input2=input2)
     # Can specify a node name.
     op_def_library.apply_op("op", input1=input1, name="node_name")
     # Must use keyword arguments, with the names specified in the OpDef.
     op_def_library.apply_op("op", input_name=input, attr_name=attr)

  All attrs must either be inferred from an input or specified.
  (If inferred, the attr must not be specified.)  If an attr has a default
  value specified in the Op's OpDef, then you may pass None as the value
  of that attr to get the default.

  Args:
    op_type_name: string. Must match the name field of a registered Op.
    name: string. Optional name of the created op.
    **keywords: input Tensor and attr arguments specified by name, and optional
      parameters to pass when constructing the Operation.

  Returns:
    The Tensor(s) representing the output of the operation, or the Operation
    itself if there are no outputs.

  Raises:
    RuntimeError: On some errors.
    TypeError: On some errors.
    ValueError: On some errors.
  )_apply_op_helperri   r   convert_n_to_tensorrX   r1   )r"   r   keywordsoutput_structureis_statefulopoutputsress           r   apply_opr     s_    @ 0@D0&$0&,KW
s..w79I
JC#tS[ijIr   c                 z   |j                   D ]  }|j                  }||   }|j                  d      r7|5t        j                         }|j                  |j                         |||<   ]t        ||j                  |      }|j                  j                  d      rt        t        |      |||        |j                  d      r`|j                  dk(  rt        |j                  |||        n8|j                  dk(  r)|j                  j                  D ]  }t        ||||         |j                  r'|j                  dk(  rt!        |j"                  |||        |j                  dk(  rt%        |j                  ||       |j                  d	k(  r(|j                  j                  D ]  }t%        |||        |||<    y)
z4Extracts `attr_protos`. For use in _apply_op_helper.default_valueNlist(r%   stringlist(string)rs   r2   
list(type))r   r   r0   r   	AttrValueCopyFromr   value_to_attr_valuer2   
startswithrB   rd   rI   rD   r1   r>   rK   ir8   )r"   r   attrsr!   r5   keyrG   
attr_values           r   _ExtractAttrProtor   =  s   ++ "h
--C#JE)em!++-j(001#k#$UHMM3?J}}( UXsLI)*	(	"*:<<3+7	9==N*__&& 	QE
,UHc<
P	Q 6$Z\\8S,O}}z#>}}$??'' 7% #67 "K9"r   c                    |j                   D ]  }|j                  r3t        ||j                  |       j                  }|j	                  |       B|j
                  r)t        ||j
                  |       }|j	                  d       w|j                  rFt        ||j                  |       }|j	                  t        |j                  j                               |j	                  d        y)z9Extracts `output_structure`. For use in _apply_op_helper.N)

output_argrM   r#   r   rc   rT   rN   rd   r1   r2   )r"   r   r!   r   rO   nts          r   _ExtractOutputStructurer   ^  s      $c

[#//<
@
B
Baa 	
[#--
>ad#			
[#"4"4l
Cac!&&++./d#$r   c                     | j                   D ]:  }|j                  |j                  d      }t        |t        j
                        r: y | j                  D ]"  }|j                  dk(  s|j                  dk(  s" y y)z:Check if the fast path for _apply_op_helper is applicable.NFfunc
list(func)T)	input_arggetr   rX   r   Tensorr   r2   )r   r   r   rG   r5   s        r   _CanExtractAttrsFastPathr   o  sr     ## iLL.EeV]]+ ++ h}}(--<"? 
r   c                     |j                   j                  }|r2||k\  r,t        d|  d| d| d|j                   j                   d	      yy)zChecks if the op is deprecated.zOp z& is not available in GraphDef version z!. It has been removed in version z. r=   N)deprecationversionNotImplementedErrorexplanation)r"   r   producerdeprecation_versions       r   _CheckOpDeprecationr     si    **22X)<<

l^A( L**=)>b))
*!	-. . =r   c                 B   | j                   D ]  }|j                  dk7  r|j                  }|j                  d      r,t	        j
                  |j                  j                        ||<   |j                  d      sn|j                  j                  j                  ||<    y)zAExtracts the `default_type_attr_map` and `allowed_list_attr_map`.r2   r   r%   N)	r   r2   r   r0   r	   r*   r   r%   r1   )r   default_type_attr_mapallowed_list_attr_mapr5   r   s        r   #_ExtractDefaultTypesAndAllowedTypesr     s     ++ Eh}}
--C)#)??

 
 
%
%$'C )*#+#:#:#?#?#D#DC Er   c                 L  ! i }|j                   D ]  }	|	j                  }
|
|v r|j                  |
      }n/|
dz   |v r|
dz  }
|j                  |
      }nt        d|
 d|       t	        |	      rt        |      st        d|
 d|  d| d      d}d}|	j                  t        j                  k7  r|	j                  }nx|	j                  rl|	j                  |v r||	j                     }n/|D ]*  }t        |t        j                        s|j                  } n ||	j                  |v r||	j                     }	 |	j                  s!|rt!        j"                  |      j$                  }t'        j(                  ||	j                  |r|nd||	j                  	      }t+        d
 |D              }|	j                  r,t-        |      dkD  rt        d|	j                   d|  d|       |D cg c]  }|j                   }}|j7                  |       nGd}d}d}|	j                  t        j                  k7  r|	j                  }nV|	j                  |v r||	j                     }n8|	j                  |v r*||	j                     }|j9                  |	j                        }	 |r|rpd}	 t'        j0                  ||	j                  |	j                        }||j                  |v r|}n\t'        j0                  ||	j                  |	j                  |      }n.t'        j0                  ||	j                  ||	j                  |      }|j                  g}|j3                  |       |D cg c]  }|j$                   c}!|	j                  r|	j                  |v rYt-        |      ||	j                     k7  rt/        d.|
 d/|  d0t-        |       d1||	j                      d,||	j                      d-      t-        |      ||	j                  <   |
||	j                  <   t?        ||	j                        }|j@                  rCt-        |      |jB                  k  r+t/        d.|
 d/|  d0t-        |       d2|jB                   d	      tE        !fd3!D              rt        d4|
 d|  d5! d6      |	j                  t        j                  k7  r!r!d7   |	j                  k7  rJ d8       |	j                  |v r !rg!d7   ||	j                     k7  rQJ d8       !s!|	j                  |vr9t        d9|
 d|  d:      !d7   ||	j                  <   |
||	j                  <   t?        ||	j                        }tG        !d7   ||
;       n|	j                  r݉!d7   }|	j                  |v r||	j                     |k7  rt        d&|
 d|  d't!        j"                  |      j                   d<t!        j"                  ||	j                           j                   d,||	j                      d-      !D ]$  }tG        |t?        ||	j                        |
;       & |||	j                  <   |
||	j                  <   n|	jH                  rω!}|	jH                  |v rw||	jH                     |k7  rdj5                  d= |D              }dj5                  d> ||	jH                     D              } t        d&|
 d|  d?| d@|  d,||	jH                      d-      !D ]$  }tG        |t?        ||	jH                        |
;       & |||	jH                  <   |
||	jH                  <   n!d7   |	j                  k7  rJ d8       |	j                  r7tK        dA |D              st        dB|  dC|
 dD      |j7                  |       ||j7                  !        y# t        t.        f$ r) g }|D ]y  }	 t'        j0                  ||	j                        }|j3                  |j                  j$                  j                         U# t        t.        f$ r |j3                  d       Y ww xY w dj5                  |      }d|
d| d|d}|	j                  ro|	j                  t        j                  k7  rt        | d|j                   d      |	j                  |v rt        | d|j                   d      t        | d      t        | d|       w xY wc c}w # t        $ r}Y d}~*d}~ww xY w# t        $ ri}||t        dt!        j"                  |      j                   d|	j                   d |  d!t;        |       d"t        |      j<                   d#|       d}~wt.        $ r+ 	 t'        j0                  ||	j                        j                  j                  }n"# t.        $ r}t/        d$|
 d%|       d}~ww xY wd&|
d| d'|d(}|	j                  t        j                  k7  r8t        | d)t!        j"                  |	j                        j                   d      |	j                  }||v r||vr||   ||<   ||vrd*||<   t        | d+t!        j"                  ||	j                           j                   d,||	j                      d-      w xY wc c}w )EzBExtracts `attrs`, `inputs`, and `input_types` in _apply_op_helper._zNo argument for input z
 found in zExpected list for 'z' argument to 'z
' Op, not r=   N)r   r4   preferred_dtypeas_refc              3   H   K   | ]  }|j                   j                    y wr(   )r4   r}   )r,   rZ   s     r   r.   z)_ExtractInputsAndAttrs.<locals>.<genexpr>  s     ;q**;s    "rR   zNot all types matched for  for z. Got )r   z<NOT CONVERTIBLE TO TENSOR>r&   zTensors in list passed to 'r;   z' Op have types []z! that do not match expected type z that do not match type z! inferred from earlier arguments.z that don't all match.z that are invalid. Tensors: )r   r   )r   r   r   )r   r4   r   r   z	Expected z passed to parameter 'z	' of op 'z', got z
 of type 'z' instead. Error: zTried to convert 'z!' to a tensor and failed. Error: zInput 'z' Op has type z that does not matchz expected type of zDefault in OpDefz type z of argument 'r    zList argument 'z' to 'z' Op with length z must match length z shorter than minimum length c              3   .   K   | ]  }|d    k7    yw)r   N )r,   bt
base_typess     r   r.   z)_ExtractInputsAndAttrs.<locals>.<genexpr>i  s     6RR:a= 6s   zAll tensors passed to 'z"' Op must have the same type. Got 	 instead.r   UnreachablezMDon't know how to infer type variable from empty input list passed to input 'z' Op.)r6   z that does not match type c              3   Z   K   | ]#  }t        j                  |      j                   % y wr(   r)   r+   s     r   r.   z)_ExtractInputsAndAttrs.<locals>.<genexpr>  s     "Oq6??1#5#:#:"Or/   c              3   Z   K   | ]#  }t        j                  |      j                   % y wr(   r)   r+   s     r   r.   z)_ExtractInputsAndAttrs.<locals>.<genexpr>  s&      %P*+fooa %%%Pr/   z' Op has type list of z that does not match type list c              3   4   K   | ]  }|j                     y wr(   )_is_ref_dtyper+   s     r   r.   z)_ExtractInputsAndAttrs.<locals>.<genexpr>  s     0Q0s   r   z' Op requires that input 'z+' be a mutable tensor (e.g.: a tf.Variable))&r   r   popr   rP   r[   r2   r   rS   rM   rT   rX   r   r   r4   is_refr	   r*   r}   r   internal_convert_n_to_tensorsetrd   r@   convert_to_tensorrc   r3   extendr   rm   __name__r   r>   r?   anyr8   rN   all)"r"   r   r   r   r   r   r   input_typesinferred_fromr   
input_namevaluesr4   default_dtyper   	all_typesobserved_typesrG   converted_valueobservedprefixr-   typesr7   inferrederrknum_attrrT   r   	base_typeactual_typesexpected_typesr   s"                                    @r   _ExtractInputsAndAttrsr     s    -## Y%iJX||J'f	c	X	% Cj||J'f.zl*VHMNN 	"&!!*_\N Kha!" 	"
 em	9//	/  %'	++,% a!V]]+gge =Y004II/	0C0CD-&KE//%(33%11 %d)##% ;F;;	  S^a%76y~~6Fe)N&= > >8 !''1qww'e'mmF eml	9//	/%'i))*"77 .i.A.AB,001D1DEDC =\(,,Y^^I4D4DFH !hnn&DF**^^ '' -	/F ((>>%%+-&V ||nemmF(-.1!,,.J			%	'v;%	 5 566
|6, @F}$7y,,-. /	 5 567r;< < (+6{i##$/9i++,!6!67CK(2B2B$B
|6, @F}$A!!"!%& &
 
6:6	6%j\~ F,,6<yBC 	C 
9//	/*Q-9>>9
%
%%' *Q-51D1D+EE
%
%    (==))3F<. I 
 (2!}%	##
$/9-	++
,FI$7$78)
"mY:?			a=j				%$$%3
|6,~,1122Ly':':!;<AAB C()<)<=>bBC C $ 	%I
"FI//0#%	%
 &0i!!"-7i))*		!	!j		!	!U	*))*j8"OJ"OO,99 %P/4Y5M5M/N%P P.
|6,7M=n=M}Y-E-EFGrKL L
 $ 	%I
"FI445#%	%
 +5i&&'2<i../ 
A)..	(#m#u0%00~7
| D3 34 	4 $sY%~ $ K 	AEA!33i..0O!!/"7"7"B"B"G"GHZ( A!!"?@A	A 99^, |X7  ^^y333vh&G$zzl!- . .""e+vh&>uzzl K? ? @ @ vh&<=>>VH$@IJ
J1K4 (8   	0  =)&//%0556 7..!<.fjf)>)>(? @u 
  C	**Y--//4uTT  	":, /u 	  |X7>>Y111VH$6#__Y^^<AAB!E F F !!!''~.q1eAh-'#5a y':':!;<AAB C()<)<=>bBC C/C< /s   8B)^!%cc9,c"A/c9j!!c9A`
	c
 `-	*c,`-	-B-c"	c6+c91c66c99	jA$e&&j45f*)j*	g	3gg		Cjc                 
   |j                   D ]  }|j                  |v r+|j                  |v rt        d|j                   d|  d      <|j                  |v r)|j                  |j                        ||j                  <   s|j                  dz   |v r,|j                  |j                  dz         ||j                  <   |j                  |v r||j                     ||j                  <   t        d|j                   d|         y)zCExtracts the remaining attributes into `attrs` in _apply_op_helper.z,Should not specify value for inferred attr 'z' for r=   r   zNo argument found for attr r   N)r   r   r   r   )r"   r   r   r   r   r   s         r   _ExtractRemainingAttrsr     s     kk )dyyE	h	:499+VnA  	  yyH!dii0eDII	SH	$ "dii#o6eDII	+	+.tyy9eDII3DII;e%( ) )#)r   c                 4   t        j                  |       }|t        d|        	 t        j                  t        |j                                     }|j                  j                  }|||fS # t        $ r }t        d|  d|j                         d}~ww xY w)zCReturns the OpDef, Graph and Producer. For use in _apply_op_helper.NzUnrecognized Op name zCannot determine graph for Op 'z
' due to: )r   r   RuntimeErrorr   _get_graph_from_inputsra   r   graph_def_versionsr   AssertionErrormessage)r"   r   r   gr   r   s         r   	_GetOpDefr    s    |,&^
.|n=
>>O 	""8HOO,=#>?A##,,H 
H		 
 O

),z!))MO OOs   AA. .	B7BBc                 z    |r9dj                  t        |j                                     }t        |  d| d      y)z:Ensures all inputs passed into _apply_op_helper were used.r&   z# got unexpected keyword arguments: r=   N)r3   sortedkeysr   )r"   r   all_keywordss      r   _CheckAllInputsUsedr    sC    99VHMMO45L
|n$G#nA' ( ( r   c                 t   t        | |      \  }}}|r|n| }i i }}i i }	}g g g }}}
d}t        ||      rJt        j                         j                  j                         rd}t        j                  | ||      \  }}
}}|rt        | ||       t        |||	       |j                         5  t        j                  |      5 }|rJt        | ||	||||
|       t        | ||||       t        | |||       ~t!        | |||       t#        | |       t%        |j&                  |
      D cg c]  \  }}|j(                  r| }}}t+        |      5  |j-                  | |
d||||      }ddd       j.                  }t1        j2                         rYt1        j4                  |j6                  j8                  t;        |j<                        |t;        |      |j>                  |      }||}||j@                  ||fcddd       cddd       S c c}}w # 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)z=Implementation of apply_op that returns output_structure, op.TFN)r	   r   r   r   r   )op_namegraph)!r  r   r   configgraph_building_optimizationrG   r   process_inputsr   r   
as_defaultr   
name_scoper   r   r   r   r  zipr   r   r   _create_op_internalr   r
   should_invoke_op_callbacksinvoke_op_callbacksnode_defr   rY   r   r   r   )r"   r   r   r   r   r   r   r!   r   r   r   r   r   fallbackscoperO   valmust_colocate_inputsr   r   callback_outputss                        r   r   r     sP    ",9&!X<$2%13R.*,b"'+&(vx0lln00668H,,\8XN 7K&6 fh7'0E(=?
 	||~ %=s~~d+ %=u\63H%'<eV(* \682E;fe[A
lFK.0,1 14F4D4Df0M +HC"zz   + +	0	1 C   vd&+'26 ! CbC jjG..0%99
++..%		*Kw''$ 
	%"V//W<K%= %= %=+C C#%= %= %= %= %=sP   )H.?A&H%H
=HH$BH4	H.HHHH"	H..H7c           	      X   t        j                         }|j                  d      r0t        |       s%t	        d| dt        |       j                   d      |dk(  rt        | |      |_        |S |dk(  r?|j                  j                  j                  | D cg c]  }t        ||       c}       |S |dk(  rt        | |      |_        |S |dk(  r?|j                  j                  j                  | D cg c]  }t        ||       c}       |S |d	k(  rt        | |      |_        |S |d
k(  r?|j                  j                  j                  | D cg c]  }t        ||       c}       |S |dk(  rt        | |      |_        |S |dk(  r?|j                  j                   j                  | D cg c]  }t        ||       c}       |S |dk(  rt#        | |      |_        |S |dk(  r?|j                  j
                  j                  | D cg c]  }t#        ||       c}       |S |dk(  r'|j$                  j'                  t)        | |             |S |dk(  r?|j                  j$                  j                  | D cg c]  }t)        ||       c}       |S |dk(  r'|j*                  j'                  t-        | |             |S |dk(  r?|j                  j*                  j                  | D cg c]  }t-        ||       c}       |S |dk(  r'|j.                  j'                  t1        | |             |S |dk(  r?|j                  j.                  j                  | D cg c]  }t1        ||       c}       |S t	        d| d| d      c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w )a=  Encodes a Python value as an `AttrValue` proto message.

  Args:
    value: The value to convert.
    attr_type: The value type (string) -- see the AttrValue proto definition for
      valid strings.
    arg_name: Argument name (for error messages).

  Returns:
    An AttrValue proto message that encodes `value`.
  r   zExpected list for attr z, obtained r   r   r   rs   z	list(int)rn   zlist(float)rz   z
list(bool)r2   r   shapezlist(shape)r   zlist(tensor)r   r   zUnrecognized Attr type r   r=   )r   r   r   r[   r   r2   r   rx   rD   r1   r   rt   r   rp   fr{   br   r  r   r   r   r   r   r   )rG   	attr_typerH   r   r-   s        r   r   r   0  s    '')*'"/ze--.i9 : : (E8,JLB 
A N"OOUChq(3CD> 
= EE8,JL: 
9 KOOUChq(3CD6 
5 GeX.JL2 
1 M!OOuE!jH5EF. 
- FUH-JL* 
) L OOeDi84DE& 
% Fx0JO" 
! L OO GA1h!7 GH 
 Gj9: 
 M!OO  5!Ia*Q"9!IJ 
 H{5(;< 
 N"OO!!U"K;q(#;"KL 
 FOOYuh78
 
	 L OO GA1h!7 GH 
 -i[hZqI
JJ= D D F E !H "J #L !Hs0   N2N	N*NN6N&N"N'ztf.dtypes.DTypeztf.dtypes.as_dtypeztf.TensorShapeztf.as_shapeztf.TensorProtoztext_format.Parseztf.convert_to_tensorr(   )B__doc__google.protobufr   tensorflow.core.configr   tensorflow.core.frameworkr   r   r   r   tensorflow.python.frameworkr	   r
   r   r   r   r   r   tensorflow.python.platformr   r   tensorflow.python.utilr   r   r   r   r#   r8   rB   rI   rK   rP   rV   r[   ra   ri   rp   rt   rx   r{   r   r   r   r   contextmanagerr   r   r   r   r   r   r   r   r   r  r  r   r   RegisterPyObjectDTyper*   TensorShaper   r   Parser   r   r   r   <module>r*     s    O ' ( 4 0 6 / . 4 = 7 + . 4 < 0 ) 05-Q?&:.bN)2&  &)^"B$" .E$^%B	)0((==@5t   0&,, ?   3V__ E   /1I1I J   }l.C.C D   /1G1G H   2K4E4E F   5s7L7L Mr   