
    BVhF                        d Z ddlZddlm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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ri ejZ                  eej\                  ej^                  ej`                  ejb                  ejd                  ejf                  ejh                  ejj                  ejl                  ejn                  ejp                  ejr                  ejt                  ejv                  ejx                  ejz                  ej|                  ej~                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  j                  ej~                  ej                  j                  ejn                  ej                  j                  ej                  ej                  j                  ejr                  ej                  j                  ejf                  ej                  j                  e ej                  j                  e"ej                  j                  e$ej                  j                  e&ej                  j                  e(ej                  j                  e*ej                  j                  e+ej                  j                  e,iZXnd% ZYd& ZZd' Z[d( Z\d) Z]d* Z^d+ Z_d, Z`d- Zad. Zbd/ Zci ej                  j                  eej                  j                  e!ej                  j                  e#ejZ                  eej\                  eYej`                  eZejd                  e[ejh                  e\ejl                  e[ejp                  e[ejt                  e^ejx                  e_ej|                  e[ej                  e[ej                  e`ej                  eaej                  ebej                  ecej                  j                  e]ej                  j                  e]ej                  j                  e]ej                  j                  e]ej                  j                  e]ej                  j                  e+ej                  j                  e,iZXd0 Zdd1 Zed2 Zfd3 Zgd4 Zh eiejZ                  ej\                  ej`                  ejd                  ejl                  ej                  ej|                  ejh                  ej                  ej                  ej                  ej                  ej                  ejt                  ejx                  ej                  ej                  ej                  ej                  ej                  ej                  g      Zjd5 Zkd6 Zld7 Zm emej                  ej                  f      Zp emej                        Zr emej                        Zt emej                        Zv emew      Zxd8 Zyi ej                  exej                  etej                  etejZ                  erej\                  erej`                  erej                  epejd                  epejh                  epej|                  epej                  elej                  elej                  elej                  elej                  elej                  evejp                  epejl                  epejt                  epejx                  epiZ{d9 Z|d: Z} ed;      	 	 dId<       Z~ ed=      d>        Zd? Zd@ Z edA      dJdB       ZdC Zej                   G dD dEe             Zej                  ej                  efZ edF      dG        ZeZdH Zy# e$ r dZY w xY w)Kz!Utilities to create TensorProtos.    N)Protocol)
tensor_pb2)tensor_shape_pb2)pywrap_tf_session)dtypes)errors_impl)tensor_shape)core)internal)compat)nest)numpy_compat)	tf_export)fast_tensor_utilTFc                     t        j                  | t        j                        j	                  t        j
                        j                         S N)r   
np_asarraynpfloat16viewuint16itemxs    W/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/framework/tensor_util.pyExtractBitsFromFloat16r   .   s1    		 	 BJJ	/	4	4RYY	?	D	D	FF    c                 r    | j                   j                  |D cg c]  }t        |       c}       y c c}w r   )half_valextendr   tensor_protoproto_valuesr   s      r   #SlowAppendFloat16ArrayToTensorProtor$   2   s-    *67Qa 77   4c                     t        j                  | t        j                  |t        j
                        j                  t        j                               y Ndtype)r   AppendFloat16ArrayToTensorProtor   r   r   r   r   r   r"   r#   s     r   &_MediumAppendFloat16ArrayToTensorProtor,   8   s7    22l"**=BB299MOr   c                     t        j                  | t        j                  j                        j                  t        j                        j                         S r'   )	r   r   r   bfloat16as_numpy_dtyper   r   r   r   r   s    r   ExtractBitsFromBFloat16r0   ?   s8    		 	 v--
//3tBIIttvFr   c                 r    | j                   j                  |D cg c]  }t        |       c}       y c c}w r   )r   r    r0   r!   s      r   $SlowAppendBFloat16ArrayToTensorProtor2   D   s-    +78aq!88r%   c                     t        j                  | t        j                  |t        j
                  j                        j                  t        j                               y r'   )
r    AppendBFloat16ArrayToTensorProtor   r   r   r.   r/   r   r   r   r+   s     r   $FastAppendBFloat16ArrayToTensorProtor5   J   s=    33L++
foo<<>>Bd299oOr   c                     | xj                   t        j                  |t        j                  j
                        j                  t        j                        j                         z  c_         y r'   )

float8_valr   r   r   float8_e5m2r/   r   r   uint8tobytesr+   s     r   &SlowAppendFloat8e5m2ArrayToTensorProtor;   P   sG    
f00??AtBHH~wy	r   c                     t        j                  | t        j                  |t        j
                  j                        j                  t        j                               y r'   )
r   AppendFloat8ArrayToTensorProtor   r   r   r8   r/   r   r   r9   r+   s     r   &FastAppendFloat8e5m2ArrayToTensorProtor>   Y   sA    11
f00??AAEbhhQr   c                     | xj                   t        j                  |t        j                  j
                        j                  t        j                        j                         z  c_         y r'   )
