code: def compute_ap(recall, precision):
      """Compute the average precision, given the recall and precision curves
      # Arguments
          recall:    The recall curve (list)
          precision: The precision curve (list)
      # Returns
          Average precision, precision curve, recall curve
      """
  
      # Append sentinel values to beginning and end
      mrec = np.concatenate(([0.0], recall, [1.0]))
      mpre = np.concatenate(([1.0], precision, [0.0]))
  
      # Compute the precision envelope
      mpre = np.flip(np.maximum.accumulate(np.flip(mpre)))
  
      # Integrate area under curve
      x = np.linspace(0, 1, 101)  # 101-point interp (COCO)
      ap = np.trapz(np.interp(x, mrec, mpre), x)  # integrate
  
      return ap, mpre, mrec
  
imports: import math
  import warnings
  import numpy
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: compute_ap(recall, precision) and returns: ap,  mpre,  mrec