code: def test_binary_and_multilabel_inputs(
      n_times, test_data_binary_and_multilabel
  ):
      y_pred, y, batch_size = test_data_binary_and_multilabel
      ap = AveragePrecision()
      ap.reset()
      if batch_size > 1:
          n_iters = y.shape[0] // batch_size + 1
          for i in range(n_iters):
              idx = i * batch_size
              ap.update(
                  (
                      y_pred[idx : idx + batch_size],
                      y[idx : idx + batch_size],
                  )
              )
      else:
          ap.update((y_pred, y))
  
      np_y = y.numpy()
      np_y_pred = y_pred.numpy()
  
      res = ap.compute()
      assert isinstance(res, float)
      assert average_precision_score(np_y, np_y_pred) == pytest.approx(
          res
      )
  
imports: import os
  from unittest.mock import patch
  import pytest
  import sklearn
  import torch
  from sklearn.metrics import average_precision_score
  import ignite.distributed
  from ignite.contrib.metrics import AveragePrecision
  from ignite.engine import Engine
  from ignite.exceptions import NotComputableError
label_desc: Use image node_id 7 for calling a global function with example usage: test_binary_and_multilabel_inputs(n_times, test_data_binary_and_multilabel) without return types