
    1Vh8                         d 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 Zd Zd	 Zd
 Zd Zd Zd Zy)z?Utilities to migrate legacy protos to their modern equivalents.    N)	event_pb2)summary_pb2)metadata)tensor_utilc                    | j                  d      s| S | j                  j                  }|D cg c]  }t        |       }}t	        |      t	        |      k(  rt        d t        ||      D              r| S t        j                         }|j                  |        |j                  j                  d d = |j                  j                  j                  |       |S c c}w )Nsummaryc              3   *   K   | ]  \  }}||u   y w)N ).0xys      G/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/data_compat.py	<genexpr>z migrate_event.<locals>.<genexpr>#   s      2AqQ2s   )HasFieldr   valuemigrate_valuelenallzipr   EventCopyFromextend)event
old_valuesr   
new_valuesresults        r   migrate_eventr      s    >>)$$$J4>?5-&?J?
:#j/)c 2 Z82 / __F
OOEQ
NN
+M @s   Cc                     t         t        t        t        dj	                  | j                  d            }|r ||       S | S )a@  Convert `value` to a new-style value, if necessary and possible.

    An "old-style" value is a value that uses any `value` field other than
    the `tensor` field. A "new-style" value is a value that uses the
    `tensor` field. TensorBoard continues to support old-style values on
    disk; this method converts them to new-style values so that further
    code need only deal with one data format.

    Arguments:
      value: A `Summary.Value` object. This argument is not modified.

    Returns:
      If the `value` is an old-style value for which there is a new-style
      equivalent, the result is the new-style value. Otherwise---if the
      value is already new-style or does not yet have a new-style
      equivalent---the value will be returned unchanged.

    :type value: Summary.Value
    :rtype: Summary.Value
    )histoimageaudiosimple_valuer   )_migrate_histogram_value_migrate_image_value_migrate_audio_value_migrate_scalar_valueget
WhichOneof)r   handlers     r   r   r   .   sD    , *%%-	
 
c%

7
#$  %75>/%/    c                 p    t        j                  |      }t        j                  j	                  | ||      S )N)tagr   tensor)r   make_tensor_protor   SummaryValue)r,   r   datatensor_protos       r   make_summaryr3   L   s7    006L$$(< %  r*   c                   
 | j                   }|j                  
t        
      }t        
fdt	        |      D        |      }t        
fdt        t	        |            D        d      }||kD  r(t        j                  ddgt        j                        }nm
||dz    
|j                  || }|j                  g|z   }||j                  gz   }t        j                  ||
gt        j                        j                         }t        j                  | j                   j"                  xs | j$                  | j                   j&                        }	t)        | j$                  |	|      S )	a  Convert `old-style` histogram value to `new-style`.

    The "old-style" format can have outermost bucket limits of -DBL_MAX and
    DBL_MAX, which are problematic for visualization. We replace those here
    with the actual min and max values seen in the input data, but then in
    order to avoid introducing "backwards" buckets (where left edge > right
    edge), we first must drop all empty buckets on the left and right ends.
    c              3   4   K   | ]  }|   d kD  s|  ywr   Nr
   r   ibucket_countss     r   r   z+_migrate_histogram_value.<locals>.<genexpr>`   s     >q)9A)=!>   c              3   4   K   | ]  }|   d kD  s|  ywr6   r
   r7   s     r   r   z+_migrate_histogram_value.<locals>.<genexpr>a   s     Faq1AA1EFr:   r      )dtype   display_namedescription)r   bucketr   nextrangereversednpzerosfloat32bucket_limitminmaxarray	transposehistogram_metadatacreate_summary_metadatar   rA   r,   summary_descriptionr3   )r   histogram_valuenstartendbucketsinner_edgesbucket_leftsbucket_rightssummary_metadatar9   s             @r   r#   r#   S   s3    kkO#**MMA>U1X>BE
F8E!H-F
KCs{ ((Aq64 &ecAg6%225='++,{:#':':&;;((=-8



)+ 	 *AA^^00=EIINN66
 		#3W==r*   c                    | j                   }t        |j                        j                  d      t        |j                        j                  d      |j
                  g}t        j                  | j                  j                  xs | j                  | j                  j                  d      }t        | j                  ||      S )NasciiT)rA   rB   converted_to_tensor)r    strwidthencodeheightencoded_image_stringimage_metadatarP   r   rA   r,   rQ   r3   )r   image_valuer1   rZ   s       r   r$   r$   ~   s    ++KK%%g.K&&w/((D &==^^00=EIINN66 
 		#3T::r*   c                 >   | j                   }|j                  dgg}t        j                  | j                  j
                  xs | j                  | j                  j                  t        j                  j                  d      d      }t        | j                  ||      S )Nr*   WAVT)rA   rB   encodingr]   )r!   encoded_audio_stringaudio_metadatarP   r   rA   r,   rQ   Encodingr0   r3   )r   audio_valuer1   rZ   s       r   r%   r%      s    ++K--s34D%==^^00=EIINN66((..u5 	 		#3T::r*   c                     | j                   }t        j                  | j                  j                  xs | j
                  | j                  j                        }t        | j
                  ||      S )Nr@   )r"   scalar_metadatarP   r   rA   r,   rQ   r3   )r   scalar_valuerZ   s      r   r&   r&      sW    %%L&>>^^00=EIINN66 		#3\BBr*   )__doc__numpyrG   tensorboard.compat.protor   r   tensorboard.plugins.audior   ri   tensorboard.plugins.histogramrO   tensorboard.plugins.imagerc   tensorboard.plugins.scalarrm   tensorboard.utilr   r   r   r3   r#   r$   r%   r&   r
   r*   r   <module>rw      sJ    F  . 0 @ H @ B ("0<(>V; 	;Cr*   