Ë
    1ÆVhM  ã                   ó‚   — 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y)z"Package for histogram compression.é    N)ÚTuple)	r   iœ  i3  i  iˆ  i  iÝ   it$  i'  T)Úfrozenc                   ó<   — e Zd ZU dZeed<   eed<   deeef   fd„Zy)ÚCompressedHistogramValuezÕRepresents 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                 ó2   — | j                   | j                  fS )z1Returns the basis point and the value as a tuple.)r   r   )Úselfs    ú[/home/dcms/DCMS/lib/python3.12/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)   … ñð ÓØƒLð.˜%  u Ñ-ô .r   r   c                 óÎ  — | j                   s(|D cg c]  }t        |d«      j                  «       ‘Œ c}S t        j                  | j
                  «      }t        | j                  «      }||d   z  |j                  «       xs dz  j                  «       }g }d}|t        |«      k  rât        j                  |||   d¬«      }|t        |«      k  r©||   }	|dkD  r||dz
     nd}
|	|
k(  r|dz  }Œ-|r|
s| j                  }nt        ||dz
     | j                  «      }t        ||   | j                  «      }t        ||   |
|	||«      }|j                  t        ||   |«      j                  «       «       |dz  }nn|t        |«      k  rŒâ|t        |«      k  rJ|j                  t        ||   | j                  «      j                  «       «       |dz  }|t        |«      k  rŒJ|S c c}w )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.
    ç        éÿÿÿÿç      ð?r   Úright©Úsideé   )Únumr   r   ÚnpÚarrayÚbucketÚlistÚbucket_limitÚsumÚcumsumÚlenÚsearchsortedÚminÚmaxÚ_lerpÚappend)ÚhistoÚbpsÚbr!   r#   ÚweightsÚvaluesÚjÚir%   Úcumsum_prevÚlhsÚrhsÚweights                 r   Úcompress_histogram_protor7   0   sÂ  € ð$ 9Š9ØEHÖIÀÔ(¨¨CÓ0×9Ñ9Õ;ÒIÐIÜX‰Xe—l‘lÓ#€FÜ˜×*Ñ*Ó+€LØ˜˜B™Ñ 6§:¡:£<Ò#6°3Ñ7×?Ñ?ÓA€GØ€FØ	€AØ
Œc#‹hŠ,ÜO‰O˜G S¨¡V°'Ô:ˆØ”#g“,ÒØ˜Q‘ZˆFØ,-°ªE˜' ! a¡%š.°sˆKØ˜Ò$ØQ‘ØÙ™KØ—i‘i‘ä˜, q¨1¡uÑ-¨u¯y©yÓ9Ül 1‘o u§y¡yÓ1ˆCÜ˜3˜q™6 ;°¸¸SÓAˆFØM‰MÔ2°3°q±6¸6ÓB×KÑKÓMÔNØ‰FˆAØàð% Œc#‹h‹,ð& Œc#‹hŠ,Ø‰Ô.¨s°1©v°u·y±yÓA×JÑJÓLÔMØ	ˆQ‰ˆð Œc#‹h‹,ð €Mùò9 Js   ‘!G"c                 ó–  — t        j                  | «      } | j                  s(|D cg c]  }t        |d«      j	                  «       ‘Œ c}S | d   d   | d   d   }}| dd…df   }t        | dd…df   «      }||d   z  |j                  «       xs dz  j                  «       }g }d}	|	t        |«      k  rÄt        j                  |||	   d¬	«      }
|
t        |«      k  r‹||
   }|
dkD  r||
dz
     nd}||k(  r|
dz  }
Œ-|
r|s|}nt        ||
dz
     |«      }t        ||
   |«      }t        ||	   ||||«      }|j                  t        ||	   |«      j	                  «       «       |	dz  }	nn|	t        |«      k  rŒÄ|	t        |«      k  r@|j                  t        ||	   |«      j	                  «       «       |	dz  }	|	t        |«      k  rŒ@|S c c}w )
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.
    r   r   r   r   Né   r   r   r   )r   r    Úsizer   r   r"   r$   r%   r&   r'   r)   r(   r*   r+   )Úbucketsr-   r.   ÚminminÚmaxmaxÚcountsÚright_edgesr/   ÚresultÚbp_indexr2   r%   r3   r4   r5   r6   s                   r   Úcompress_histogramrB   b   sã  € ô( h‰hwÓ€GØ<Š<ØEHÖIÀÔ(¨¨CÓ0×9Ñ9Õ;ÒIÐIØ ™
 1™ w¨r¡{°1¡~ˆV€VØ’Q˜T‰]€FÜwšq !˜t‘}Ó%€KØ˜˜B™Ñ 6§:¡:£<Ò#6°3Ñ7×?Ñ?ÓA€Gà€FØ€HØ
”S˜“XÒ
ÜO‰O˜G S¨¡]¸ÔAˆØ”#g“,ÒØ˜Q‘ZˆFØ,-°ªE˜' ! a¡%š.°sˆKØ˜Ò$ØQ‘ØÙ™KØ‘ä˜+ a¨!¡eÑ,¨fÓ5Ük !‘n fÓ-ˆCÜ˜3˜x™=¨+°v¸sÀCÓHˆFØM‰MÜ(¨¨X©¸Ó?×HÑHÓJôð ˜‰MˆHØàð) ”S˜“XÓ
ð* ”S˜“XÒ
Ø‰Ü$ S¨¡]°FÓ;×DÑDÓFô	
ð 	A‰ˆð	 ”S˜“XÓ
ð
 €MùòE Js   ¦!Gc                 ó<   — || |z
  t        ||z
  «      z  ||z
  z  z   S )z)Affinely map from [x0, x1] onto [y0, y1].)r   )ÚxÚx0Úx1Úy0Úy1s        r   r*   r*      s'   € àR‘œ5  b¡›>Ñ)¨R°"©WÑ5Ñ5Ð5r   )r   ÚdataclassesÚnumpyr   Útypingr   ÚNORMAL_HISTOGRAM_BPSÚ	dataclassr   r7   rB   r*   r   r   r   ú<module>rN      s_   ðñ )ó Û å ð
 KÐ ð €×Ñ˜dÔ#÷.ð .ó $ð.ð$ )=ó /ðd %9ó 8óv6r   