
    &VfT                        d Z ddlZddlmZ ddlmZmZ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i ej        e
ej        eej        eej        eej        eej        eej        eej        eej         eej!        eej"        eej#        eej$        eej%        eej&        eej'        j(        eej)        j(        eej*        j(        eej+        j(        eej,        j(        eiZ-ej.        j(        eiZ/d Z0d Z1d Z2d Z3 e4e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        ej         g          Z5 G d d          Z6d Z7d Z8d Z9d Z:d Z;d Z<d  Z=d! Z>i ej?        e>gej$        e<gej#        e<gej        e;gej        e;gej        e;gej"        e:gej        e:gej        e:gej!        e:gej*        e:e9gej,        e:e9gej'        e:e9gej+        e:e9gej)        e:e9gej@        e=gej        e:gej        e:giZAd" ZBd&d$ZCd% ZDdS )'z%Utilities to manipulate TensorProtos.    N)
tensor_pb2)dtypescompattensor_shapec                     t          j        | t           j                                      t           j                                                  S Ndtype)npasarrayfloat16viewuint16itemxs    Y/var/www/html/software/conda/lib/python3.11/site-packages/tensorboard/util/tensor_util.pyExtractBitsFromFloat16r      s5    :arz***//	::??AAA    c                 N    | j                             d |D                        d S )Nc                 ,    g | ]}t          |          S  )r   .0r   s     r   
<listcomp>z7SlowAppendFloat16ArrayToTensorProto.<locals>.<listcomp>   s!    999q		"	"999r   half_valextendtensor_protoproto_valuess     r   #SlowAppendFloat16ArrayToTensorProtor"      s8      99L999    r   c                     t          j        | t          j        j                                      t           j                                                  S r   )r   r   r   bfloat16as_numpy_dtyper   r   r   r   s    r   ExtractBitsFromBFloat16r&   !   s4    

