code: def testRebin(self):
      # [Bucket(0, -1, -0.01), Bucket(1, 0, 0) ... Bucket(101, 101, 1.01)]
      histogram = [calibration_histogram.Bucket(0, -1, -0.01, 1.0)]
      for i in range(100):
          histogram.append(
              calibration_histogram.Bucket(i + 1, i, i * 0.01, 1.0)
          )
      histogram.append(
          calibration_histogram.Bucket(101, 101, 1.01, 1.0)
      )
      # [-1e-7, 0.0, 0.1, ..., 0.9, 1.0, 1.0+1e-7]
      thresholds = (
          [-1e-7] + [i * 1.0 / 10 for i in range(11)] + [1.0 + 1e-7]
      )
      got = calibration_histogram.rebin(thresholds, histogram, 100)
  
      # labels = (10 * (i-1)) + (1 + 2 + 3 + ... + 9)
      expected = [
          calibration_histogram.Bucket(0, -1, -0.01, 1.0),
          calibration_histogram.Bucket(1, 45.0, 0.45, 10.0),
          calibration_histogram.Bucket(2, 145.0, 1.45, 10.0),
          calibration_histogram.Bucket(3, 245.0, 2.45, 10.0),
          calibration_histogram.Bucket(4, 345.0, 3.45, 10.0),
          calibration_histogram.Bucket(5, 445.0, 4.45, 10.0),
          calibration_histogram.Bucket(6, 545.0, 5.45, 10.0),
          calibration_histogram.Bucket(7, 645.0, 6.45, 10.0),
          calibration_histogram.Bucket(8, 745.0, 7.45, 10.0),
          calibration_histogram.Bucket(9, 845.0, 8.45, 10.0),
          calibration_histogram.Bucket(10, 945.0, 9.45, 10.0),
          calibration_histogram.Bucket(11, 0.0, 0.0, 0.0),
          calibration_histogram.Bucket(12, 101.0, 1.01, 1.0),
      ]
      self.assertLen(got, len(expected))
      for i in range(len(got)):
          self.assertSequenceAlmostEqual(
              dataclasses.astuple(got[i]),
              dataclasses.astuple(expected[i]),
          )
  
file_path: model-analysis/tensorflow_model_analysis/metrics/calibration_histogram_test.py
imports: import dataclasses
  import apache_beam
  from apache_beam.testing import util
  import numpy
  import tensorflow
  from tensorflow_model_analysis.eval_saved_model import testutil
  from tensorflow_model_analysis.metrics import calibration_histogram
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
label_desc: Use image node_id 4 for calling the CalibrationHistogramTest obj's underlying member method code with example usage: obj.testRebin() without return types