code: def JaccardIndex(
      cm: ConfusionMatrix, ignore_index: Optional[int] = None
  ) -> MetricsLambda:
      r"""Calculates the Jaccard Index using :class:`~ignite.metrics.confusion_matrix.ConfusionMatrix` metric.
      Implementation is based on :meth:`~ignite.metrics.IoU`.
  
      .. math:: \text{J}(A, B) = \frac{ \lvert A \cap B \rvert }{ \lvert A \cup B \rvert }
  
      Args:
          cm: instance of confusion matrix metric
          ignore_index: index to ignore, e.g. background index
  
      Returns:
          MetricsLambda
  
      Examples:
  
          For more information on how metric works with :class:`~ignite.engine.engine.Engine`, visit :ref:`attach-engine`.
  
          .. include:: defaults.rst
              :start-after: :orphan:
  
          .. testcode::
  
              cm = ConfusionMatrix(num_classes=3)
              metric = JaccardIndex(cm, ignore_index=0)
              metric.attach(default_evaluator, 'jac')
              y_true = torch.tensor([0, 1, 0, 1, 2])
              y_pred = torch.tensor([
                  [0.0, 1.0, 0.0],
                  [0.0, 1.0, 0.0],
                  [1.0, 0.0, 0.0],
                  [0.0, 1.0, 0.0],
                  [0.0, 1.0, 0.0],
              ])
              state = default_evaluator.run([[y_pred, y_true]])
              print(state.metrics['jac'])
  
          .. testoutput::
  
              tensor([0.5000, 0.0000], dtype=torch.float64)
      """
      return IoU(cm, ignore_index)
  
imports: import numbers
  from typing import Callable, Optional, Sequence, Tuple, Union
  import torch
  from ignite.exceptions import NotComputableError
  from ignite.metrics.metric import Metric, reinit__is_reduced, sync_all_reduce
  from ignite.metrics.metrics_lambda import MetricsLambda
label_desc: Use image node_id 7 for calling a global function with example usage: JaccardIndex(cm, ignore_index) and returns: IoU