code: def _adjust_weights_safe_divide(
      score: Tensor,
      average: Optional[str],
      multilabel: bool,
      tp: Tensor,
      fp: Tensor,
      fn: Tensor,
  ) -> Tensor:
      if average is None or average == "none":
          return score
      if average == "weighted":
          weights = tp + fn
      else:
          weights = torch.ones_like(score)
          if not multilabel:
              weights[tp + fp + fn == 0] = 0.0
      return _safe_divide(
          weights * score, weights.sum(-1, keepdim=True)
      ).sum(-1)
  
file_path: torchmetrics/src/torchmetrics/utilities/compute.py
imports: from typing import Optional, Tuple
  import torch
  from torch import Tensor
label_desc: Use image node_id 4 for calling a global function with example usage: _adjust_weights_safe_divide(score, average, multilabel, tp, fp, fn) and returns: _safe_divide, score