code: def _test_distrib_multiclass_images(device):
      def _test(metric_device):
          num_classes = 3
          cm = ConfusionMatrix(
              num_classes=num_classes, device=metric_device
          )
  
          y_true, y_pred = get_y_true_y_pred()
  
          # Compute confusion matrix with sklearn
          true_res = confusion_matrix(
              y_true.reshape(-1), y_pred.reshape(-1)
          )
  
          th_y_true, th_y_logits = compute_th_y_true_y_logits(
              y_true, y_pred
          )
          th_y_true = th_y_true.to(device)
          th_y_logits = th_y_logits.to(device)
  
          # Update metric
          output = (th_y_logits, th_y_true)
          cm.update(output)
  
          res = cm.compute().cpu().numpy() / idist.get_world_size()
  
          assert np.all(true_res == res)
  
          # Another test on batch of 2 images
          num_classes = 3
          cm = ConfusionMatrix(
              num_classes=num_classes, device=metric_device
          )
  
          # Create a batch of two images:
          th_y_true1 = torch.from_numpy(y_true).reshape(1, 30, 30)
          th_y_true2 = torch.from_numpy(y_true.transpose()).reshape(
              1, 30, 30
          )
          th_y_true = torch.cat([th_y_true1, th_y_true2], dim=0)
          th_y_true = th_y_true.to(device)
  
          # Create a batch of 2 logits tensors
          y_probas = np.ones((3, 30, 30)) * -10
          y_probas[0, (y_pred == 0)] = 720
          y_probas[1, (y_pred == 1)] = 720
          y_probas[2, (y_pred == 2)] = 768
          th_y_logits1 = torch.from_numpy(y_probas).reshape(
              1, 3, 30, 30
          )
  
          y_probas = np.ones((3, 30, 30)) * -10
          y_probas[0, (y_pred.transpose() == 0)] = 720
          y_probas[1, (y_pred.transpose() == 2)] = 720
          y_probas[2, (y_pred.transpose() == 1)] = 768
          th_y_logits2 = torch.from_numpy(y_probas).reshape(
              1, 3, 30, 30
          )
  
          th_y_logits = torch.cat([th_y_logits1, th_y_logits2], dim=0)
          # check update if input is on another device
          th_y_logits = th_y_logits.to(device)
  
          # Update metric & compute
          output = (th_y_logits, th_y_true)
          cm.update(output)
          res = cm.compute().cpu().numpy()
  
          # Compute confusion matrix with sklearn
          th_y_true = idist.all_gather(th_y_true)
          th_y_logits = idist.all_gather(th_y_logits)
  
          np_y_true = th_y_true.cpu().numpy().reshape(-1)
          np_y_pred = np.argmax(
              th_y_logits.cpu().numpy(), axis=1
          ).reshape(-1)
          true_res = confusion_matrix(np_y_true, np_y_pred)
  
          assert np.all(true_res == res)
  
      _test("cpu")
      if device.type != "xla":
          _test(idist.device())
  
imports: import os
  import numpy
  import pytest
  import torch
  from sklearn.metrics import accuracy_score, confusion_matrix, precision_score, recall_score
  import ignite.distributed
  from ignite.exceptions import NotComputableError
  from ignite.metrics import ConfusionMatrix, IoU, JaccardIndex, mIoU
  from ignite.metrics.confusion_matrix import cmAccuracy, cmPrecision, cmRecall, DiceCoefficient
label_desc: Use image node_id 19 for calling a global function with example usage: _test_distrib_multiclass_images(device) without return types