r7   r   r   r   float8_e4m3fnr/   r   r   r9   r:   r+   s     r   (SlowAppendFloat8e4m3fnArrayToTensorProtorA   `   sG    
f22AACtBHH~wy	r   c                     t        j                  | t        j                  |t        j
                  j                        j                  t        j                               y r'   )
r   r=   r   r   r   r@   r/   r   r   r9   r+   s     r   (FastAppendFloat8e4m3fnArrayToTensorProtorC   i   sE    11
f22AACCG4hhDr   c                     | xj                   t        j                  |t        j                  j
                        j                  t        j                        j                         z  c_         y r'   )
r7   r   r   r   float8_e4m3fnuzr/   r   r   r9   r:   r+   s     r   *SlowAppendFloat8e4m3fnuzArrayToTensorProtorF   q   H    
f44CC tBHH~wyr   c                     t        j                  | t        j                  |t        j
                  j                        j                  t        j                               y r'   )
r   r=   r   r   r   rE   r/   r   r   r9   r+   s     r   *FastAppendFloat8e4m3fnuzArrayToTensorProtorI   {   ?    11
f44CCRXX	r   c                     | xj                   t        j                  |t        j                  j
                        j                  t        j                        j                         z  c_         y r'   )
r7   r   r   r   float8_e4m3b11fnuzr/   r   r   r9   r:   r+   s     r   -SlowAppendFloat8e4m3b11fnuzArrayToTensorProtorM      sH    
f77FF tBHH~wyr   c                     t        j                  | t        j                  |t        j
                  j                        j                  t        j                               y r'   )
r   r=   r   r   r   rL   r/   r   r   r9   r+   s     r   -FastAppendFloat8e4m3b11fnuzArrayToTensorProtorO      s?    11
f77FFRXX	r   c                     | xj                   t        j                  |t        j                  j
                        j                  t        j                        j                         z  c_         y r'   )
r7   r   r   r   float8_e5m2fnuzr/   r   r   r9   r:   r+   s     r   *SlowAppendFloat8e5m2fnuzArrayToTensorProtorR      rG   r   c                     t        j                  | t        j                  |t        j
                  j                        j                  t        j                               y r'   )
r   r=   r   r   r   rQ   r/   r   r   r9   r+   s     r   *FastAppendFloat8e5m2fnuzArrayToTensorProtorT      rJ   r   c                     t        j                  |t        j                  j                        j                  t        j                        }| j                  j                  |j                                y r'   )r   r   r   int4r/   astyper   int8int_valr    tolistr!   s      r    SlowAppendInt4ArrayToTensorProtor[      sM     &++4466<fRWWo ahhj)r   c                     t        j                  |t        j                  j                        j                  t        j                        }| j                  j                  |j                                y r'   )r   r   r   uint4r/   rW   r   rX   rY   r    rZ   r!   s      r   !SlowAppendUInt4ArrayToTensorProtor^      sM     &,,5577=vbgg ahhj)r   c                 |    | j                   j                  |D cg c]  }|j                          c}       y c c}w r   )	float_valr    r   r!   s      r   #SlowAppendFloat32ArrayToTensorProtora      *    !!\"B1668"BC"B   9c                 |    | j                   j                  |D cg c]  }|j                          c}       y c c}w r   )
double_valr    r   r!   s      r   #SlowAppendFloat64ArrayToTensorProtorf      *    ""l#CAFFH#CD#Crc   c                 |    | j                   j                  |D cg c]  }|j                          c}       y c c}w r   rY   r    r   r!   s      r   SlowAppendIntArrayToTensorProtorj      s*    < @a @A @rc   c                 |    | j                   j                  |D cg c]  }|j                          c}       y c c}w r   )	int64_valr    r   r!   s      r   !SlowAppendInt64ArrayToTensorProtorm      rb   rc   c                     | j                   j                  |D cg c]  }|j                         d    c}       y c c}w )Nr   ri   r!   s      r    SlowAppendQIntArrayToTensorProtoro      s.    l C! CD Cs   <c                 |    | j                   j                  |D cg c]  }|j                          c}       y c c}w r   )
uint32_valr    r   r!   s      r   "SlowAppendUInt32ArrayToTensorProtorr      rg   rc   c                 |    | j                   j                  |D cg c]  }|j                          c}       y c c}w r   )
uint64_valr    r   r!   s      r   "SlowAppendUInt64ArrayToTensorProtoru     rg   rc   c           	          | j                   j                  |D cg c]/  }|j                  |j                  fD ]  }|j	                          1 c}}       y c c}}w r   )scomplex_valr    realimagr   r"   r#   r   vs       r   %SlowAppendComplex64ArrayToTensorProtor|     G    $$'Ba!&&!&&1ABABBDB   4A
c           	          | j                   j                  |D cg c]/  }|j                  |j                  fD ]  }|j	                          1 c}}       y c c}}w r   )dcomplex_valr    rx   ry   r   rz   s       r   &SlowAppendComplex128ArrayToTensorProtor     r}   r~   c                     | j                   j                  |D cg c]  }t        j                  |       c}       y c c}w r   )
string_valr    r   as_bytesr!   s      r   "SlowAppendObjectArrayToTensorProtor     s-    ""#M1FOOA$6#MN#Ms   >c                 |    | j                   j                  |D cg c]  }|j                          c}       y c c}w r   )bool_valr    r   r!   s      r    SlowAppendBoolArrayToTensorProtor     s*      L!Aq!&&(!AB!Arc   c                 F    | j                         D ]  \  }}||k(  s|c S  y r   )items)
dtype_dictr)   keyvals       r   GetFromNumpyDTypeDictr   1  s/    ""$ hc3
e|j 
r   c                     | j                   t        j                  k(  s| j                   t        j                  k(  rt        rt
        j                  S t        S t        t        |       S r   )
typer   bytes_str__FAST_TENSOR_UTIL_AVAILABLEr   AppendObjectArrayToTensorProtor   r   _NP_TO_APPEND_FNr(   s    r   GetNumpyAppendFnr   9  sF    
 ZZ299

bgg 5"<<<//	/	77r   c                 T    | j                   D cg c]  }|j                   c}S c c}w )zConvert a TensorShape to a list.

  Args:
    shape: A TensorShapeProto.

  Returns:
    List of integers representing the dimensions of the tensor.
  )dimsize)shaper   s     r   TensorShapeProtoToListr   F  s      $ii	(s#((	((	(s   %c                 r    t        | t        t        f      sg S | sdgS t        |       gt	        | d         z   S )z9Returns the inferred dense dimensions of a list of lists.r   )
isinstancelisttuplelen_GetDenseDimensions)list_of_listss    r   r   r   R  s=    	MD%=	1I3J"5mA6F"GGGr   c              #   x   K   t        | t        t        f      r| D ]  }t        |      D ]  }|   y |  y wr   )r   r   r   _FlattenToStrings)nested_stringsinnerflattened_strings      r   r   r   \  sF     u. /6 
 s   8:c                     t        |       r   )
ValueError)r{   s    r   _check_failedr     s     	1r   c                     t        | t        t        f      st        |        t        | t              r| D cg c]  }t	        |       }}y | D cg c]  }t        |       }}y c c}w c c}w r   )r   r   r   r   
_check_int_check_quantizedvaluesr{   _s      r   r   r     sZ    	FT5M	*& &'1A'A'&,-	!	-A- 	(-s   A$A)c                       fd}|S )Nc                     t        j                  |       D ]U  }t        |      rt        |t        j                        r!t        |j                  j                        rKt        |       W y r   )	r   flattenr   r   ndarray
issubclassr)   r   r   )r   r{   expected_typess     r   r   z)_generate_isinstance_check.<locals>.inner  sM    \\&! N+!RZZ(!'',,7a	r    )r   r   s   ` r   _generate_isinstance_checkr     s     
,r   c                     t        j                  |       D cg c]'  }t        |t        j                        rt        |      ) }}y c c}w r   )r   r   r   r
   Symbolr   r   s      r   _check_not_tensorr     s?    !%f!5 &A