1FO:;;;	bi	r   c                 N    | j                             d |D                        d S )Nc                 ,    g | ]}t          |          S r   )r&   r   s     r   r   z8SlowAppendBFloat16ArrayToTensorProto.<locals>.<listcomp>+   s!    :::	 	#	#:::r   r   r   s     r   $SlowAppendBFloat16ArrayToTensorProtor)   )   s8      ::\:::    r   c                 N    | j                             d |D                        d S )Nc                 6    g | ]}|                                 S r   r   r   s     r   r   z7SlowAppendFloat32ArrayToTensorProto.<locals>.<listcomp>0        "B"B"B16688"B"B"Br   )	float_valr   r   s     r   #SlowAppendFloat32ArrayToTensorProtor/   /   .    !!"B"B\"B"B"BCCCCCr   c                 N    | j                             d |D                        d S )Nc                 6    g | ]}|                                 S r   r,   r   s     r   r   z7SlowAppendFloat64ArrayToTensorProto.<locals>.<listcomp>4        #C#C#CAFFHH#C#C#Cr   )
double_valr   r   s     r   #SlowAppendFloat64ArrayToTensorProtor5   3   .    ""#C#Cl#C#C#CDDDDDr   c                 N    | j                             d |D                        d S )Nc                 6    g | ]}|                                 S r   r,   r   s     r   r   z3SlowAppendIntArrayToTensorProto.<locals>.<listcomp>8   s      @ @ @a @ @ @r   int_valr   r   s     r   SlowAppendIntArrayToTensorProtor;   7   s.     @ @< @ @ @AAAAAr   c                 N    | j                             d |D                        d S )Nc                 6    g | ]}|                                 S r   r,   r   s     r   r   z5SlowAppendInt64ArrayToTensorProto.<locals>.<listcomp><   r-   r   )	int64_valr   r   s     r   !SlowAppendInt64ArrayToTensorProtor?   ;   r0   r   c                 N    | j                             d |D                        d S )Nc                 B    g | ]}|d                                           S )r   r,   r   s     r   r   z4SlowAppendQIntArrayToTensorProto.<locals>.<listcomp>@   s$     C C C1 C C Cr   r9   r   s     r    SlowAppendQIntArrayToTensorProtorB   ?   s.     C Cl C C CDDDDDr   c                 N    | j                             d |D                        d S )Nc                 6    g | ]}|                                 S r   r,   r   s     r   r   z6SlowAppendUInt32ArrayToTensorProto.<locals>.<listcomp>D   r3   r   )
uint32_valr   r   s     r   "SlowAppendUInt32ArrayToTensorProtorF   C   r6   r   c                 N    | j                             d |D                        d S )Nc                 6    g | ]}|                                 S r   r,   r   s     r   r   z6SlowAppendUInt64ArrayToTensorProto.<locals>.<listcomp>H   r3   r   )
uint64_valr   r   s     r   "SlowAppendUInt64ArrayToTensorProtorJ   G   r6   r   c                 N    | j                             d |D                        d S )Nc                 X    g | ]'}|j         |j        fD ]}|                                (S r   realimagr   r   r   vs      r   r   z9SlowAppendComplex64ArrayToTensorProto.<locals>.<listcomp>M   6    BBBa!&!&1ABBABBBBr   )scomplex_valr   r   s     r   %SlowAppendComplex64ArrayToTensorProtorT   K   8    $$BB<BBB    r   c                 N    | j                             d |D                        d S )Nc                 X    g | ]'}|j         |j        fD ]}|                                (S r   rM   rP   s      r   r   z:SlowAppendComplex128ArrayToTensorProto.<locals>.<listcomp>S   rR   r   )dcomplex_valr   r   s     r   &SlowAppendComplex128ArrayToTensorProtorY   Q   rU   r   c                 N    | j                             d |D                        d S )Nc                 6    g | ]}t          j        |          S r   r   as_bytesr   s     r   r   z6SlowAppendObjectArrayToTensorProto.<locals>.<listcomp>X   s"    #M#M#M1FOA$6$6#M#M#Mr   )
string_valr   r   s     r   "SlowAppendObjectArrayToTensorProtor_   W   s.    ""#M#M#M#M#MNNNNNr   c                 N    | j                             d |D                        d S )Nc                 6    g | ]}|                                 S r   r,   r   s     r   r   z4SlowAppendBoolArrayToTensorProto.<locals>.<listcomp>\   s     !A!A!Aq!&&((!A!A!Ar   )bool_valr   r   s     r    SlowAppendBoolArrayToTensorProtorc   [   s.      !A!AL!A!A!ABBBBBr   c                     |                                  D ]\  }}||k    r|c S t                                           D ]\  }}||k    r|c S d S N)itemsBACKUP_DICT)
dtype_dictr
   keyvals       r   GetFromNumpyDTypeDictrk   |   ss    $$&&  S%<<JJJ %%''  S%<<JJJ 4r   c                     | j         t          j        k    s| j         t          j        k    rt          S t          t          |           S re   )typer   string_unicode_r_   rk   _NP_TO_APPEND_FNr	   s    r   GetNumpyAppendFnrq      s8    
 zRZ5:#<#<11 !15999r   c                     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   rw   rw      sR    mdE]33 L	 Ls
M""#&9-:J&K&KKKr   c              #      K   t          | t          t          f          r| D ]}t          |          D ]}|V  d S | V  d S re   )rs   rt   ru   _FlattenToStrings)nested_stringsinnerflattened_strings      r   rz   rz      su      .4-00 # 	' 	'E$5e$<$< ' ' &&&&&'	' 	' r   c                       e Zd Zd Zd ZdS )_Messagec                     || _         d S re   _message)selfmessages     r   __init__z_Message.__init__   s    r   c                     | j         S re   r   )r   s    r   __repr__z_Message.__repr__   s
    }r   N)__name__
