code: def _test_distrib_compute(device):
      rank = idist.get_rank()
  
      def _test(y_pred, y, batch_size, metric_device):
          metric_device = torch.device(metric_device)
          prc = PrecisionRecallCurve(device=metric_device)
  
          prc.reset()
          if batch_size > 1:
              n_iters = y.shape[0] // batch_size + 1
              for i in range(n_iters):
                  idx = i * batch_size
                  prc.update(
                      (
                          y_pred[idx : idx + batch_size],
                          y[idx : idx + batch_size],
                      )
                  )
          else:
              prc.update((y_pred, y))
  
          # gather y_pred, y
          y_pred = idist.all_gather(y_pred)
          y = idist.all_gather(y)
  
          np_y = y.cpu().numpy()
          np_y_pred = y_pred.cpu().numpy()
  
          res = prc.compute()
  
          assert isinstance(res, Tuple)
          assert precision_recall_curve(np_y, np_y_pred)[
              0
          ] == pytest.approx(res[0].cpu().numpy())
          assert precision_recall_curve(np_y, np_y_pred)[
              1
          ] == pytest.approx(res[1].cpu().numpy())
          assert precision_recall_curve(np_y, np_y_pred)[
              2
          ] == pytest.approx(res[2].cpu().numpy())
  
      def get_test_cases():
          test_cases = [
              # Binary input data of shape (N,) or (N, 1)
              (
                  torch.randint(0, 2, size=(10,)),
                  torch.randint(0, 2, size=(10,)),
                  1,
              ),
              (
                  torch.randint(0, 2, size=(10, 1)),
                  torch.randint(0, 2, size=(10, 1)),
                  1,
              ),
              # updated batches
              (
                  torch.randint(0, 2, size=(50,)),
                  torch.randint(0, 2, size=(50,)),
                  16,
              ),
              (
                  torch.randint(0, 2, size=(50, 1)),
                  torch.randint(0, 2, size=(50, 1)),
                  16,
              ),
          ]
          return test_cases
  
      for i in range(3):
          torch.manual_seed(12 + rank + i)
          test_cases = get_test_cases()
          for y_pred, y, batch_size in test_cases:
              y_pred = y_pred.to(device)
              y = y.to(device)
              _test(y_pred, y, batch_size, "cpu")
              if device.type != "xla":
                  _test(y_pred, y, batch_size, idist.device())
  
imports: import os
  from typing import Tuple
  from unittest.mock import patch
  import numpy
  import pytest
  import sklearn
  import torch
  from sklearn.metrics import precision_recall_curve
  import ignite.distributed
  from ignite.contrib.metrics.precision_recall_curve import PrecisionRecallCurve
  from ignite.engine import Engine
  from ignite.metrics.epoch_metric import EpochMetricWarning
label_desc: Use image node_id 7 for calling a global function with example usage: _test_distrib_compute(device) and returns: test_cases