code: def _baseline_specificity_multiclass_global(
      preds, target, ignore_index, average
  ):
      preds = preds.numpy().flatten()
      target = target.numpy().flatten()
  
      if ignore_index is not None:
          idx = target == ignore_index
          target = target[~idx]
          preds = preds[~idx]
      confmat = sk_confusion_matrix(
          y_true=target, y_pred=preds, labels=list(range(NUM_CLASSES))
      )
      tp = np.diag(confmat)
      fp = confmat.sum(0) - tp
      fn = confmat.sum(1) - tp
      tn = confmat.sum() - (fp + fn + tp)
  
      if average == "micro":
          return _calc_specificity(tn.sum(), fp.sum())
  
      res = _calc_specificity(tn, fp)
      if average == "macro":
          res = res[
              (
                  np.bincount(preds, minlength=NUM_CLASSES)
                  + np.bincount(target, minlength=NUM_CLASSES)
              )
              != 0.0
          ]
          return res.mean(0)
      if average == "weighted":
          w = tp + fn
          return (res * (w / w.sum()).reshape(-1, 1)).sum(0)
      if average is None or average == "none":
          return res
      return None
  
imports: from functools import partial
  import numpy
  import pytest
  import torch
  from scipy.special import expit
  from sklearn.metrics import confusion_matrix
  from torch import Tensor, tensor
  from torchmetrics.classification.specificity import BinarySpecificity, MulticlassSpecificity, MultilabelSpecificity, Specificity
  from torchmetrics.functional.classification.specificity import binary_specificity, multiclass_specificity, multilabel_specificity
  from torchmetrics.metric import Metric
  from unittests import NUM_CLASSES, THRESHOLD
  from unittests.classification.inputs import _binary_cases, _multiclass_cases, _multilabel_cases
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester, inject_ignore_index
label_desc: Use image node_id 3 for calling a global function with example usage: _baseline_specificity_multiclass_global(preds, target, ignore_index, average) and returns: None, _calc_specificity, res, unknown, res