code: def _sklearn_hamming_distance_multilabel_global(
      preds, target, ignore_index, average
  ):
      if average == "micro":
          preds = preds.flatten()
          target = target.flatten()
          target, preds = remove_ignore_index(
              target, preds, ignore_index
          )
          return _sklearn_hamming_loss(target, preds)
  
      hamming, weights = [], []
      for i in range(preds.shape[1]):
          pred, true = preds[:, i].flatten(), target[:, i].flatten()
          true, pred = remove_ignore_index(true, pred, ignore_index)
          confmat = sk_confusion_matrix(true, pred, labels=[0, 1])
          hamming.append(_sklearn_hamming_loss(true, pred))
          weights.append(confmat[1, 1] + confmat[1, 0])
      res = np.stack(hamming, axis=0)
  
      if average == "macro":
          return res.mean(0)
      if average == "weighted":
          weights = np.stack(weights, 0).astype(float)
          weights_norm = weights.sum(-1, keepdims=True)
          weights_norm[weights_norm == 0] = 1.0
          return ((weights * res) / weights_norm).sum(-1)
      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 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 6 for calling a global function with example usage: _sklearn_hamming_distance_multilabel_global(preds, target, ignore_index, average) and returns: None, _sklearn_hamming_loss, res, unknown, res