a
    Sic8$                     @   sR   d Z ddlZddlmZ ddlmZ ejZejZdddZdddZ	dd	d
Z
dS )a  Histogram summaries and TensorFlow operations to create them.

A histogram summary stores a list of buckets. Each bucket is encoded as
a triple `[left_edge, right_edge, count]`. Thus, a full histogram is
encoded as a tensor of dimension `[k, 3]`.

In general, the value of `k` (the number of buckets) will be a constant,
like 30. There are two edge cases: if there is no data, then there are
no buckets (the shape is `[0, 3]`); and if there is data but all points
have the same value, then there is one bucket whose left and right
endpoints are the same (the shape is `[1, 3]`).

NOTE: This module is in beta, and its API is subject to change, but the
data that it stores to disk will be supported forever.
    N)metadata)
summary_v2c              	      s   ddl m  m  du r tj jd gd   j	gz j
dgdjjdd}fdd	} fd
d}|||W  d   W  d   S 1 s0    Y  W d   n1 s0    Y  dS )a  Create a TensorFlow op to group data into histogram buckets.

    Arguments:
      data: A `Tensor` of any shape. Must be castable to `float64`.
      bucket_count: Optional positive `int` or scalar `int32` `Tensor`.
    Returns:
      A `Tensor` of shape `[k, 3]` and type `float64`. The `i`th row is
      a triple `[left_edge, right_edge, count]` for a single bucket.
      The value of `k` is either `bucket_count` or `1` or `0`.
    r   Nbuckets)values)shapeinputc                      s    j g d jdS )Nr      )r   dtype)constantfloat64 )tfr   a/var/www/html/django/DPS/env/lib/python3.9/site-packages/tensorboard/plugins/histogram/summary.py
when_emptyD   s    z_buckets.<locals>.when_emptyc                     s`   j djd   d}  fdd}fdd}| ||S )N)input_tensorr   c            	         s     j }  }j ||  jd}| d }j| jd}j j|ddjd} d }|d d }|dd  }j	|||gdS )Nr      )depthr   r   )r   axisr   a)
castr   floorint32minimumone_hot
reduce_sumlinspace	transposestack)	bucket_widthoffsetsbucket_indicesclamped_indicesone_hotsbucket_countsedges
left_edgesright_edges)bucket_countdatamax_min_range_r   r   r   when_nonsingularM   s&    z9_buckets.<locals>.when_nonempty.<locals>.when_nonsingularc                     sZ   }  | d g} | d g} j djg}j |||gdS )N      ?r   r   )r"   r   sizer   r!   )centerZbucket_startsZbucket_endsr(   )r-   r/   r   r   r   when_singulare   s    z6_buckets.<locals>.when_nonempty.<locals>.when_singular)
reduce_min
reduce_maxequalcond)is_singularr1   r5   r,   r-   r   )r.   r/   r0   r   when_nonemptyG   s    z_buckets.<locals>.when_nonempty)tensorflow.compat.v1compatv1r   DEFAULT_BUCKET_COUNT
name_scopecontrol_dependenciesassert_scalarassert_typer   reshaper   r   r8   r3   r9   )r-   r,   is_emptyr   r<   r   r;   r   _buckets+   s     +rG   c           	      C   sz   ddl m  m} |du r| }tj||d}|| 0 t||d}|jjd|||dW  d   S 1 sl0    Y  dS )a  Create a legacy histogram summary op.

    Arguments:
      name: A unique name for the generated summary node.
      data: A `Tensor` of any shape. Must be castable to `float64`.
      bucket_count: Optional positive `int`. The output will have this
        many buckets, except in two edge cases. If there is no data, then
        there are no buckets. If there is data but all points have the
        same value, then there is one bucket whose left and right
        endpoints are the same.
      display_name: Optional name for this summary in TensorBoard, as a
        constant `str`. Defaults to `name`.
      description: Optional long-form description for this summary, as a
        constant `str`. Markdown is supported. Defaults to empty.
      collections: Optional list of graph collections keys. The new
        summary op is added to these collections. Defaults to
        `[Graph Keys.SUMMARIES]`.

    Returns:
      A TensorFlow summary op.
    r   Ndisplay_namedescription)r,   histogram_summary)nametensorcollectionssummary_metadata)	r=   r>   r?   r   create_summary_metadatarA   rG   summarytensor_summary)	rL   r-   r,   rI   rJ   rN   r   rO   rM   r   r   r   opu   s    rS   c                 C   s  ddl m  m} |du r tj}t| t	}|j
dkrRtg d}nt|}t|}|| }	|	dkr|}
t|
d |
d t	|j
gg}n|	| }|| }t|| t}t||d }t|g td|k}|j|j
|fksJ |j|j
|fftj|dd}t|||d }|dd }|dd }t|||g }|j||jd}|du r|| }tj||d	}|j| }| }|jjd
|  ||d |S )aa  Create a legacy histogram summary protobuf.

    Arguments:
      name: A unique name for the generated summary, including any desired
        name scopes.
      data: A `np.array` or array-like form of any shape. Must have type
        castable to `float`.
      bucket_count: Optional positive `int`. The output will have this
        many buckets, except in two edge cases. If there is no data, then
        there are no buckets. If there is data but all points have the
        same value, then there is one bucket whose left and right
        endpoints are the same.
      display_name: Optional name for this summary in TensorBoard, as a
        `str`. Defaults to `name`.
      description: Optional long-form description for this summary, as a
        `str`. Markdown is supported. Defaults to empty.

    Returns:
      A `tf.Summary` protobuf object.
    r   Nr
   r2   r   )r   r   r   rH   z%s/histogram_summary)tagr   rM   ) r=   r>   r?   r   r@   nparrayflattenastypefloatr3   rE   minmaxr   intr   r!   aranger   sumr    make_tensor_protor   r   rP   SummaryMetadata
FromStringSerializeToStringSummaryvalueadd)rL   r-   r,   rI   rJ   r   r   r/   r.   r0   r4   r#   r$   r%   r&   r'   r(   r)   r*   r+   rM   rO   tf_summary_metadatarQ   r   r   r   pb   s\    


"
rg   )N)NNNN)NNN)__doc__numpyrU   tensorboard.plugins.histogramr   r   	histogramhistogram_pbrG   rS   rg   r   r   r   r   <module>   s   
M    
/