code: def _sklearn_jaccard_index_multilabel(
      preds, target, ignore_index=None, average="macro"
  ):
      preds = preds.numpy()
      target = target.numpy()
      if np.issubdtype(preds.dtype, np.floating):
          if not ((preds > 0) & (preds < 1)).all():
              preds = sigmoid(preds)
          preds = (preds >= THRESHOLD).astype(np.uint8)
      preds = np.moveaxis(preds, 1, -1).reshape((-1, preds.shape[1]))
      target = np.moveaxis(target, 1, -1).reshape((-1, target.shape[1]))
      if ignore_index is None:
          return sk_jaccard_index(
              y_true=target, y_pred=preds, average=average
          )
  
      if average == "micro":
          return _sklearn_jaccard_index_binary(
              torch.tensor(preds), torch.tensor(target), ignore_index
          )
      scores, weights = [], []
      for i in range(preds.shape[1]):
          pred, true = preds[:, i], target[:, i]
          true, pred = remove_ignore_index(true, pred, ignore_index)
          confmat = sk_confusion_matrix(true, pred, labels=[0, 1])
          scores.append(sk_jaccard_index(true, pred))
          weights.append(confmat[1, 0] + confmat[1, 1])
      scores = np.stack(scores, axis=0)
      weights = np.stack(weights, axis=0)
      if average is None or average == "none":
          return scores
      if average == "macro":
          return scores.mean()
      return ((scores * weights) / weights.sum()).sum()
  
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 jaccard_score
  from torchmetrics.classification.jaccard import BinaryJaccardIndex, JaccardIndex, MulticlassJaccardIndex, MultilabelJaccardIndex
  from torchmetrics.functional.classification.jaccard import binary_jaccard_index, multiclass_jaccard_index, multilabel_jaccard_index
  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.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_jaccard_index_multilabel(preds, target, ignore_index, average) and returns: unknown, sk_jaccard_index, _sklearn_jaccard_index_binary, scores, scores