code: def _search_for_label_edge_timestamp(
      class_label_name: str,
      track_rectangles: List[Dict[str, Any]],
      cur_idx: int,
      step: int,
      interpolation_cutoff_threshold_sec: Optional[float] = None,
  ) -> float:
      """Find the timestamp of the furthest invisible annotation that has the same label
      with `class_label_name`.
  
      Args:
          class_label_name: The string name of the target class's annotation to search.
          track_rectangles: The annotation of an identity across time.
          cur_idx: The index of the annotation in `track_rectangles` to start searching.
          step: The step to search for the timetamp. A positive step indicates the
              timstamp should be after `cur_idx`'s; while a negative step indicates the
              timestamp should be before `cur_idx`'s.
          interpolation_cutoff_threshold_sec: The threshold of timestamp difference where
              the label value changes.
  
      Returns:
          The edge timestamp.
      """
      label = track_rectangles[cur_idx][class_label_name]
  
      def in_bounds(idx: int) -> bool:
          return 0 <= idx < len(track_rectangles)
  
      while True:
          cur_idx += step
          if not in_bounds(cur_idx):
              # If the original video clips were split into smaller clips before running
              # this pipeline (which occurs with some datasets), then there is a chance
              # that this annotation was split into two separate clips. However, since the
              # label is at the edge of the clip, we don't know if it was split, or if the
              # label just coinciedentally starts/ends at this edge of the video.
              logger.warning(
                  "Annotation is potentially split across video clips. This "
                  "makes the 'progress' calculation inherently unreliable."
              )
              break
          cur_rectangle = track_rectangles[cur_idx]
          if (
              cur_rectangle[class_label_name] != label
              or not cur_rectangle["is_visible"]
          ):
              break
  
      outside_idx = cur_idx  # First encountered outside label idx.
      inside_idx = cur_idx - step  # Last known 'inside' label idx.
      inside_timestamp = track_rectangles[inside_idx]["timestamp"]
  
      if in_bounds(outside_idx):
          # Since we know that the label at `outside_idx` is valid, but different than the
          # relevant action, we can interpolate halfway between (of course, only if the
          # labels are within the threshold).
          outside_timestamp = track_rectangles[outside_idx]["timestamp"]
  
          if step > 0 and (
              interpolation_cutoff_threshold_sec is None
              or (
                  abs(inside_timestamp - outside_timestamp)
                  < interpolation_cutoff_threshold_sec
              )
          ):
              # In this case, `outside_idx` is at the first timestamp which has a
              # differing label. Since we use the "floor" convention for computing the
              # label, `outside_timestamp` is our upper bound.
              return outside_timestamp
  
      return inside_timestamp
  
file_path: ml-cvnets/data/datasets/utils/video.py
imports: import functools
  from typing import Any, Collection, Dict, List, Optional, Tuple
  import numpy
  from utils import logger
label_desc: Use image node_id 7 for calling a global function with example usage: _search_for_label_edge_timestamp(class_label_name, track_rectangles, cur_idx, step, interpolation_cutoff_threshold_sec) and returns: inside_timestamp, unknown, outside_timestamp