code: def _rank_data(x: Tensor) -> Tensor:
      """Rank data based on values."""
      # torch.unique does not support input that requires grad
      with torch.no_grad():
          _, inverse, counts = torch.unique(
              x, sorted=True, return_inverse=True, return_counts=True
          )
      ranks = _cumsum(counts, dim=0)
      return ranks[inverse]
  
file_path: torchmetrics/src/torchmetrics/functional/classification/ranking.py
imports: from typing import Optional, Tuple
  import torch
  from torch import Tensor
  from torchmetrics.functional.classification.confusion_matrix import _multilabel_confusion_matrix_arg_validation, _multilabel_confusion_matrix_format, _multilabel_confusion_matrix_tensor_validation
  from torchmetrics.utilities.data import _cumsum
label_desc: Use image node_id 1 for calling a global function with example usage: _rank_data(x) and returns: ranks