code: def test_iou(average):
      y_true, y_pred = get_y_true_y_pred()
      th_y_true, th_y_logits = compute_th_y_true_y_logits(
          y_true, y_pred
      )
  
      true_res = [0, 0, 0]
      for index in range(3):
          bin_y_true = y_true == index
          bin_y_pred = y_pred == index
          intersection = bin_y_true & bin_y_pred
          union = bin_y_true | bin_y_pred
          true_res[index] = intersection.sum() / union.sum()
  
      cm = ConfusionMatrix(num_classes=3, average=average)
      iou_metric = IoU(cm)
  
      # Update metric
      output = (th_y_logits, th_y_true)
      cm.update(output)
  
      res = iou_metric.compute().numpy()
  
      assert np.all(res == true_res)
  
      for ignore_index in range(3):
          cm = ConfusionMatrix(num_classes=3)
          iou_metric = IoU(cm, ignore_index=ignore_index)
          # Update metric
          output = (th_y_logits, th_y_true)
          cm.update(output)
          res = iou_metric.compute().numpy()
          true_res_ = (
              true_res[:ignore_index] + true_res[ignore_index + 1 :]
          )
          assert np.all(
              res == true_res_
          ), f"{ignore_index}: {res} vs {true_res_}"
  
      with pytest.raises(
          ValueError,
          match=r"ConfusionMatrix should have average attribute either",
      ):
          cm = ConfusionMatrix(num_classes=3, average="precision")
          IoU(cm)
  
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 11 for calling a global function with example usage: test_iou(average) without return types