
    &Vf                         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  G d	 d
ej                  ZdS )zThe TensorBoard Distributions (a.k.a. compressed histograms) plugin.

See `http_api.md` in this directory for specifications of the routes for
this plugin.
    )wrappers)plugin_util)	http_util)base_plugin)
compressor)metadata)histograms_pluginc                       e Zd ZdZej        ZdZd Zd Z	d Z
d Zd Zd Zd	 Zd
 Zej        j        d             Zej        j        d             ZdS )DistributionsPlugina  Distributions 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).
    i  c                 8    t          j        |          | _        dS )zInstantiates DistributionsPlugin via TensorBoard core.

        Args:
          context: A base_plugin.TBContext instance.
        N)r	   HistogramsPlugin_histograms_plugin)selfcontexts     r/var/www/html/software/conda/lib/python3.11/site-packages/tensorboard/plugins/distribution/distributions_plugin.py__init__zDistributionsPlugin.__init__/   s     #4"DW"M"M    c                      | j         | j        dS )N)z/distributionsz/tags)distributions_route
tags_router   s    r   get_plugin_appsz#DistributionsPlugin.get_plugin_apps7   s    "6_
 
 	
r   c                 4    | j                                         S )zThis plugin is active iff any run has at least one histogram tag.

        (The distributions plugin uses the same data source as the
        histogram plugin.)
        )r   	is_activer   s    r   r   zDistributionsPlugin.is_active=   s     &00222r   c                     | j         j        fS N)r   plugin_namer   s    r   data_plugin_namesz%DistributionsPlugin.data_plugin_namesE   s    '355r   c                 ,    t          j        d          S )Nztf-distribution-dashboard)element_name)r   FrontendMetadatar   s    r   frontend_metadataz%DistributionsPlugin.frontend_metadataH   s    +4
 
 
 	
r   c                 r      j                             |||| j                  \  }} fd|D             |fS )zResult of the form `(body, mime_type)`.

        Raises:
          tensorboard.errors.PublicError: On invalid request.
        )
experimentdownsample_toc                 :    g | ]}                     |          S  )	_compress).0	histogramr   s     r   
<listcomp>z:DistributionsPlugin.distributions_impl.<locals>.<listcomp>W   s%    CCC9T^^I&&CCCr   )r   histograms_implSAMPLE_SIZE)r   ctxtagrunr$   
histograms	mime_types   `      r   distributions_implz&DistributionsPlugin.distributions_implM   s]     #'"9"I"Icj@P #J #
 #
Y DCCC
CCC
 	
r   c                 @    |\  }}}t          j        |          }|||gS r   )r   compress_histogram)r   r*   	wall_timestepbucketsconverted_bucketss         r   r(   zDistributionsPlugin._compress[   s-    %."D'&9'BB4!233r   c                 :    | j                             ||          S )Nr$   )r   
index_impl)r   r.   r$   s      r   r<   zDistributionsPlugin.index_impl`   s    &11#*1MMMr   c                     t          j        |j                  }t          j        |j                  }|                     ||          }t          j        ||d          S )Nr;   zapplication/json)r   r   environexperiment_idr<   r   Respond)r   requestr.   r$   indexs        r   r   zDistributionsPlugin.tags_routec   sQ    !'/22 .w??

;; %1CDDDr   c                 2   t          j        |j                  }t          j        |j                  }|j                            d          }|j                            d          }|                     ||||          \  }}t          j        |||          S )zMGiven a tag and single run, return an array of compressed
        histograms.r/   r0   r;   )	r   r   r>   r?   argsgetr3   r   r@   )r   rA   r.   r$   r/   r0   bodyr2   s           r   r   z'DistributionsPlugin.distributions_routej   s     !'/22 .w??
lu%%lu%% 33cj 4 
 
y  $	:::r   N)__name__
__module____qualname____doc__r   PLUGIN_NAMEr   r-   r   r   r   r   r"   r3   r(   r<   r   Requestapplicationr   r   r'   r   r   r   r       s          &K KN N N
 
 
3 3 36 6 6
 
 


 
 
4 4 4
N N N !E E "!E !
; 
; "!
; 
; 
;r   r   N)rJ   werkzeugr   tensorboardr   tensorboard.backendr   tensorboard.pluginsr    tensorboard.plugins.distributionr   r   tensorboard.plugins.histogramr	   TBPluginr   r'   r   r   <module>rU      s           # # # # # # ) ) ) ) ) ) + + + + + + 7 7 7 7 7 7 5 5 5 5 5 5 ; ; ; ; ; ;U; U; U; U; U;+. U; U; U; U; U;r   