Q
$ Q &! & &s   ,Ac                    |t         }n
	 t        |   }	  ||        y # t        $ rU |j                  rt        }n?|j
                  rt        }n,|j                  rt        }n|j                  rt        }nt         }Y gw xY w# t        $ rR}|j                  \  }|t        d      t        d|j                   d| dt        |      j                    d      d }~ww xY w)Nz7Expected any non-tensor type, but got a tensor instead.z	Expected 
, but got z
 of type 'z'.)r   _TF_TO_IS_OKKeyError
is_integerr   is_floating_check_float
is_complex_check_complexis_quantizedr   r   args	TypeErrornamer   __name__)r   r)   fnemismatchs        r   _AssertCompatibler     s    
]	Bb7vJ  			 
 7JX}OPP	%**Zz Bx.112"6 7 77s(   	 A? AA<;A<?	CACCc                 (   t        | t        j                        rt        | t        j                        syt	        t        | dd            st        t        | dd      t              ry	 t        |        t        | t               S # t        $ r Y yw xY w)z&Check if a given object is array-like.F	__array__N__array_interface__T)
r   r
   r   Valuecallablegetattrdict
memoryviewbytesr   )objs    r   _is_array_liker     s~    T[[!*S$***E  wsK./3T:DA&sO #u%%% 
 s   )B 	BBmake_tensor_protoc           
      b   |r|rt        d      t        | t        j                        r| S |rt	        j
                  |      }|t        j                  t        j                  t        j                  t        j                  t        j                  fv }t        |       rt        j                  |       } t        | t        j                  t        j                   f      r/|r)|j"                  r| j%                  |j&                        }n{| }nw| t        d      |r|j"                  r|j&                  }nd}|@t        j(                  |t        j*                        dk(  rt        j,                  ||      }nvt/        | |       t        j0                  | |      }t3        |j4                        t7        |       k7  r3|s1t        d|  dt7        |        dt3        |j4                         d	      |j8                  t        j:                  k(  r"| |j%                  t        j<                        }nV|j8                  t        j*                  k(  r9|7|j%                  t        j>                        }t        j@                  ||      r|}t	        j
                  |j8                        }	|	tC        d
