code: def mean_average_precision(
      knn_labels,
      gt_labels,
      ref_includes_query,
      label_counts,
      avg_of_avgs,
      return_per_class,
      label_comparison_fn,
      at_r=False,
  ):
      device = gt_labels.device
      num_samples, num_k = knn_labels.shape[:2]
      relevance_mask, count_per_query = get_relevance_mask(
          knn_labels.shape[:2],
          gt_labels,
          ref_includes_query,
          label_counts,
      )
      knn_mask = (
          relevance_mask
          if at_r
          else torch.ones(
              (num_samples, num_k), dtype=torch.bool, device=device
          )
      )
      is_same_label = label_comparison_fn(gt_labels, knn_labels)
      equality = is_same_label * knn_mask
      cumulative_correct = torch.cumsum(equality, dim=1)
      k_idx = torch.arange(1, num_k + 1, device=device).repeat(
          num_samples, 1
      )
      precision_at_ks = (cumulative_correct * equality).type(
          torch.float64
      ) / k_idx
      summed_precision_per_row = torch.sum(
          precision_at_ks * knn_mask, dim=1
      )
      accuracy_per_sample = summed_precision_per_row / count_per_query
      return maybe_get_avg_of_avgs(
          accuracy_per_sample, gt_labels, avg_of_avgs, return_per_class
      )
  
imports: import torch
  from sklearn.metrics import adjusted_mutual_info_score, normalized_mutual_info_score
  from .None import common_functions
  from .inference import FaissKMeans, FaissKNN
label_desc: Use image node_id 5 for calling a global function with example usage: mean_average_precision(knn_labels, gt_labels, ref_includes_query, label_counts, avg_of_avgs, return_per_class, label_comparison_fn, at_r) and returns: maybe_get_avg_of_avgs