__module____qualname__r   r   r   r   r   r   r      s2                 r   r   c                     | D ]}||c S 	d S re   r   )lr   s     r   _FirstNotNoner      s)      =HHH 4r   c                 (    | t          d          S | S )NNone)r   rQ   s    r   _NotNoner      s    yr   c                 ^   t          | t          t          f          s| S t          | t                    rt          d | D                       sd S t          | t                    r2t          d | D                       st	          d | D                       S t	          d | D                       S )Nc              3   N   K   | ] }t          |t          t          f          V  !d S re   rs   rt   ru   r   s     r   	<genexpr>z_FilterTuple.<locals>.<genexpr>   0      ;;A:a$//;;;;;;r   c              3   N   K   | ] }t          |t          t          f          V  !d S re   r   r   s     r   r   z_FilterTuple.<locals>.<genexpr>   r   r   c                 N    g | ]"}t          |t          t          f          rd n|#S re   r   r   s     r   r   z _FilterTuple.<locals>.<listcomp>   s/    HHHAe}55<1HHHr   c                 ,    g | ]}t          |          S r   )_FilterTupler   s     r   r   z _FilterTuple.<locals>.<listcomp>   s    555a,q//555r   )rs   rt   ru   anyr   r   s    r   r   r      s    a$'' !U ;;;;;;; 	4!T ;;;;;;; 	 HHaHHH   551555666r   c                     t          | t          t          f          rt          d | D                       S t          | t          j        t          j        f          rd nt          |           S )Nc                 ,    g | ]}t          |          S r   )
_FilterIntr   s     r   r   z_FilterInt.<locals>.<listcomp>       777jmm777r   )	rs   rt   ru   r   r   integral_typesr   	Dimensionr   r   s    r   r   r      sf    !dE]## 977Q777888 a&/1GHII	a[[r   c                     t          | t          t          f          rt          d | D                       S t          | t          j                  rd nt          |           S )Nc                 ,    g | ]}t          |          S r   )_FilterFloatr   s     r   r   z _FilterFloat.<locals>.<listcomp>   s    999!l1oo999r   )rs   rt   ru   r   r   
real_typesr   r   s    r   r   r      sW    !dE]## ;99q999:::a!233D44!Dr   c                     t          | t          t          f          rt          d | D                       S t          | t          j                  rd nt          |           S )Nc                 ,    g | ]}t          |          S r   )_FilterComplexr   s     r   r   z"_FilterComplex.<locals>.<listcomp>   s     ;;;AnQ//;;;r   )rs   rt   ru   r   r   complex_typesr   r   s    r   r   r      sW    !dE]## =;;;;;<<<a!566G44HQKKGr   c                     t          | t          t          f          rt          d | D                       S t          | t          j                  rd S t          |           S )Nc                 ,    g | ]}t          |          S r   )
_FilterStrr   s     r   r   z_FilterStr.<locals>.<listcomp>   r   r   )rs   rt   ru   r   r   bytes_or_text_typesr   r   s    r   r   r      s[    !dE]## 977Q777888!V/00 t{{r   c                     t          | t          t          f          rt          d | D                       S t          | t                    rd nt          |           S )Nc                 ,    g | ]}t          |          S r   )_FilterBoolr   s     r   r   z_FilterBool.<locals>.<listcomp>   s    888k!nn888r   )rs   rt   ru   r   boolr   r   s    r   r   r      sT    !dE]## :88a888999a&&744HQKK7r   c           
      
    |	|t           vrd S t                               |          }t           fd|D                       }|=t          d|j        dt          |          dt          |          j        d          d S )Nc                 &    g | ]} |          S r   r   )r   fnvaluess     r   r   z&_Assertconvertible.<locals>.<listcomp>  s!    ;;;Rbbjj;;;r   z	Expected , got z
 of type 'z