|j8                   d	      |r|}	|DtE        |d      r|jF                  |	jF                  k7  rtC        d| d|  d|j8                   d	      ||j4                  }d}
|jH                  }n|D cg c]  }tK        |       }}t        j(                  |t        j*                        }||jH                  k(  }
|r[|j4                  dk(  s|j4                  tM               k(  rn|jH                  |k7  rtC        dtM        |       d|j4                   d	      |r=|j4                  tM        |      k7  r%tC        dtM        |       d|j4                   d	      |jH                  |kD  rt        d|dd|jH                  dd	      t        j                  |	jN                  tQ        jR                  |      jU                               }|
rK|	tV        v rC|dkD  r>|jH                  |jX                  z  dk\  rt        d      |j[                         |_.        |S |	t        j^                  k(  ret        | t        j                        sKta        |       }	 |D cg c]  }tc        jd                  |       }}|jf                  ji                  |       |S |jk                         }tm        |j8                        }|tC        d|	jn                   d	       |||       |S c c}w c c}w # tB        $ r tC        d|  d      w xY w)a  Create a TensorProto.

  In TensorFlow 2.0, representing tensors as protos should no longer be a
  common workflow. That said, this utility function is still useful for
  generating TF Serving request protos:

  ```python
    request = tensorflow_serving.apis.predict_pb2.PredictRequest()
    request.model_spec.name = "my_model"
    request.model_spec.signature_name = "serving_default"
    request.inputs["images"].CopyFrom(tf.make_tensor_proto(X_new))
  ```

  `make_tensor_proto` accepts "values" of a python scalar, a python list, a
  numpy ndarray, or a numpy scalar.

  If "values" is a python scalar or a python list, make_tensor_proto
  first convert it to numpy ndarray. If dtype is None, the
  conversion tries its best to infer the right numpy data
  type. Otherwise, the resulting numpy array has a compatible data
  type with the given dtype.

  In either case above, the numpy ndarray (either the caller provided
  or the auto-converted) must have the compatible type with dtype.

  `make_tensor_proto` then converts the numpy array to a tensor proto.

  If "shape" is None, the resulting tensor proto represents the numpy
  array precisely.

  Otherwise, "shape" specifies the tensor's shape and the numpy array
  can not have more elements than what "shape" specifies.

  Args:
    values:         Values to put in the TensorProto.
    dtype:          Optional tensor_pb2 DataType value.
    shape:          List of integers representing the dimensions of tensor.
    verify_shape:   Boolean that enables verification of a shape of values.
    allow_broadcast:  Boolean that enables allowing scalars and 1 length vector
        broadcasting. Cannot be true when verify_shape is true.

  Returns:
    A `TensorProto`. Depending on the type, it may contain data in the
    "tensor_content" attribute, which is not directly useful to Python programs.
    To access the values you should convert the proto back to a numpy ndarray
    with `tf.make_ndarray(proto)`.

    If `values` is a `TensorProto`, it is immediately returned; `dtype` and
    `shape` are ignored.

  Raises:
    TypeError:  if unsupported types are provided.
    ValueError: if arguments have inappropriate values or if verify_shape is
     True and shape of values is not equals to a shape from the argument.

  z6allow_broadcast and verify_shape are not both allowed.NzNone values not supported.r(   r   zExpected values z! to be a dense tensor with shape z, but got shape .zUnrecognized data type: 
base_dtypez`dtype` z is not compatible with z
 of dtype T)   zExpected Tensor's shape: r   z*Too many elements provided. Takes at most d)r)   r	   r   l        z>Cannot create a tensor proto whose content is larger than 2GB.zFailed to convert elements of z to Tensor. Consider casting elements to a supported type. See https://www.tensorflow.org/api_docs/python/tf/dtypes for supported TF dtypes.z+Element type not supported in TensorProto: )8r   r   r   TensorProtor   as_dtypeqint8quint8qint16quint16qint32r   r   r   r   r   genericis_numpy_compatiblerW   r/   prodint64emptyr   np_arrayr   r   r   r)   float64float32int32array_equalr   hasattrr   r   intr   as_datatype_enumr	   as_shapeas_proto_TENSOR_CONTENT_TYPESitemsizer:   tensor_contentstringr   r   r   r   r    ravelr   r   )r   r)   r   verify_shapeallow_broadcastr   nparraynp_dtdowncasted_arraynumpy_dtypeis_same_size
shape_sizer   r"   r#   r   
str_values	append_fns                     r   r   r     s$   v 
M
NN
../M
OOE"E 
,,v}}fnn
--   F$$V,F RZZ01**e223gg~344 **""ee RWWU"((;q@e,g&%%fe4g w}}
!4V!<
<+F8 4""5f"=!>>N /03 4 	4
 	#rzz*g
--288
# 1	('	2" .+
.w}}oQ?
@@ K
| <!,,0F0FF
hug%=fX F$]]O1. / / ]MMELJ!&'#SX'E'bhh/J-L	$	'--57":<<:%3E%L>"==/, - 	- 
'--5<73E%L>"==/, - 	- 

	"E&q>GLL3C1F G 	G ''((((/88:<, k%::zA~||g&&&73
JL L")//"3L FMM!*VRZZ*H$V,L20<=1FOOA&=j= "":. ,|112)

