code: def _sklearn_jaccard_index_multiclass(
      preds, target, ignore_index=None, average="macro"
  ):
      preds = preds.numpy()
      target = target.numpy()
      if np.issubdtype(preds.dtype, np.floating):
          preds = np.argmax(preds, axis=1)
      preds = preds.flatten()
      target = target.flatten()
      target, preds = remove_ignore_index(target, preds, ignore_index)
      if ignore_index is not None and 0 <= ignore_index < NUM_CLASSES:
          labels = [i for i in range(NUM_CLASSES) if i != ignore_index]
          res = sk_jaccard_index(
              y_true=target,
              y_pred=preds,
              average=average,
              labels=labels,
          )
          return (
              np.insert(res, ignore_index, 0.0)
              if average is None
              else res
          )
      if average is None:
          return sk_jaccard_index(
              y_true=target,
              y_pred=preds,
              average=average,
              labels=list(range(NUM_CLASSES)),
          )
      return sk_jaccard_index(
          y_true=target, y_pred=preds, average=average
      )
  
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 2 for calling a global function with example usage: _sklearn_jaccard_index_multiclass(preds, target, ignore_index, average) and returns: sk_jaccard_index, unknown, sk_jaccard_index