code: def generate_equal_width_histogram(
      quantiles, num_buckets: int, total_freq: float
  ) -> Histogram:
      """Generates the equal width histogram from the input quantiles and total frequency. The
      quantiles are assumed to be ordered and corresponding to equal distant percentiles.
  
      :param quantiles: the quantiles that capture the frequency distribution.
      :param num_buckets: the number of buckets in the generated histogram.
      :param total_freq: the total frequency (=count of rows).
      :return: equal width histogram or None if inputs are invalid.
      """
      if len(quantiles) < 2 or num_buckets <= 0 or total_freq <= 0:
          return None
  
      min_val = quantiles[0]
      max_val = quantiles[-1]
  
      # If all values are the same, the width of all buckets will be 1 as fixed,
      # except the bucket that contains the real value. The width of that will be 0.
      histogram = Histogram()
      histogram.type = Histogram.HistogramType.STANDARD
      if min_val == max_val:
          half_buckets = num_buckets // 2
          bucket_left = min_val - half_buckets
          for i in range(num_buckets):
              if i == half_buckets:
                  histogram.buckets.append(
                      Histogram.Bucket(
                          low_value=bucket_left,
                          high_value=bucket_left,
                          sample_count=total_freq,
                      )
                  )
              else:
                  histogram.buckets.append(
                      Histogram.Bucket(
                          low_value=bucket_left,
                          high_value=bucket_left + 1,
                          sample_count=0,
                      )
                  )
                  bucket_left += 1
      else:
          bucket_width = (max_val - min_val) / num_buckets
          for i in range(num_buckets):
              bucket_left = min_val + i * bucket_width
              bucket_right = bucket_left + bucket_width
              histogram.buckets.append(
                  _generate_equal_width_histogram_internal(
                      bucket_left=bucket_left,
                      bucket_right=bucket_right,
                      quantiles=quantiles,
                      total_freq=total_freq,
                  )
              )
  
      return histogram
  
imports: from mlflow.protos.facet_feature_statistics_pb2 import Histogram
label_desc: Use image node_id 2 for calling a global function with example usage: generate_equal_width_histogram(quantiles, num_buckets, total_freq) and returns: histogram, None