' instead.)_TF_TO_IS_OKgetr   	TypeErrornamereprrm   r   )r   r
   fn_listmismatchs   `   r   _Assertconvertibler     s    }\11u%%G;;;;7;;;<<Hizzz4>>>>4>>+B+B+BD
 
 	
 r   Fc           
      "
   t          | t          j                  r| S |rt          j        |          }|t          j        t          j        t          j        t          j        t          j	        fv }t          | t          j        t          j        f          r"|r|                     |j                  }n| }nt          t!          | dd                    s$t          t!          | dd          t"                    rt          j        | |          }|} nj| t'          d          |r|j        r|j        }nd}|;t          j        |t          j                  dk    rt          j        ||          }nt1          | |           t          j        | |          }t5          |j                  t9          |           k    r:|s8t'          d| dt5          |j                  d	t9          |           d
          |j        t          j        k    r"| |                    t          j                  }nM|j        t          j        k    r8|6|                    t          j                   }t          j!        ||          r|}t          j        |j                  }|tE          d|j        z            |r|}|=tG          |d          r|j$        |j$        k    rtE          d|d|j        d|           ||j        }d}	|j%        }
nd |D             }t          j        |t          j                  }
|
|j%        k    }	|r@|j        tM          |          k    s(tE          dtM          |          d|j        d
          |j%        |
k    rt'          d|
|j%        fz            t          j        |j'        tQ          j)        |          *                                          }|	rL|tV          v rC|
dk    r=|j%        |j,        z  dk    rt'          d          |-                                |_.        |S |t          j/        k    rt          | t          j                  sjta          |           }	 d |D             }n1# tD          $ r$ tE          dtc          |           d| d          w xY w|j2        3                    |           |S |4                                }tk          |j                  }|tE          d|j6        z             |||           |S )a  Create a TensorProto.

    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.

    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 `tensor_util.MakeNdarray(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.

    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 convertible data
    type with the given dtype.

    In either case above, the numpy ndarray (either the caller provided
    or the auto converted) must have the convertible 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.
    	__array__N__array_interface__r	   zNone values not supported.r   z!Argument must be a dense tensor: z - got shape z, but wanted .zUnrecognized data type: %s
base_dtypezInconvertible types: z vs. z. Value is Tc                 ,    g | ]}t          |          S r   )int)r   dims     r   r   z%make_tensor_proto.<locals>.<listcomp>  s    +++cS+++r   zExpected Tensor's shape: r   z>Too many elements provided. Needed at most %d, but received %d)r
   r      l        z>Cannot create a tensor proto whose content is larger than 2GB.c                 6    g | ]}t          j        |          S r   r\   r   s     r   r   z%make_tensor_proto.<locals>.<listcomp>  s"    CCC&/!,,CCCr   z!Failed to convert object of type z to Tensor. Contents: z0. Consider casting elements to a supported type.z-Element type not supported in TensorProto: %s)7rs   r   TensorProtor   as_dtypeqint8quint8qint16quint16qint32r   ndarraygenericastyper%   callablegetattrdictr   
ValueErroris_numpy_compatibleprodint64emptyr   arrayrt   shaperw   r
   float64float32int32array_equalr   hasattrr   sizeru   as_datatype_enumr   as_shapeas_proto_TENSOR_CONTENT_TYPESitemsizetobytestensor_contentstringrz   rm   r^   r   ravelrq   r   )r   r
   r   verify_shapeis_quantizednparraynp_dtdowncasted_arraynumpy_dtypeis_same_size
shape_sizer    r!   
str_values	append_fns                  r   make_tensor_protor   $  ss   V &*011  '&& L &2:rz233 3+ 	mmE$899GGGG	'&+t44	5	5 .+-t44d: : .+
 *V5111 >9:::  	U. 	(EEE bh!?!?!?1!D!DhuE222GGvu---hvU333G W]##':6'B'BBB$ C !j vvtGM22224G4O4O4O4OQ   MRZ''U]nnRZ00GGmrx''U]&~~bh77~.88 +* /'-00K4w}DEEE  E<(( {555iuugmmmVV-
 
 	
 }\

++U+++WU"(333
!W\1 	=E%LL00iU||||W]]]4  
 <*$$Pw|,-  
 )*!*511::<<  L
  '<<<a<'**w77P   '.oo&7&7# fm##Jvrz,J,J#(00	CClCCCJJ 	 	 	) &*&\\\\666;  	 	&&z222 ==??L !344I;k>NN
 
 	
 IlL)))s   (Q5 5.R#c                    d | j         j        D             }t          j        |t          j                  }t          j        | j                  }|j        }| j	        r@t          j
        | j	        |                                                              |          S |t
          j        k    s|t
          j        k    rt          | j                  dk    r_t          j        | j        d         t          j                  }|j        |_        t          j        ||                              |          S t          j        | j        t          j                  }|j        |_        |                    |          S |t
          j        k    rt          | j                  dk    rGt          j        t          j        | j        d         |          |                              |          S t          j        | j        |                              |          S |t
          j        k    rt          | j                  dk    rGt          j        t          j        | j        d         |          |                              |          S t          j        | j        |                              |          S |t
          j        t
          j        t
          j        t
          j        t
          j        t
          j        t
          j        t
          j        t
          j         t
          j!        f
