code: def _test_distrib_multiclass_images(device):
      def _test(metric_device):
          num_classes = 3
          cm = MultiLabelConfusionMatrix(
              num_classes=num_classes, device=metric_device
          )
  
          y_true, y_pred = get_y_true_y_pred()
  
          # Compute confusion matrix with sklearn
          sklearn_CM = multilabel_confusion_matrix(
              y_true.transpose((0, 2, 3, 1)).reshape(-1, 3),
              y_pred.transpose((0, 2, 3, 1)).reshape(-1, 3),
          )
  
          # Update metric
          output = (
              torch.tensor(y_pred).to(device),
              torch.tensor(y_true).to(device),
          )
          cm.update(output)
  
          ignite_CM = cm.compute().cpu().numpy()
  
          assert np.all(ignite_CM == sklearn_CM)
  
          # Another test on batch of 2 images
          num_classes = 3
          cm = MultiLabelConfusionMatrix(
              num_classes=num_classes, device=metric_device
          )
  
          # Create a batch of two images:
          th_y_true1 = torch.tensor(y_true)
          th_y_true2 = torch.tensor(y_true.transpose(0, 1, 3, 2))
          th_y_true = torch.cat([th_y_true1, th_y_true2], dim=0)
          th_y_true = th_y_true.to(device)
  
          th_y_pred1 = torch.tensor(y_pred)
          th_y_pred2 = torch.tensor(y_pred.transpose(0, 1, 3, 2))
          th_y_pred = torch.cat([th_y_pred1, th_y_pred2], dim=0)
          th_y_pred = th_y_pred.to(device)
  
          # Update metric & compute
          output = (th_y_pred, th_y_true)
          cm.update(output)
          ignite_CM = cm.compute().cpu().numpy()
  
          # Compute confusion matrix with sklearn
          th_y_true = idist.all_gather(th_y_true)
          th_y_pred = idist.all_gather(th_y_pred)
  
          np_y_true = (
              th_y_true.cpu()
              .numpy()
              .transpose((0, 2, 3, 1))
              .reshape(-1, 3)
          )
          np_y_pred = (
              th_y_pred.cpu()
              .numpy()
              .transpose((0, 2, 3, 1))
              .reshape(-1, 3)
          )
          sklearn_CM = multilabel_confusion_matrix(np_y_true, np_y_pred)
  
          assert np.all(ignite_CM == sklearn_CM)
  
      _test("cpu")
      if device.type != "xla":
          _test(idist.device())
  
file_path: ignite/tests/ignite/metrics/test_multilabel_confusion_matrix.py
imports: import numpy
  import pytest
  import torch
  from sklearn.metrics import multilabel_confusion_matrix
  import ignite.distributed
  from ignite.exceptions import NotComputableError
  from ignite.metrics.multilabel_confusion_matrix import MultiLabelConfusionMatrix
label_desc: Use image node_id 6 for calling a global function with example usage: _test_distrib_multiclass_images(device) without return types