
    &VfM                         d Z ddlZddlZddlmZ dZ ej        d           G d d                      Zefd	Z	efd
Z
d ZdS )z"Package for histogram compression.    N)Tuple)	r   i  i3  i  i  i  i   it$  i'  T)frozenc                   D    e Zd ZU dZeed<   eed<   deeef         fdZdS )CompressedHistogramValuezRepresents a value in a compressed histogram.

    Attributes:
      basis_point: Compression point represented in basis point, 1/100th of a
        percent.
      value: Cumulative weight at the basis point.
    basis_pointvaluereturnc                     | j         | j        fS )z1Returns the basis point and the value as a tuple.)r   r   )selfs    h/var/www/html/software/conda/lib/python3.11/site-packages/tensorboard/plugins/distribution/compressor.pyas_tuplez!CompressedHistogramValue.as_tuple*   s     $*--    N)__name__
__module____qualname____doc__float__annotations__r   r    r   r   r   r      s[           LLL.%u- . . . . . .r   r   c                 
   | j         sd |D             S t          j        | j                  }t	          | j                  }||d         z  |                                pdz                                  }g }d}|t          |          k     rt          j	        |||         d          }|t          |          k     r||         }|dk    r||dz
           nd}	||	k    r|dz  }:|r|	s| j
        }
nt          ||dz
           | j
                  }
t          ||         | j                  }t          ||         |	||
|          }|                    t          ||         |                                                     |dz  }nn|t          |          k     |t          |          k     rX|                    t          ||         | j                                                             |dz  }|t          |          k     X|S )	a  Creates fixed size histogram by adding compression to accumulated state.

    This routine transforms a histogram at a particular step by interpolating its
    variable number of buckets to represent their cumulative weight at a constant
    number of compression points. This significantly reduces the size of the
    histogram and makes it suitable for a two-dimensional area plot where the
    output of this routine constitutes the ranges for a single x coordinate.

    Args:
      histo: A HistogramProto object.
      bps: Compression points represented in basis points, 1/100ths of a percent.
          Defaults to normal distribution.

    Returns:
      List of values for each basis point.
    c                 R    g | ]$}t          |d                                           %S         r   r   .0bs     r   
<listcomp>z,compress_histogram_proto.<locals>.<listcomp>C   /    III(C0099;;IIIr         ?r   rightside   r   )numnparraybucketlistbucket_limitsumcumsumlensearchsortedminmax_lerpappendr   r   )histobpsr)   r+   weightsvaluesjir-   cumsum_prevlhsrhsweights                r   compress_histogram_protor>   0   s   $ 9 JIISIIIIXel##F*++LB6::<<#637??AAGF	A
c#hh,,OGSV':::#g,,QZF,-EE'!a%..sK$$Q :K :i,q1u-uy99l1ouy11C3q6;SAAFMM23q66BBKKMMNNNFA% c#hh,,& c#hh,,.s1vuyAAJJLLMMM	Q c#hh,, Mr   c                 .   t          j        |           } | j        sd |D             S | d         d         | d         d         }}| dddf         }t          | dddf                   }||d         z  |                                pdz                                  }g }d}|t          |          k     rt          j        |||         d	          }	|	t          |          k     r||	         }
|	dk    r||	dz
           nd
}|
|k    r|	dz  }	:|	r|s|}nt          ||	dz
           |          }t          ||	         |          }t          ||         ||
||          }|                    t          ||         |                                                     |dz  }nn|t          |          k     |t          |          k     rS|                    t          ||         |                                                     |dz  }|t          |          k     S|S )a  Creates fixed size histogram by adding compression to accumulated state.

    This routine transforms a histogram at a particular step by linearly
    interpolating its variable number of buckets to represent their cumulative
    weight at a constant number of compression points. This significantly reduces
    the size of the histogram and makes it suitable for a two-dimensional area
    plot where the output of this routine constitutes the ranges for a single x
    coordinate.

    Args:
      buckets: A list of buckets, each of which is a 3-tuple of the form
        `(min, max, count)`.
      bps: Compression points represented in basis points, 1/100ths of a percent.
          Defaults to normal distribution.

    Returns:
      List of values for each basis point.
    c                 R    g | ]$}t          |d                                           %S r   r   r   s     r   r   z&compress_histogram.<locals>.<listcomp>x   r   r   r   r    r%   N   r!   r"   r#   r   )r'   r(   sizer*   r,   r-   r.   r/   r1   r0   r2   r3   r   r   )bucketsr5   minminmaxmaxcountsright_edgesr6   resultbp_indexr9   r-   r:   r;   r<   r=   s                  r   compress_histogramrJ   b   s<   ( hwG< JIISIIII
1wr{1~VVQQQT]Fwqqq!t}%%KB6::<<#637??AAGFH
SXX

OGS]AAA#g,,QZF,-EE'!a%..sK$$Q 6K 6+a!e,f55k!nf--C3x=+vsCHHFMM(X??HHJJ   MH) SXX

* SXX

$S]F;;DDFF	
 	
 	
 	A	 SXX


 Mr   c                 D    || |z
  t          ||z
            z  ||z
  z  z   S )z)Affinely map from [x0, x1] onto [y0, y1].)r   )xx0x1y0y1s        r   r2   r2      s)    R5b>>)R"W555r   )r   dataclassesnumpyr'   typingr   NORMAL_HISTOGRAM_BPS	dataclassr   r>   rJ   r2   r   r   r   <module>rV      s    ) (              
 K  d###. . . . . . . $#.$ )= / / / /d %9 8 8 8 8v6 6 6 6 6r   