5k6F6F5GqIK KL,'	E (` > 26vh ?1 1 2 22s$   (VV V!V V V.make_ndarrayc                     | j                   j                  D cg c]  }|j                   }}t        j                  |t        j
                        }t        j                  | j                        }|j                  }| j                  r>t        j                  | j                  |      j                         j                  |      S |t        j                  k(  rlt        | j                         }|t#        |      z
  }|dkD  r|r|d   nd}|j%                  |g|z         t        j&                  ||      j                  |      S |t        j(                  k(  s|t        j*                  k(  r8t        j,                  | j.                  t        j0                        }||_        na|t        j2                  t        j4                  fv r8t        j,                  | j6                  t        j8                        }||_        n|t        j:                  k(  r#t        j,                  | j<                  |      }n|t        j>                  k(  r#t        j,                  | j@                  |      }n|t        jB                  t        j8                  t        j0                  t        jD                  t        jF                  t        jH                  t        jJ                  t        jL                  t        jN                  t        jP                  t        jR                  t        jT                  fv r#t        j,                  | jV                  |      }n|t        j
                  k(  r#t        j,                  | jX                  |      }n|t        jZ                  k(  r#t        j,                  | j\                  |      }nT|t        j^                  k(  r#t        j,                  | j`                  |      }n|t        jb                  k(  rUte        | jf                        }	t        j&                  ti        |	|	      D 
cg c]  }
tk        |
d   |
d          c}
|      }n|t        jl                  k(  rUte        | jn                        }	t        j&                  ti        |	|	      D 
cg c]  }
tk        |
d   |
d          c}
|      }nN|t        jp                  k(  r"t        j,                  | jr                  |      }ntu        d| j                   d      |j                  dk(  rt        jv                  ||      S |j                  |k7  r&t        jx                  |d||j                  z
  fd      }|j                  |      S c c}w c c}
