code: def _baseline_specificity_multilabel_global(
      preds, target, ignore_index, average
  ):
      tns, fps = [], []
      for i in range(preds.shape[1]):
          p, t = preds[:, i].flatten(), target[:, i].flatten()
          if ignore_index is not None:
              idx = t == ignore_index
              t = t[~idx]
              p = p[~idx]
          tn, fp, fn, tp = sk_confusion_matrix(
              t, p, labels=[0, 1]
          ).ravel()
          tns.append(tn)
          fps.append(fp)
  
      tn = np.array(tns)
      fp = np.array(fps)
      if average == "micro":
          return _calc_specificity(tn.sum(), fp.sum())
  
      res = _calc_specificity(tn, fp)
      if average == "macro":
          return res.mean(0)
      if average == "weighted":
          w = res[:, 0] + res[:, 3]
          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 7 for calling a global function with example usage: _baseline_specificity_multilabel_global(preds, target, ignore_index, average) and returns: None, _calc_specificity, res, unknown, res