code: def _multilabel_ranking_average_precision_update(
      preds: Tensor, target: Tensor
  ) -> Tuple[Tensor, int]:
      """Accumulate state for label ranking average precision."""
      # Invert so that the highest score receives rank 1
      neg_preds = -preds
  
      score = torch.tensor(0.0, device=neg_preds.device)
      num_preds, num_labels = neg_preds.shape
      for i in range(num_preds):
          relevant = target[i] == 1
          ranking = _rank_data(neg_preds[i][relevant]).float()
          if len(ranking) > 0 and len(ranking) < num_labels:
              rank = _rank_data(neg_preds[i])[relevant].float()
              score_idx = (ranking / rank).mean()
          else:
              score_idx = torch.ones_like(score)
          score += score_idx
      return score, num_preds
  
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 6 for calling a global function with example usage: _multilabel_ranking_average_precision_update(preds, target) and returns: score,  num_preds