code: def test_multilabel_input(average):
      pr = Precision(average=average, is_multilabel=True)
      assert pr._updated is False
  
      def _test(y_pred, y, batch_size):
          pr.reset()
          assert pr._updated is False
  
          if batch_size > 1:
              n_iters = y.shape[0] // batch_size + 1
              for i in range(n_iters):
                  idx = i * batch_size
                  pr.update(
                      (
                          y_pred[idx : idx + batch_size],
                          y[idx : idx + batch_size],
                      )
                  )
          else:
              pr.update((y_pred, y))
  
          np_y_pred = to_numpy_multilabel(y_pred)
          np_y = to_numpy_multilabel(y)
  
          assert pr._type == "multilabel"
          assert pr._updated is True
          pr_compute = (
              pr.compute().numpy() if not average else pr.compute()
          )
          sk_average_parameter = ignite_average_to_scikit_average(
              average, "multilabel"
          )
          with warnings.catch_warnings():
              warnings.simplefilter(
                  "ignore", category=UndefinedMetricWarning
              )
              assert precision_score(
                  np_y, np_y_pred, average=sk_average_parameter
              ) == pytest.approx(pr_compute)
  
      def get_test_cases():
          test_cases = [
              # Multilabel input data of shape (N, C)
              (
                  torch.randint(0, 2, size=(10, 5)),
                  torch.randint(0, 2, size=(10, 5)),
                  1,
              ),
              (
                  torch.randint(0, 2, size=(10, 4)),
                  torch.randint(0, 2, size=(10, 4)),
                  1,
              ),
              # updated batches
              (
                  torch.randint(0, 2, size=(50, 5)),
                  torch.randint(0, 2, size=(50, 5)),
                  16,
              ),
              (
                  torch.randint(0, 2, size=(50, 4)),
                  torch.randint(0, 2, size=(50, 4)),
                  16,
              ),
              # Multilabel input data of shape (N, C, L)
              (
                  torch.randint(0, 2, size=(10, 5, 10)),
                  torch.randint(0, 2, size=(10, 5, 10)),
                  1,
              ),
              (
                  torch.randint(0, 2, size=(10, 4, 10)),
                  torch.randint(0, 2, size=(10, 4, 10)),
                  1,
              ),
              # updated batches
              (
                  torch.randint(0, 2, size=(50, 5, 10)),
                  torch.randint(0, 2, size=(50, 5, 10)),
                  16,
              ),
              (
                  torch.randint(0, 2, size=(50, 4, 10)),
                  torch.randint(0, 2, size=(50, 4, 10)),
                  16,
              ),
              # Multilabel input data of shape (N, C, H, W)
              (
                  torch.randint(0, 2, size=(10, 5, 18, 16)),
                  torch.randint(0, 2, size=(10, 5, 18, 16)),
                  1,
              ),
              (
                  torch.randint(0, 2, size=(10, 4, 20, 23)),
                  torch.randint(0, 2, size=(10, 4, 20, 23)),
                  1,
              ),
              # updated batches
              (
                  torch.randint(0, 2, size=(50, 5, 18, 16)),
                  torch.randint(0, 2, size=(50, 5, 18, 16)),
                  16,
              ),
              (
                  torch.randint(0, 2, size=(50, 4, 20, 23)),
                  torch.randint(0, 2, size=(50, 4, 20, 23)),
                  16,
              ),
              # Corner case with all zeros predictions
              (
                  torch.zeros(size=(10, 5)),
                  torch.randint(0, 2, size=(10, 5)),
                  1,
              ),
              (
                  torch.zeros(size=(10, 4)),
                  torch.randint(0, 2, size=(10, 4)),
                  1,
              ),
          ]
  
          return test_cases
  
      for _ in range(5):
          # check multiple random inputs as random exact occurencies are rare
          test_cases = get_test_cases()
          for y_pred, y, batch_size in test_cases:
              _test(y_pred, y, batch_size)
  
imports: import warnings
  import pytest
  import torch
  from sklearn.exceptions import UndefinedMetricWarning
  from sklearn.metrics import precision_score
  import ignite.distributed
  from ignite.exceptions import NotComputableError
  from ignite.metrics import Precision
label_desc: Use image node_id 10 for calling a global function with example usage: test_multilabel_input(average) and returns: test_cases