code: def _r_precision(target: np.ndarray, preds: np.ndarray):
      """Didn't find a reliable implementation of R-Precision in Information Retrieval, so, reimplementing here.
  
      A good explanation can be found
      `here <https://web.stanford.edu/class/cs276/handouts/EvaluationNew-handout-1-per.pdf>_`.
  
      """
      assert target.shape == preds.shape
      assert (
          len(target.shape) == 1
      )  # works only with single dimension inputs
  
      if target.sum() > 0:
          order_indexes = np.argsort(preds, axis=0)[::-1]
          relevant = np.sum(target[order_indexes][: target.sum()])
          return relevant * 1.0 / target.sum()
      return np.NaN
  
file_path: torchmetrics/tests/unittests/retrieval/test_r_precision.py
imports: from typing import Callable, Union
  import numpy
  import pytest
  from torch import Tensor
  from torchmetrics.functional.retrieval.r_precision import retrieval_r_precision
  from torchmetrics.retrieval.r_precision import RetrievalRPrecision
  from typing_extensions import Literal
  from unittests.helpers import seed_all
  from unittests.retrieval.helpers import RetrievalMetricTester, _concat_tests, _custom_aggregate_fn, _default_metric_class_input_arguments, _default_metric_class_input_arguments_ignore_index, _default_metric_functional_input_arguments, _errors_test_class_metric_parameters_default, _errors_test_class_metric_parameters_no_pos_target, _errors_test_functional_metric_parameters_default
label_desc: Use image node_id 1 for calling a global function with example usage: _r_precision(target, preds) and returns: np, unknown