code: def test_epoch_metric():
      def compute_fn(y_preds, y_targets):
          return 0.0
  
      em = EpochMetric(compute_fn)
  
      em.reset()
      output1 = (
          torch.rand(4, 3),
          torch.randint(0, 2, size=(4, 3), dtype=torch.long),
      )
      em.update(output1)
      output2 = (
          torch.rand(4, 3),
          torch.randint(0, 2, size=(4, 3), dtype=torch.long),
      )
      em.update(output2)
  
      assert all(
          [
              t.device.type == "cpu"
              for t in em._predictions + em._targets
          ]
      )
      assert torch.equal(em._predictions[0], output1[0])
      assert torch.equal(em._predictions[1], output2[0])
      assert torch.equal(em._targets[0], output1[1])
      assert torch.equal(em._targets[1], output2[1])
      assert em.compute() == 0.0
  
      # test when y and y_pred are (batch_size, 1) that are squeezed to (batch_size, )
      em.reset()
      output1 = (
          torch.rand(4, 1),
          torch.randint(0, 2, size=(4, 1), dtype=torch.long),
      )
      em.update(output1)
      output2 = (
          torch.rand(4, 1),
          torch.randint(0, 2, size=(4, 1), dtype=torch.long),
      )
      em.update(output2)
  
      assert all(
          [
              t.device.type == "cpu"
              for t in em._predictions + em._targets
          ]
      )
      assert torch.equal(em._predictions[0], output1[0][:, 0])
      assert torch.equal(em._predictions[1], output2[0][:, 0])
      assert torch.equal(em._targets[0], output1[1][:, 0])
      assert torch.equal(em._targets[1], output2[1][:, 0])
      assert em.compute() == 0.0
  
file_path: ignite/tests/ignite/metrics/test_epoch_metric.py
imports: import pytest
  import torch
  import ignite.distributed
  from ignite.engine import Engine
  from ignite.metrics import EpochMetric
  from ignite.metrics.epoch_metric import EpochMetricWarning, NotComputableError
label_desc: Use image node_id 2 for calling a global function with example usage: test_epoch_metric() and returns: int