w c c}
w )	a\  Create a numpy ndarray from a tensor.

  Create a numpy ndarray with the same shape and data as the tensor.

  For example:

  ```python
  # Tensor a has shape (2,3)
  a = tf.constant([[1,2,3],[4,5,6]])
  proto_tensor = tf.make_tensor_proto(a)  # convert `tensor a` to a proto tensor
  tf.make_ndarray(proto_tensor) # output: array([[1, 2, 3],
  #                                              [4, 5, 6]], dtype=int32)
  # output has shape (2,3)
  ```

  Args:
    tensor: A TensorProto.

  Returns:
    A numpy array with the tensor contents.

  Raises:
    TypeError: if tensor has unsupported type.

  r(   r    r   zUnsupported tensor type: zS. See https://www.tensorflow.org/api_docs/python/tf/dtypes for supported TF dtypes.edge)=r	   r   r   r   r   r   r   r   r)   r/   r   
frombuffercopyreshaper   r   r   r   r    arrayr   r.   fromiterr   r   r8   r@   r7   r9   r   r`   r   re   r   int16rX   r   r   r   r   r   rV   r]   rY   rl   uint32rq   uint64rt   	complex64iterrw   zipcomplex
complex128r   boolr   r   zerospad)tensorr   r   num_elementstensor_dtyper)   r   paddinglastitr   s              r   MakeNdarrayr    s   6 "..22
3a166
3%
3bhh/,.,

%
%%MM&// %''+tvggen> V]]"&##$FS[(G{!VBZrdmmTFW$%88F%(0077V^^#|v'F [[		:FFL  [[**"((;FFLv~~%[[))7Fv~~%[[**%8Fllllmmllkkmmmmllmmnnkkll  [[u5Fv||#[[))7Fv}}$[[**%8Fv}}$[[**%8Fv'''	f!!	"BXXCBK@qwqtQqT*@NFv(((	f!!	"BXXCBK@qwqtQqT*@NFv{{"[[6F
/~ >/ / 0 0 [[A88E5!![[L VVFQv{{ :;VDF		S 4p A As   U1-U6U;c                    t        | t        j                        st        dt	        |        d      t        |t
        j                        r$|j                  D cg c]  }|j                   }}n.t        |t        t        f      st        dt	        |       d      | j                  j                  D cg c]  }|j                   }}t        d t        ||      D              S c c}w c c}w )ao  Returns True if "tensor_proto" has the given "shape".

  Args:
    tensor_proto: A TensorProto.
    shape: A tensor shape, expressed as a TensorShape, list, or tuple.

  Returns:
    True if "tensor_proto" has the given "shape", otherwise False.

  Raises:
    TypeError: If "tensor_proto" is not a TensorProto, or shape is not a
      TensorShape, list, or tuple.
  zE`tensor_proto` must be a tensor_pb2.TensorProto object, but got type r   z.`shape` must be a list or tuple, but got type c              3   ,   K   | ]  \  }}||k(    y wr   r   ).0r   ys      r   	<genexpr>zShapeEquals.<locals>.<genexpr>A  s     >1Q!V>s   )r   r   r   r   r   r   TensorShapeProtor   r   r   r   r	   allr  )r"   r   r   tensor_shape_lists       r   ShapeEqualsr(  *  s     
L*"8"8	9
 $$($6#7q: ; ;'889"YY'QVV'E'edE]+
DE{m1& ' ''3'@'@'D'DE!qvvEE	>$5u =>	>> ( Fs   C(7C-c                    t        | t        j                        st        | dt	        |        d      | j
                  j                  dk(  r$t        | j
                  j                  d            S | j
                  j                  dk(  r| j
                  j                  d   j                         }|j                         rMt        j                  |j                  D cg c]  }|j                   c}| j                  j                         S y | j
                  j                  dk(  r| j
                  j                  d   j                         }|j                         rGt        j"                  |j                  D cg c]  }|j                   c}t        j$                        S y | j
                  j                  d	k(  r| j
                  j                  d   j                         }|j&                  Tt        j(                  d
t        j                  |j&                  gt        j$                        t        j$                        S y | j
                  j                  dk(  rt+        | j
                  j                  d         }|y t+        | j
                  j                  d         }|y t+        | j
                  j                  d         }|y t        j,                  |||| j                  j                         S | j
                  j                  dk(  rnt+        | j
                  j                  d         }|y t/        j0                  | j
                  j                  d            }|j3                  |j                         S | j
                  j                  dk(  r|t+        | j
                  j                  d         }|y g }	| j
                  j                  dd  D ]"  }
t+        |
      }| y |	j5                  |       $ t        j6                  |	|      S | j
                  j                  dk(  r|t+        | j
                  j                  d         }|y g }	| j
                  j                  d d D ]"  }
t+        |
      }| y |	j5                  |       $ t        j6                  |	|      S | j
                  j                  dk(  rg }	| j
                  j                  sy | j
                  j                  d      dk7  ry | j
                  j                  D ]%  }
t+        |
|      }||s y |	j5                  |       ' 	 t        j                  |	      S | j
                  j                  dk(  rT| j
                  j                  d      dk7  ry t+        | j
                  j                  d   |      }|y || j<                     S | j
                  j                  dk(  rt+        | j
                  j                  d         }t+        | j
                  j                  d   |      }||y t        j>                  || j
                  j                  d      |      }|| j<                     S | j
                  j                  dk(  rq| j@                  }t+        | j
                  j                  d         }|j                         r2|0t        jB                  |jE                         ||j                        S y | j
                  j                  dk(  r`t+        | j
                  j                  d         }|y t+        | j
                  j                  d         }|y t        jF                  ||      S | j
                  j                  dk(  r`t+        | j
                  j                  d         }|y t+        | j
                  j                  d         }|y t        jH                  ||      S | j
                  j                  dk(  r#t+        | j
                  j                  d   |      S | j
                  j                  dv r#t+        | j
                  j                  d   |      S y c c}w c c}w # t8        $ r t        j                  |	t:              cY S w xY w)Nz must be a Tensor, but got r   ConstvalueShaper   r(   SizeRankr   )r   bufferr)   Ranger      CastDstTConcat)axisConcatV2r  Packr5  UnpackSplit	num_splitFillEqualNotEqualStopGradient)CheckNumericsV2DebugIdentityV2Identity)%r   r
   r   r   r   opr  get_attrinputs	get_shapeis_fully_definedr   r  dimsr+  r)   r/   r   r   ndimsr   constant_valuearanger   r   rW   appendconcatenater   objectvalue_indexsplitr   fullas_listequal	not_equal)r  partialinput_shaper   startlimitdeltapre_cast
cast_dtyper   r   r+  rO  
fill_shape
fill_valuevalue1value2s                    r   _ConstantValuer_  D  s   	FDKK	(
vj ;DL>K
LLYY^^wvyy))'233yy~~ ))""1%//1K##%XX + 0 0
1399
1++- - yy~~))""1%//1K##%WW;+;+;<Ccii<BHHMMyy~~))""1%//1K$ZZ;,,-RXX> 
 yy~~ 699++A./E}699++A./E}699++A./E}99UE50K0KLLyy~~fii..q12H!3!3F!;<J??:4455yy~~!
))!,
-C
{FYYab! Qe	mmE	
 >>&s++yy~~#
))"-
.C
{FYYcr" Qe	mmE	
 >>&s++yy~~F 99yy&!Q&YY Q(e	wmmE	
,XXf yy~~!yy&!Q&699++A.8E}##$$yy~~ 
))!,
-C699++A.8E}HHUFII..{;SAE##$$yy~~J		 0 0 34J""$)?WWZ''):Z=M=MNNyy~~ FII,,Q/0F~FII,,Q/0F~88FF##yy~~#FII,,Q/0F~FII,,Q/0F~<<''yy~~'&))**1-w77yy~~KK&))**1-w77s 2 =H  ,XXfF++,s   a=a?a! !$bbget_static_valuec                 0   t        | t        j                        r	 | j                         S t        |       s| S t        | t        j                        syt        | |      }|| j                  j                  |        |S # t        j
                  $ r Y yw xY w)a  Returns the constant value of the given tensor, if efficiently calculable.

  This function attempts to partially evaluate the given tensor, and
  returns its value as a numpy ndarray if this succeeds.

  Example usage:

  >>> a = tf.constant(10)
  >>> print(tf.get_static_value(a))
  10
  >>> b = tf.constant(20)
  >>> print(tf.get_static_value(tf.add(a, b)))
  30

  >>> # `tf.Variable` is not supported.
  >>> c = tf.Variable(30)
  >>> print(tf.get_static_value(c))
  None

  Using `partial` option is most relevant when calling `get_static_value` inside
  a `tf.function`. Setting it to `True` will return the results but for the
  values that cannot be evaluated will be `None`. For example:

  ```python
  class Foo:
    def __init__(self):
      self.a = tf.Variable(1)
      self.b = tf.constant(2)

    @tf.function
    def bar(self, partial):
      packed = tf.raw_ops.Pack(values=[self.a, self.b])
      static_val = tf.get_static_value(packed, partial=partial)
      tf.print(static_val)

  f = Foo()
  f.bar(partial=True)  # `array([None, array(2, dtype=int32)], dtype=object)`
  f.bar(partial=False)  # `None`
  ```

  Compatibility(V1): If `constant_value(tensor)` returns a non-`None` result, it
  will no longer be possible to feed a different value for `tensor`. This allows
  the result of this function to influence the graph that is constructed, and
  permits static shape optimizations.

  Args:
    tensor: The Tensor to be evaluated.
    partial: If True, the returned numpy array is allowed to have partially
      evaluated values. Values that can't be evaluated will be None.

  Returns:
    A numpy ndarray containing the constant value of the given `tensor`,
    or None if it cannot be calculated.

  Raises:
    TypeError: if tensor is not an tensor.Tensor.
  N)r   r
   r   numpyr   UnimplementedError	is_tensorr   r_  graphprevent_feeding)r  rT  rets      r   rI  rI    s    v 

#\\^
 
6	M	FDKK	(vw'#_ LL  (	* ))  s   A? ?BBc           	         t        | t        j                        r8t        j                  | j                         D cg c]  }|dk7  r|nd c}      S | j                         j                  dk(  r@t        |       }|t        d      |dk7  rt        d| d      t        j                         S | j                         j                  d      }|dgk(  rt        j                  g       S | j                  j                  dk(  r$t        | j                  j                  d         }|j                   |S t#        j$                  | j                  j'                  d	            }|t"        j(                  t"        j*                  fvr,t        j                  |j                   d   j,                        S t/        j0                  |j3                         D cg c]  }||nd
 c}      j5                  |j6                        }t        j                  |D cg c]  }|dk\  r|nd c}      S | j                  j                  d
k(  r'| j                  j                  d   j                         S | j                  j                  dk(  rt        j                  g       }| j                  j'                  d      dk(  sJ | j                  j                  D ]Q  }	t        |	      }
|
|
dk  rt        j8                  d      }nt        j8                  |
      }|j;                  |g      }S |S | j                  j                  dk(  rOt        j                  g       }| j                  j                  dd D ]  }|j;                  t        |            } |S | j                  j                  dk(  rOt        j                  g       }| j                  j                  dd D ]  }|j;                  t        |            } |S | j                  j                  dk(  r}	 t        | j                  j                  d         }t        | j                  j                  d         }t        | j                  j                  d         }||||d   }|d   }|d   }| j                  j'                  d      }|dk(  rd}| j                  j'                  d      }|dk(  rd}| j                  j'                  d      }| j                  j'                  d      }| j                  j'                  d      }| xr  | xr | xr | xs |dk(  xr
 | xs |dk(  }|rAt        | j                  j                  d         }||||   }t        j                  |      }|S n| j                  j                  dk(  r| j                  j>                  j@                  rtC        | j                  j>                  d      retE        | j                  j>                  jF                        D ]9  \  }}|| u s| j                  j>                  jH                  |   }t        |      c S  t        j                  |j                   d   j,                        }t        |       }|9|jK                  t        j                  |D cg c]  }|dk\  r|nd c}            }|S c c}w c c}w c c}w # t        $ r Y t<        $ r Y w xY wc c}w )aq  A version of `constant_value()` that returns a `TensorShape`.

  This version should be used when a constant tensor value is
  interpreted as a (possibly partial) shape, e.g. in the shape
  function for `tf.reshape()`. By explicitly requesting a
  `TensorShape` as the return value, it is possible to represent
  unknown dimensions; by contrast, `constant_value()` is
  all-or-nothing.

  Args:
    tensor: The rank-0 or rank-1 Tensor to be evaluated.

  Returns:
    A `TensorShape` based on the constant value of the given `tensor`.

  Raises:
    ValueError: If the shape is rank-0 and is not statically known to be -1.
  r  Nr   z~Received a scalar with unknown value as shape; require a statically known scalar with value '-1' to describe an unknown shape.zReceived a scalar value 'z[' as shape; require a statically known scalar with value '-1' to describe an unknown shape.r   r2  r3  r,  r7  r5  r4  r6  StridedSlicer1     
begin_maskend_maskellipsis_masknew_axis_maskshrink_axis_maskPlaceholderinternal_captures)&r   r
   r   r	   TensorShaperb  rE  rH  rI  r   unknown_shape	with_rankrB  r   constant_value_as_shaperD  rG  r   r   rC  r   r   r+  r   r  rQ  rW   r/   	DimensionrL  r   re  building_functionr   	enumeraterq  external_captures
merge_with)r  r   r+  r   rY  rZ  r   dest_dtype_shape_arrayrg  
pack_inputpack_input_valnew_dimconcat_inputbeginendstridesrk  rl  rm  rn  ro  valid_attributesprevicaptureexternal_capturer   s                              r   ru  ru    sS   & 

###/5||~>r	t	#>@ @ "6"E}GH H {%eW -G GH H %%''




&
&q
)%
qc\##B''yy~~&vyy'7'7':;H}}o!3!3F!;<J&,,55''

1(;(;<<XX-5-=-=-?@am	#@BBH&%%C'  ##'%) !V%) * * yy~~ 99A((**yy~~

"
"2
&C 99f%***ii&& '
 &j1n		>A#5((.((8OOWI&c' Jyy~~! 
"
"2
&C		((, C OO3LABcC Jyy~~# 
"
"2
&C		(("- C OO3LABcC Jyy~~'VYY--a01e699++A./cvyy//23g		s73Fa!f!*YY''5
?%99%%j1q=#		**?;		**?;!99--.@A -- >m2C > 00>:Dn 7H7AQ> "*\<h!m 	 ()9)9!)<=$eC'($((.#* 			-'		))		!45  		 A AB 9
7	F	!99??<<Q?&'7889
 	""5::a=#6#67#

 %

..  !GAqAv!4"7!GHJC	*o 	?4 	A%)J  
 
& "Hs0   Z;[ [E:[
 [#
	[ [ [ c                       e Zd Zd Zy)IsTensorLikec                      y r   r   )selfs    r   is_tensor_likezIsTensorLike.is_tensor_like  s    r   N)r   
__module____qualname__r  r   r   r   r  r    s    	r   r  rd  c                 "    t        | t              S )a  Checks whether `x` is a TF-native type that can be passed to many TF ops.

  Use `is_tensor` to differentiate types that can ingested by TensorFlow ops
  without any conversion (e.g., `tf.Tensor`, `tf.SparseTensor`, and
  `tf.RaggedTensor`) from types that need to be converted into tensors before
  they are ingested (e.g., numpy `ndarray` and Python scalars).

  For example, in the following code block:

  ```python
  if not tf.is_tensor(t):
    t = tf.convert_to_tensor(t)
  return t.shape, t.dtype
  ```

  we check to make sure that `t` is a tensor (and convert it if not) before
  accessing its `shape` and `dtype`.  (But note that not all TensorFlow native
  types have shapes or dtypes; `tf.data.Dataset` is an example of a TensorFlow
  native type that has neither shape nor dtype.)

  Args:
    x: A python object to check.

  Returns:
    `True` if `x` is a TensorFlow-native type.
  )r   tf_type_classesr   s    r   
is_tf_typer    s    8 
A	''r   c                     | j                   j                  j                         5 }t        j                  || j                               cddd       S # 1 sw Y   yxY w)zEvaluates a symbolic tensor as a constant.

  Args:
    tensor: a symbolic Tensor.

  Returns:
    ndarray if the evaluation succeeds, or None if it fails.
  N)re  _c_graphgetc_apiTF_TryEvaluateConstant_wrapper_as_tf_output)r  c_graphs     r   try_evaluate_constantr    sN     ||  " Qg//9M9M9OPQ Q Qs   $AA)NNFF)F)__doc__typingr   rb  r   tensorflow.core.frameworkr   r   tensorflow.python.clientr   r  tensorflow.python.frameworkr   r   r	   tensorflow.python.typesr
   r   tensorflow.python.utilr   r   r    tensorflow.python.util.tf_exportr   r   r   ImportErrorr   r$   r,   r0   r2   r5   r;   r>   rA   rC   rF   rI   rM   rO   rR   rT   r[   r^   r   r   AppendFloat32ArrayToTensorProtor   AppendFloat64ArrayToTensorProtor   AppendInt32ArrayToTensorProtor   AppendInt64ArrayToTensorProtor9   AppendUInt8ArrayToTensorProtor   AppendUInt16ArrayToTensorProtor  AppendUInt32ArrayToTensorProtor  AppendUInt64ArrayToTensorProtorX   AppendInt8ArrayToTensorProtor  AppendInt16ArrayToTensorProtor  !AppendComplex64ArrayToTensorProtor  "AppendComplex128ArrayToTensorProtoobject_r   bool_AppendBoolArrayToTensorProtor   r/   r   r   r   r   r.   r8   r@   rE   rL   rQ   rV   r]   r   ra   rf   rj   rm   ro   rr   ru   r|   r   r   r   r   r   r   r   r   	frozensetr   r   r   r   integral_typesrv  r   
real_typesr   complex_typesr   bytes_or_text_types
_check_strr  _check_boolr   r   r   r   r   r   r  r(  r_  rI  ru  runtime_checkabler  NativeObjectTensorr  r  rd  r  r   r   r   <module>r     sr   (    0 6 ? . 3 4 ( , ) ' / 6
&: $GOF
OQ** /jj8/jj"BB/ 	jj"BB/ 	hh >>	/
 	hh >>/ 	hh >>/ 	ii!@@/ 	ii!@@/ 	ii!@@/ 	gg<</ 	hh >>/ 	ll$FF/ 	mm%HH/ 	jj"AA/ 	hh ==/  ll!!

7
7#/& mm""

8
8)/, mm""

8
8nn##

9
9mm""

8
8oo$$&J'')O))
2++
4..
7++
4kk  "Bll!!#D]/dDEBDEEEDDOCoo$$&J'')O ))
2	 	jj5 	jj5 	jj5 	hh/ 	hh1 	hh/ 	ii0 	ii3 	ii3 	gg.  	hh/!" 	ll9#$ 	mm;%& 	jj4'( 	hh0ll!!#Cmm""$Dmm""$Dnn##%Emm""$Dkk  "Bll!!#D7>
8	)H "
NN
NN
NN
LL
LL
LL
KK
LL
LL
MM
MM
NN
MM
MM
MM





OO+#  8. (L2235
)&*;*;<+F,@,@A'(B(BC
(.&

KK
~ n NNL	
 NNL NNL LL* LL* LL* KK MM# MM# LL" NN$ MM#  MM:!" MM:#$ LL*
MM:
MM:)07<&* CH&+K  K^ >c cL?4CL J JZL^ 	8 	 	 (($++|D ;( (> 	QY%  & %&s   _: :``