v rt          | j"                  dk    rGt          j        t          j        | j"        d         |          |                              |          S t          j        | j"        |                              |          S |t
          j        k    rt          | j#                  dk    rGt          j        t          j        | j#        d         |          |                              |          S t          j        | j#        |                              |          S |t
          j$        k    rt          | j%                  dk    rGt          j        t          j        | j%        d         |          |                              |          S t          j        tM          | j%                  |                              |          S |t
          j'        k    rtQ          | j)                  }t          | j)                  dk    r`t          j        t          j        tU          | j)        d         | j)        d                   |          |                              |          S t          j        d tW          ||          D             |                              |          S |t
          j,        k    rtQ          | j-                  }t          | j-                  dk    r`t          j        t          j        tU          | j-        d         | j-        d                   |          |                              |          S t          j        d tW          ||          D             |                              |          S |t
          j.        k    rt          | j/                  dk    rGt          j        t          j        | j/        d         |          |                              |          S t          j        | j/        |                              |          S ta          d| j        z            )	a  Create a numpy ndarray from a tensor.

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

    Args:
      tensor: A TensorProto.

    Returns:
      A numpy array with the tensor contents.

    Raises:
      TypeError: if tensor has unsupported type.
    c                     g | ]	}|j         
S r   )r   )r   ds     r   r   z make_ndarray.<locals>.<listcomp>  s    555QV555r   r	   r   r      c                 F    g | ]}t          |d          |d                   S r   r   complexr   s     r   r   z make_ndarray.<locals>.<listcomp>Q  *    :::1qt$$:::r   c                 F    g | ]}t          |d          |d                   S r   r   r   s     r   r   z make_ndarray.<locals>.<listcomp>_  r   r   zUnsupported tensor type: %s)1r   r   r   r   r   r   r   r
   r%   r   
frombuffercopyreshaper   r$   rv   r   r   r   repeatfromiterr   r.   r   r4   r   uint8int16int8r   r   r   r   r   r:   r>   r   r^   rt   	complex64iterrS   r   zip
complex128rX   r   rb   r   )tensorr   num_elementstensor_dtyper
   tmpits          r   make_ndarrayr    sK    65V04555E75111L?6<00L'E cFM&/u===TVVWU^^	

 
	'	'<6?+J+J v1$$(6?1-RY???C$3CI9S,//77>>>+foRY???C$3CI;;u%%%		'	'v  A%%9)!,E:::L genn ;v/u===EEeLLL		'	'v !!Q&&9*1-U;;;\ genn ;v0>>>FFuMMM	 
 
 v~!##9*%888, genn ;v~U;;;CCEJJJ		%	%v  A%%9)!,E:::L genn ;v/u===EEeLLL		&	&v !!Q&&9*1-U;;;\ genn 8D!2335AAAII%PPP	)	)	)&%&&v"##q((9F/2F4G4JKK     genn 8::c"bkk:::%  genn 
*	*	*&%&&v"##q((9F/2F4G4JKK     genn 8::c"bkk:::%  genn 
	$	$v1$$9+5999< genn ;ve<<<DDUKKK5DEEEr   )NNF)E__doc__numpyr   tensorboard.compat.protor   "tensorboard.compat.tensorflow_stubr   r   r   r   r"   r&   r)   r/   r5   r;   r?   rB   rF   rJ   rT   rY   r_   rc   r   r   r   r   r   r  r   uint32uint64r  r  r	  r  object_bool_r   r%   r   r   r   r   rp   r$   rg   rk   rq   rw   rz   	frozensetr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   <module>r     s\   , +     / / / / / / K K K K K K K K K KB B B      D D DE E EB B BD D DE E EE E EE E E    O O OC C CJ3J3 J3 H-	
 H/ H- I. I1 I1 G, H- L7 M9 J2 H.  L!A!" M "B#$ M "B
N!#C
M "B)  2 O"$H
  : : :L L L   "	  (           7 7 7  E E EH H H  8 8 8
K+
' ~& N\N	
 N\N N\N L:, L:, L:, K* MJ- MJ- L:|, NZ. MJ-  MJ<!" MJ<#$ L:,% ,

 

 

L L L L^vF vF vF vF vFr   