code: def _baseline_specificity_multiclass_local(
      preds, target, ignore_index, average
  ):
      preds = preds.numpy()
      target = target.numpy()
  
      res = []
      for pred, true in zip(preds, target):
          pred = pred.flatten()
          true = true.flatten()
  
          if ignore_index is not None:
              idx = true == ignore_index
              true = true[~idx]
              pred = pred[~idx]
          confmat = sk_confusion_matrix(
              y_true=true, y_pred=pred, 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":
              res.append(_calc_specificity(tn.sum(), fp.sum()))
  
          r = _calc_specificity(tn, fp)
          if average == "macro":
              r = r[
                  (
                      np.bincount(pred, minlength=NUM_CLASSES)
                      + np.bincount(true, minlength=NUM_CLASSES)
                  )
                  != 0.0
              ]
              res.append(r.mean(0) if len(r) > 0 else 0.0)
          elif average == "weighted":
              w = tp + fn
              res.append((r * (w / w.sum()).reshape(-1, 1)).sum(0))
          elif average is None or average == "none":
              res.append(r)
      return np.stack(res, 0)
  
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 4 for calling a global function with example usage: _baseline_specificity_multiclass_local(preds, target, ignore_index, average) and returns: np