code: def _compute_precision_recall_curve(
      preds: Union[Tensor, array],
      target: Union[Tensor, array],
      indexes: Optional[Union[Tensor, array]] = None,
      max_k: Optional[int] = None,
      adaptive_k: bool = False,
      ignore_index: Optional[int] = None,
      empty_target_action: str = "skip",
      reverse: bool = False,
      aggregation: Union[
          Literal["mean", "median", "min", "max"], Callable
      ] = "mean",
  ) -> Tuple[Tensor, Tensor, Tensor]:
      """Compute metric with multiple iterations over every query predictions set.
  
      Didn't find a reliable implementation of precision-recall curve in Information Retrieval,
      so, reimplementing here.
  
      A good explanation can be found here:
      `<https://nlp.stanford.edu/IR-book/pdf/08eval.pdf>_`. (part 8.4)
  
      """
      recalls, precisions = [], []
  
      if indexes is None:
          indexes = np.full_like(preds, fill_value=0, dtype=np.int64)
      if isinstance(indexes, Tensor):
          indexes = indexes.cpu().numpy()
      if isinstance(preds, Tensor):
          preds = preds.cpu().numpy()
      if isinstance(target, Tensor):
          target = target.cpu().numpy()
  
      assert isinstance(indexes, np.ndarray)
      assert isinstance(preds, np.ndarray)
      assert isinstance(target, np.ndarray)
  
      if ignore_index is not None:
          valid_positions = target != ignore_index
          indexes, preds, target = (
              indexes[valid_positions],
              preds[valid_positions],
              target[valid_positions],
          )
  
      indexes = indexes.flatten()
      preds = preds.flatten()
      target = target.flatten()
      groups = get_group_indexes(indexes)
  
      if max_k is None:
          max_k = max(map(len, groups))
  
      top_k = torch.arange(1, max_k + 1)
  
      for group in groups:
          trg, prd = target[group], preds[group]
          r, p = [], []
  
          if ((1 - trg) if reverse else trg).sum() == 0:
              if empty_target_action == "skip":
                  pass
              elif empty_target_action == "pos":
                  arr = [1.0] * max_k
                  recalls.append(arr)
                  precisions.append(arr)
              elif empty_target_action == "neg":
                  arr = [0.0] * max_k
                  recalls.append(arr)
                  precisions.append(arr)
  
          else:
              for k in top_k:
                  r.append(_recall_at_k(trg, prd, top_k=k.item()))
                  p.append(
                      _precision_at_k(
                          trg,
                          prd,
                          top_k=k.item(),
                          adaptive_k=adaptive_k,
                      )
                  )
  
              recalls.append(r)
              precisions.append(p)
  
      if not recalls:
          return torch.zeros(max_k), torch.zeros(max_k), top_k
  
      recalls = _retrieval_aggregate(
          tensor(recalls), aggregation=aggregation, dim=0
      )
      precisions = _retrieval_aggregate(
          tensor(precisions), aggregation=aggregation, dim=0
      )
  
      return precisions, recalls, top_k
  
imports: from functools import partial
  from typing import Callable, Optional, Tuple, Union
  import numpy
  import pytest
  import torch
  from numpy import array
  from torch import Tensor, tensor
  from torchmetrics.retrieval import RetrievalPrecisionRecallCurve
  from torchmetrics.retrieval.base import _retrieval_aggregate
  from typing_extensions import Literal
  from unittests.helpers import seed_all
  from unittests.helpers.testers import Metric, MetricTester
  from unittests.retrieval.helpers import _custom_aggregate_fn, _default_metric_class_input_arguments, get_group_indexes
  from unittests.retrieval.test_precision import _precision_at_k
  from unittests.retrieval.test_recall import _recall_at_k
label_desc: Use image node_id 1 for calling a global function with example usage: _compute_precision_recall_curve(preds, target, indexes, max_k, adaptive_k, ignore_index, empty_target_action, reverse, aggregation) and returns: precisions,  recalls,  top_k, torch,  torch,  top_k