class_docstr: Represents a histogram over numbers.
  
  Attributes:
      name: unique name of the histogram which represents the histogram type.
      bins: histogram bins.
      lower: lower bound of the whole histogram, always included and always
        equals to 1 for integer histograms, None if there are no bins in the
        histogram.
      upper: upper bound of the whole histogram, there is no upper for integer
        histograms (i.e. +inf) and for floating histograms upper exists and is
        always included, None if there are no bins in the histogram.
class_docstr_tok: ["Represents","a","histogram","over","numbers",".","Attributes",":","name",":","unique","name","of","the","histogram","which","represents","the","histogram","type",".","bins",":","histogram","bins",".","lower",":","lower","bound","of","the","whole","histogram",",","always","included","and","always","equals","to","1","for","integer","histograms",",","None","if","there","are","no","bins","in","the","histogram",".","upper",":","upper","bound","of","the","whole","histogram",",","there","is","no","upper","for","integer","histograms","(","i.e",".","+inf",")","and","for","floating","histograms","upper","exists","and","is","always","included",",","None","if","there","are","no","bins","in","the","histogram","."]
docstr: Computes approximate quantiles over datasets.
  
  The output quantiles are chosen only from lower bounds of bins in
  this histogram. For each target quantile q it returns the lower bound of
  the first bin, such that all bins from the left contain not more than
  q part of the data.
  E.g. for quantile 0.8, the returned value is bin.lower for the first
  bin such that the ratio of data in bins to left from 'bin' is <= 0.8.
  
  Args:
      q: a list of quantiles to compute. It must be sorted in ascending
      order.
  
  Returns:
      A list of computed quantiles in the same order as in q.
docstr_tok: ["Computes","approximate","quantiles","over","datasets",".","The","output","quantiles","are","chosen","only","from","lower","bounds","of","bins","in","this","histogram",".","For","each","target","quantile","q","it","returns","the","lower","bound","of","the","first","bin",",","such","that","all","bins","from","the","left","contain","not","more","than","q","part","of","the","data",".","E.g",".","for","quantile","0.8",",","the","returned","value","is","bin.lower","for","the","first","bin","such","that","the","ratio","of","data","in","bins","to","left","from","'bin","'","is","<","=","0.8",".","Args",":","q",":","a","list","of","quantiles","to","compute",".","It","must","be","sorted","in","ascending","order",".","Returns",":","A","list","of","computed","quantiles","in","the","same","order","as","in","q","."]
code: def quantiles(self, q: List[float]) -> List[int]:
      """Computes approximate quantiles over datasets.
  
      The output quantiles are chosen only from lower bounds of bins in
      this histogram. For each target quantile q it returns the lower bound of
      the first bin, such that all bins from the left contain not more than
      q part of the data.
      E.g. for quantile 0.8, the returned value is bin.lower for the first
      bin such that the ratio of data in bins to left from 'bin' is <= 0.8.
  
      Args:
          q: a list of quantiles to compute. It must be sorted in ascending
          order.
  
      Returns:
          A list of computed quantiles in the same order as in q.
      """
      assert sorted(q) == q, "Quantiles to compute must be sorted."
  
      result = []
      total_count_up_to_current_bin = count_smaller = self.total_count()
      if total_count_up_to_current_bin == 0:
          raise ValueError(
              "Cannot compute quantiles of an empty histogram"
          )
      i_q = len(q) - 1
      for bin in self.bins[::-1]:
          count_smaller -= bin.count
          ratio_smaller = count_smaller / total_count_up_to_current_bin
          while i_q >= 0 and q[i_q] >= ratio_smaller:
              result.append(bin.lower)
              i_q -= 1
      while i_q >= 0:
          result.append(bin[0].lower)
      return result[::-1]
  
file_path: pipelinedp/pipeline_dp/dataset_histograms/histograms.py
imports: from dataclasses import dataclass, field
  import enum
  from typing import List, Sequence, Tuple, Union
label_desc: Use image node_id 6 for calling the Histogram obj's underlying member method code with example usage: obj.quantiles(q) and returns: result