code: def _calculate_average_precision(
      recall_values: np.ndarray, precision_values: np.ndarray
  ) -> np.ndarray:
      """Computes the average precision (AP) for a set of recall and precision values. It takes arrays of recall and precision values as inputs."""
      recall_values = recall_values[np.newaxis, :]
      precision_values = precision_values[np.newaxis, :]
      num_scales = recall_values.shape[0]
      average_precision = np.zeros(num_scales, dtype=np.float32)
      zeros_matrix = np.zeros(
          (num_scales, 1), dtype=recall_values.dtype
      )
      ones_matrix = np.ones((num_scales, 1), dtype=recall_values.dtype)
      modified_recall = np.hstack(
          (zeros_matrix, recall_values, ones_matrix)
      )
      modified_precision = np.hstack(
          (zeros_matrix, precision_values, zeros_matrix)
      )
  
      for i in range(modified_precision.shape[1] - 1, 0, -1):
          modified_precision[:, i - 1] = np.maximum(
              modified_precision[:, i - 1], modified_precision[:, i]
          )
  
      for i in range(num_scales):
          index = np.where(
              modified_recall[i, 1:] != modified_recall[i, :-1]
          )[0]
          average_precision[i] = np.sum(
              (
                  modified_recall[i, index + 1]
                  - modified_recall[i, index]
              )
              * modified_precision[i, index + 1]
          )
  
      return average_precision
  
file_path: cleanlab/cleanlab/object_detection/filter.py
imports: from collections import defaultdict
  from multiprocessing import Pool
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  from cleanlab.internal.constants import ALPHA, HIGH_PROBABILITY_THRESHOLD, LOW_PROBABILITY_THRESHOLD, OVERLOOKED_THRESHOLD_FACTOR, BADLOC_THRESHOLD_FACTOR, SWAP_THRESHOLD_FACTOR, AP_SCALE_FACTOR
  from cleanlab.internal.object_detection_utils import assert_valid_inputs
  from cleanlab.object_detection.rank import _get_valid_inputs_for_compute_scores, _separate_label, _separate_prediction, compute_badloc_box_scores, compute_overlooked_box_scores, compute_swap_box_scores, get_label_quality_scores, issues_from_scores, _get_overlap_matrix
label_desc: Use image node_id 9 for calling a global function with example usage: _calculate_average_precision(recall_values, precision_values) and returns: average_precision