code: def _sklearn_hamming_distance_multiclass_global(
      preds, target, ignore_index, average
  ):
      preds = preds.numpy().flatten()
      target = target.numpy().flatten()
      target, preds = remove_ignore_index(target, preds, ignore_index)
      if average == "micro":
          return _sklearn_hamming_loss(target, preds)
      confmat = sk_confusion_matrix(
          y_true=target, y_pred=preds, labels=list(range(NUM_CLASSES))
      )
      hamming_per_class = 1 - confmat.diagonal() / confmat.sum(axis=1)
      hamming_per_class[np.isnan(hamming_per_class)] = 1.0
      if average == "macro":
          hamming_per_class = hamming_per_class[
              (
                  np.bincount(preds, minlength=NUM_CLASSES)
                  + np.bincount(target, minlength=NUM_CLASSES)
              )
              != 0.0
          ]
          return hamming_per_class.mean()
      if average == "weighted":
          weights = confmat.sum(1)
          return ((weights * hamming_per_class) / weights.sum()).sum()
      return hamming_per_class
  
imports: from functools import partial
  import numpy
  import pytest
  import torch
  from scipy.special import expit
  from sklearn.metrics import confusion_matrix
  from sklearn.metrics import hamming_loss
  from torchmetrics.classification.hamming import BinaryHammingDistance, HammingDistance, MulticlassHammingDistance, MultilabelHammingDistance
  from torchmetrics.functional.classification.hamming import binary_hamming_distance, multiclass_hamming_distance, multilabel_hamming_distance
  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, remove_ignore_index
label_desc: Use image node_id 3 for calling a global function with example usage: _sklearn_hamming_distance_multiclass_global(preds, target, ignore_index, average) and returns: hamming_per_class, _sklearn_hamming_loss, hamming_per_class, unknown