code: def _baseline_specificity_multilabel_local(
      preds, target, ignore_index, average
  ):
      specificity = []
      for i in range(preds.shape[0]):
          tns, fps = [], []
          for j in range(preds.shape[1]):
              pred, true = preds[i, j], target[i, j]
              if ignore_index is not None:
                  idx = true == ignore_index
                  true = true[~idx]
                  pred = pred[~idx]
              tn, fp, _, _ = sk_confusion_matrix(
                  true, pred, labels=[0, 1]
              ).ravel()
              tns.append(tn)
              fps.append(fp)
          tn = np.array(tns)
          fp = np.array(fps)
          if average == "micro":
              specificity.append(_calc_specificity(tn.sum(), fp.sum()))
          else:
              specificity.append(_calc_specificity(tn, fp))
  
      res = np.stack(specificity, 0)
      if average == "micro" or average is None or average == "none":
          return res
      if average == "macro":
          return res.mean(-1)
      if average == "weighted":
          w = res[:, 0, :] + res[:, 3, :]
          return (res * (w / w.sum())[:, np.newaxis]).sum(-1)
      if average is None or average == "none":
          return np.moveaxis(res, 1, -1)
      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 8 for calling a global function with example usage: _baseline_specificity_multilabel_local(preds, target, ignore_index, average) and returns: None, res, res, unknown, np