code: def _overlap(
      bucket: statistics_pb2.Histogram.Bucket,
      low_bound: float,
      high_bound: float,
      first_bucket: bool,
  ) -> Tuple[float, bool, bool]:
      """Computes overlap fraction between a histogram bucket and an interval.
  
      Args:
        bucket: a histogram bucket. The low_value and high_value may be negative or
          positive inf respectively.
        low_bound: A finite lower bound of a probe interval.
        high_bound: A finite upper bound of a probe interval.
        first_bucket: Indicates if this is the first interval, which may contain a
          point bucket on its left edge.
  
      Returns:
        A tuple consisting of the following elements:
        1) The fraction of bucket's sample count falling into a probe
        interval. Samples are assumed to be uniformly distributed within a bucket.
        Buckets with infinite bounds are treated as having full overlap with any
        intervals they overlap with.
        2) A boolean indicating whether the bucket completely precedes the probe
        interval.
        3) A boolean indicating whether the bucket completely follows the probe
        interval.
      """
      # Case 0, the bucket is a point, and is equal to an interval edge.
      # If this is the first bucket, we treat it as overlapping if it falls on the
      # left boundary.
      if (
          first_bucket
          and bucket.high_value == bucket.low_value == low_bound
      ):
          return 1.0, False, False
      # Otherwise we treat it as not overlapping.
      if (
          not first_bucket
          and bucket.high_value == bucket.low_value == low_bound
      ):
          return 0.0, True, False
      # Case 1, the bucket entirely precedes the interval.
      #            |bucket|
      #                       |   |
      if bucket.high_value < low_bound:
          return 0.0, True, False
      # Case 2, the bucket entirely follows the interval.
      #            |bucket|
      #      |   |
      if bucket.low_value > high_bound:
          return 0.0, False, True
      # Case 3: bucket is contained.
      #            |bucket|
      #        |              |
      if (
          low_bound <= bucket.low_value
          and high_bound >= bucket.high_value
      ):
          return 1.0, False, False
      # Case 4: interval overlaps bucket on the left.
      #            |bucket|
      #        |     |
      if low_bound <= bucket.low_value:
          return (
              (high_bound - bucket.low_value)
              / (bucket.high_value - bucket.low_value),
              False,
              False,
          )
      # Case 5: interval overlaps bucket on the right.
      #            |bucket|
      #               |     |
      if high_bound >= bucket.high_value:
          return (
              (bucket.high_value - low_bound)
              / (bucket.high_value - bucket.low_value),
              False,
              False,
          )
      # Case 6: interval falls inside of the bucket.
      #            |bucket|
      #               | |
      if (
          low_bound > bucket.low_value
          and high_bound < bucket.high_value
      ):
          return (
              (high_bound - low_bound)
              / (bucket.high_value - bucket.low_value),
              False,
              False,
          )
      raise ValueError(
          "Unable to compute overlap between (%f, %f) and %s"
          % (low_bound, high_bound, bucket)
      )
  
file_path: data-validation/tensorflow_data_validation/utils/quantiles_util.py
imports: from typing import Tuple
  import numpy
  from tensorflow_metadata.proto.v0 import statistics_pb2
label_desc: Use image node_id 6 for calling a global function with example usage: _overlap(bucket, low_bound, high_bound, first_bucket) and returns: int,  False,  False, int,  True,  False, int,  True,  False, int,  False,  True, int,  False,  False, unknown,  False,  False, unknown,  False,  False, unknown,  False,  False