
    &Vfj                         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	Z G d
 dej                  ZdS )zzThe TensorBoard Histograms plugin.

See `http_api.md` in this directory for specifications of the routes for
this plugin.
    )wrappers)errors)plugin_util)	http_util)provider)base_plugin)metadatai  c                       e Zd ZdZej        ZdZd Zd Z	d Z
d Zd Zdd	Zej        j        d
             Zej        j        d             ZdS )HistogramsPlugina  Histograms Plugin for TensorBoard.

    This supports both old-style summaries (created with TensorFlow ops
    that output directly to the `histo` field of the proto) and new-
    style summaries (as created by the
    `tensorboard.plugins.histogram.summary` module).
    3   c                     |j         pi                     | j        t                    | _        |j        | _        t          j        dd          | _	        dS )zInstantiates HistogramsPlugin via TensorBoard core.

        Args:
          context: A base_plugin.TBContext instance.
        	histogramr   )	data_kindlatest_known_versionN)
sampling_hintsgetplugin_name_DEFAULT_DOWNSAMPLING_downsample_todata_provider_data_providerr   _MetadataVersionChecker_version_checker)selfcontexts     l/var/www/html/software/conda/lib/python3.11/site-packages/tensorboard/plugins/histogram/histograms_plugin.py__init__zHistogramsPlugin.__init__2   s`      '5;@@3
 
 &3 + C!!"!
 !
 !
    c                      | j         | j        dS )N)z/histogramsz/tags)histograms_route
tags_router   s    r   get_plugin_appsz HistogramsPlugin.get_plugin_appsA   s    0_
 
 	
r   c                     dS )NF r"   s    r   	is_activezHistogramsPlugin.is_activeG   s    ur   c                    | j                             ||t          j                  }d |D             }|                                D ]\  }}|                                D ]l\  }}t          j        |j                  }	t          j        |j	                  }
| j
                            |
j        ||          sY|j        |	d||         |<   m|S )zJReturn {runName: {tagName: {displayName: ..., description:
        ...}}}.)experiment_idr   c                     i | ]}|i S r%   r%   ).0runs     r   
<dictcomp>z/HistogramsPlugin.index_impl.<locals>.<dictcomp>R   s    ---c#r---r   )displayNamedescription)r   list_tensorsr	   PLUGIN_NAMEitemsr   markdown_to_safe_htmlr.   parse_plugin_metadataplugin_contentr   okversiondisplay_name)r   ctx
experimentmappingresultr+   tag_to_contenttag	metadatumr.   mds              r   
index_implzHistogramsPlugin.index_implJ   s     %22$ , 3 
 

 .-W---%,]]__ 	 	!S.$2$8$8$:$: 
 
 i)?)  3I4LMM,//
CEE #,#9#.$ $sC  
 r   c                 ,    t          j        d          S )Nztf-histogram-dashboard)element_name)r   FrontendMetadatar"   s    r   frontend_metadataz"HistogramsPlugin.frontend_metadataa   s    +1
 
 
 	
r   Nc           
      B   ||n| j         }| j                            ||t          j        |t          j        |g|g                    }|                    |i                               |d          }|t          j	        d|d|          d |D             }	|	dfS )a  Result of the form `(body, mime_type)`.

        At most `downsample_to` events will be returned. If this value is
        `None`, then default downsampling will be performed.

        Raises:
          tensorboard.errors.PublicError: On invalid request.
        N)runstags)r(   r   
downsamplerun_tag_filterzNo histogram tag z	 for run c                 Z    g | ](}|j         |j        |j                                        f)S r%   )	wall_timestepnumpytolist)r*   es     r   
<listcomp>z4HistogramsPlugin.histograms_impl.<locals>.<listcomp>~   s/    NNNa1;(8(89NNNr   application/json)
r   r   read_tensorsr	   r0   r   RunTagFilterr   r   NotFoundError)
r   r8   r=   r+   r9   downsample_tosample_countall_histograms
histogramseventss
             r   histograms_implz HistogramsPlugin.histograms_implf   s     +6MMD<O 	 ,99$ ,##0se3%HHH : 
 
 $''R0044S$??
&&47CC=   ON:NNN*++r   c                     t          j        |j                  }t          j        |j                  }|                     ||          }t          j        ||d          S )N)r9   rQ   )r   r   environr(   r@   r   Respond)r   requestr8   r9   indexs        r   r!   zHistogramsPlugin.tags_route   sQ    !'/22 .w??

;; %1CDDDr   c                 >   t          j        |j                  }t          j        |j                  }|j                            d          }|j                            d          }|                     ||||| j                  \  }}t          j	        |||          S )z=Given a tag and single run, return array of histogram values.r=   r+   )r9   rU   )
r   r   r\   r(   argsr   rZ   SAMPLE_SIZEr   r]   )r   r^   r8   r9   r=   r+   body	mime_types           r   r    z!HistogramsPlugin.histograms_route   s     !'/22 .w??
lu%%lu%% 00cj@P 1 
 
y  $	:::r   )N)__name__
__module____qualname____doc__r	   r0   r   rb   r   r#   r&   r@   rD   rZ   r   Requestapplicationr!   r    r%   r   r   r   r   #   s          &K K
 
 

 
 
    .
 
 

, , , ,6 !E E "!E !	; 	; "!	; 	; 	;r   r   N)rh   werkzeugr   tensorboardr   r   tensorboard.backendr   tensorboard.datar   tensorboard.pluginsr   tensorboard.plugins.histogramr	   r   TBPluginr   r%   r   r   <module>rr      s                 # # # # # # ) ) ) ) ) ) % % % % % % + + + + + + 2 2 2 2 2 2  o; o; o; o; o;{+ o; o; o; o; o;r   