code: def test_result_collection_on_tensor_with_mean_reduction():
      result_collection = _ResultCollection(True)
      product = [
          (True, True),
          (False, True),
          (True, False),
          (False, False),
      ]
      values = torch.arange(1, 10)
      batches = values * values
  
      for i, v in enumerate(values):
          for prog_bar in [False, True]:
              for logger in [False, True]:
                  for on_step, on_epoch in product:
                      name = "loss"
                      if on_step:
                          name += "_on_step"
                      if on_epoch:
                          name += "_on_epoch"
                      if prog_bar:
                          name += "_prog_bar"
                      if logger:
                          name += "_logger"
                      log_kwargs = {
                          "fx": "training_step",
                          "name": name,
                          "value": v,
                          "on_step": on_step,
                          "on_epoch": on_epoch,
                          "batch_size": batches[i],
                          "prog_bar": prog_bar,
                          "logger": logger,
                      }
                      if not on_step and not on_epoch:
                          with pytest.raises(
                              MisconfigurationException,
                              match="on_step=False, on_epoch=False",
                          ):
                              result_collection.log(**log_kwargs)
                      else:
                          result_collection.log(**log_kwargs)
  
      total_value = sum(values * batches)
      total_batches = sum(batches)
      assert (
          result_collection["training_step.loss_on_step_on_epoch"].value
          == total_value
      )
      assert (
          result_collection[
              "training_step.loss_on_step_on_epoch"
          ].cumulated_batch_size
          == total_batches
      )
  
      batch_metrics = result_collection.metrics(True)
      max_ = max(values)
      assert batch_metrics["pbar"] == {
          "loss_on_step_on_epoch_prog_bar_step": max_,
          "loss_on_step_on_epoch_prog_bar_logger_step": max_,
          "loss_on_step_prog_bar": max_,
          "loss_on_step_prog_bar_logger": max_,
      }
      assert batch_metrics["log"] == {
          "loss_on_step_on_epoch_logger_step": max_,
          "loss_on_step_logger": max_,
          "loss_on_step_on_epoch_prog_bar_logger_step": max_,
          "loss_on_step_prog_bar_logger": max_,
      }
      assert batch_metrics["callback"] == {
          "loss_on_step": max_,
          "loss_on_step_logger": max_,
          "loss_on_step_on_epoch": max_,
          "loss_on_step_on_epoch_logger": max_,
          "loss_on_step_on_epoch_logger_step": max_,
          "loss_on_step_on_epoch_prog_bar": max_,
          "loss_on_step_on_epoch_prog_bar_logger": max_,
          "loss_on_step_on_epoch_prog_bar_logger_step": max_,
          "loss_on_step_on_epoch_prog_bar_step": max_,
          "loss_on_step_on_epoch_step": max_,
          "loss_on_step_prog_bar": max_,
          "loss_on_step_prog_bar_logger": max_,
      }
  
      epoch_metrics = result_collection.metrics(False)
      mean = total_value / total_batches
      assert epoch_metrics["pbar"] == {
          "loss_on_epoch_prog_bar": mean,
          "loss_on_epoch_prog_bar_logger": mean,
          "loss_on_step_on_epoch_prog_bar_epoch": mean,
          "loss_on_step_on_epoch_prog_bar_logger_epoch": mean,
      }
      assert epoch_metrics["log"] == {
          "loss_on_epoch_logger": mean,
          "loss_on_epoch_prog_bar_logger": mean,
          "loss_on_step_on_epoch_logger_epoch": mean,
          "loss_on_step_on_epoch_prog_bar_logger_epoch": mean,
      }
      assert epoch_metrics["callback"] == {
          "loss_on_epoch": mean,
          "loss_on_epoch_logger": mean,
          "loss_on_epoch_prog_bar": mean,
          "loss_on_epoch_prog_bar_logger": mean,
          "loss_on_step_on_epoch": mean,
          "loss_on_step_on_epoch_epoch": mean,
          "loss_on_step_on_epoch_logger": mean,
          "loss_on_step_on_epoch_logger_epoch": mean,
          "loss_on_step_on_epoch_prog_bar": mean,
          "loss_on_step_on_epoch_prog_bar_epoch": mean,
          "loss_on_step_on_epoch_prog_bar_logger": mean,
          "loss_on_step_on_epoch_prog_bar_logger_epoch": mean,
      }
  
imports: import operator
  from functools import partial
  from unittest import mock
  from unittest.mock import Mock
  import pytest
  import torch
  from lightning.pytorch import LightningModule
  from lightning.pytorch.callbacks.callback import Callback
  from lightning.pytorch.demos.boring_classes import BoringModel, RandomDataset
  from lightning.pytorch.loggers import CSVLogger
  from lightning.pytorch.trainer import Trainer
  from lightning.pytorch.trainer.connectors.logger_connector.fx_validator import _FxValidator
  from lightning.pytorch.trainer.connectors.logger_connector.result import _ResultCollection
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.imports import _TORCHMETRICS_GREATER_EQUAL_0_9_1
  from lightning.pytorch.utilities.imports import _TORCHMETRICS_GREATER_EQUAL_0_11
  from lightning_utilities.core.imports import compare_version
  from torch.utils.data import DataLoader
  from torchmetrics import Accuracy, MeanAbsoluteError, MeanSquaredError, MetricCollection
  from torchmetrics import AveragePrecision
  from tests_pytorch.models.test_hooks import get_members
label_desc: Use image node_id 6 for calling a global function with example usage: test_result_collection_on_tensor_with_mean_reduction() without return types