code: def reduce(
      x: Tensor,
      reduction: Literal["elementwise_mean", "sum", "none", None],
  ) -> Tensor:
      """Reduces a given tensor by a given reduction method.
  
      Args:
          x: the tensor, which shall be reduced
          reduction:  a string specifying the reduction method ('elementwise_mean', 'none', 'sum')
  
      Return:
          reduced Tensor
  
      Raise:
          ValueError if an invalid reduction parameter was given
  
      """
      if reduction == "elementwise_mean":
          return torch.mean(x)
      if reduction == "none" or reduction is None:
          return x
      if reduction == "sum":
          return torch.sum(x)
      raise ValueError("Reduction parameter unknown.")
  
file_path: torchmetrics/src/torchmetrics/utilities/distributed.py
imports: from typing import Any, List, Optional
  import torch
  from torch import Tensor
  from torch.nn import functional
  from typing_extensions import Literal
label_desc: Use image node_id 1 for calling a global function with example usage: reduce(x, reduction) and returns: torch, x, torch