class_docstr: Helper class to compute geometric average of a single variable.
  
  - ``update`` must receive output of the form `x`.
  - `x` can be a positive number or a positive `torch.Tensor`, such that ``torch.log(x)`` is not `nan`.
  
  Args:
      output_transform: a callable that is used to transform the
          :class:`~ignite.engine.engine.Engine`'s ``process_function``'s output into the
          form expected by the metric. This can be useful if, for example, you have a multi-output model and
          you want to compute the metric with respect to one of the outputs.
      device: specifies which device updates are accumulated on. Setting the metric's
          device to be the same as your ``update`` arguments ensures the ``update`` method is non-blocking. By
          default, CPU.
  
  Note:
  
      Number of samples is updated following the rule:
  
      - `+1` if input is a number
      - `+1` if input is a 1D `torch.Tensor`
      - `+batch_size` if input is a ND `torch.Tensor`. Batch size is the first dimension (`shape[0]`).
  
      For input `x` being an ND `torch.Tensor` with N > 1, the first dimension is seen as the number of samples and
      is aggregated and added to the accumulator: `accumulator *= prod(x, dim=0)`
  
      ``output_tranform`` can be added to the metric to transform the output into the form expected by the metric.
  
  Examples:
  
      For more information on how metric works with :class:`~ignite.engine.engine.Engine`, visit :ref:`attach-engine`.
  
      .. include:: defaults.rst
          :start-after: :orphan:
  
      .. testcode::
  
          metric = GeometricAverage()
          metric.attach(default_evaluator, 'avg')
          # Case 1. input is er
          data = torch.tensor([1, 2, 3])
          state = default_evaluator.run(data)
          print(state.metrics['avg'])
  
      .. testoutput::
  
          1.8171...
  
      .. testcode::
  
          metric = GeometricAverage()
          metric.attach(default_evaluator, 'avg')
          # Case 2. input is a 1D torch.Tensor
          data = torch.tensor([
              [1, 1, 1],
              [2, 2, 2],
              [3, 3, 3],
              [4, 4, 4],
          ])
          state = default_evaluator.run(data)
          print(state.metrics['avg'])
  
      .. testoutput::
  
          tensor([2.2134, 2.2134, 2.2134], dtype=torch.float64)
  
      .. testcode::
  
          metric = GeometricAverage()
          metric.attach(default_evaluator, 'avg')
          # Case 3. input is a ND torch.Tensor
          data = [
              torch.tensor([[1, 1, 1], [2, 2, 2]]),
              torch.tensor([[3, 3, 3], [4, 4, 4]])
          ]
          state = default_evaluator.run(data)
          print(state.metrics['avg'])
  
      .. testoutput::
  
          tensor([2.2134, 2.2134, 2.2134], dtype=torch.float64)
class_docstr_tok: ["Helper","class","to","compute","geometric","average","of","a","single","variable",".","-","``","update","``","must","receive","output","of","the","form","`","x","`",".","-","`","x","`","can","be","a","positive","number","or","a","positive","`","torch.Tensor","`",",","such","that","``","torch.log","(","x",")","``","is","not","`","nan","`",".","Args",":","output_transform",":","a","callable","that","is","used","to","transform","the",":","class",":","`","~ignite.engine.engine.Engine","`","'s","``","process_function","``","'s","output","into","the","form","expected","by","the","metric",".","This","can","be","useful","if",",","for","example",",","you","have","a","multi-output","model","and","you","want","to","compute","the","metric","with","respect","to","one","of","the","outputs",".","device",":","specifies","which","device","updates","are","accumulated","on",".","Setting","the","metric's","device","to","be","the","same","as","your","``","update","``","arguments","ensures","the","``","update","``","method","is","non-blocking",".","By","default",",","CPU",".","Note",":","Number","of","samples","is","updated","following","the","rule",":","-","`","+1","`","if","input","is","a","number","-","`","+1","`","if","input","is","a","1D","`","torch.Tensor","`","-","`","+batch_size","`","if","input","is","a","ND","`","torch.Tensor","`",".","Batch","size","is","the","first","dimension","(","`","shape","[","0","]","`",")",".","For","input","`","x","`","being","an","ND","`","torch.Tensor","`","with","N",">","1",",","the","first","dimension","is","seen","as","the","number","of","samples","and","is","aggregated","and","added","to","the","accumulator",":","`","accumulator","*","=","prod","(","x",",","dim=0",")","`","``","output_tranform","``","can","be","added","to","the","metric","to","transform","the","output","into","the","form","expected","by","the","metric",".","Examples",":","For","more","information","on","how","metric","works","with",":","class",":","`","~ignite.engine.engine.Engine","`",",","visit",":","ref",":","`","attach-engine","`",".","..","include",":",":","defaults.rst",":","start-after",":",":","orphan",":","..","testcode",":",":","metric","=","GeometricAverage","(",")","metric.attach","(","default_evaluator",",","'avg","'",")","#","Case","1.","input","is","er","data","=","torch.tensor","(","[","1",",","2",",","3","]",")","state","=","default_evaluator.run","(","data",")","print","(","state.metrics","[","'avg","'","]",")","..","testoutput",":",":","1.8171","...","..","testcode",":",":","metric","=","GeometricAverage","(",")","metric.attach","(","default_evaluator",",","'avg","'",")","#","Case","2.","input","is","a","1D","torch.Tensor","data","=","torch.tensor","(","[","[","1",",","1",",","1","]",",","[","2",",","2",",","2","]",",","[","3",",","3",",","3","]",",","[","4",",","4",",","4","]",",","]",")","state","=","default_evaluator.run","(","data",")","print","(","state.metrics","[","'avg","'","]",")","..","testoutput",":",":","tensor","(","[","2.2134",",","2.2134",",","2.2134","]",",","dtype=torch.float64",")","..","testcode",":",":","metric","=","GeometricAverage","(",")","metric.attach","(","default_evaluator",",","'avg","'",")","#","Case","3.","input","is","a","ND","torch.Tensor","data","=","[","torch.tensor","(","[","[","1",",","1",",","1","]",",","[","2",",","2",",","2","]","]",")",",","torch.tensor","(","[","[","3",",","3",",","3","]",",","[","4",",","4",",","4","]","]",")","]","state","=","default_evaluator.run","(","data",")","print","(","state.metrics","[","'avg","'","]",")","..","testoutput",":",":","tensor","(","[","2.2134",",","2.2134",",","2.2134","]",",","dtype=torch.float64",")"]
code: def compute(self) -> Union[float, torch.Tensor]:
      if self.num_examples < 1:
          raise NotComputableError(
              f"{self.__class__.__name__} must have at least one example before it can be computed."
          )
  
      tensor = torch.exp(self.accumulator / self.num_examples)
  
      if tensor.numel() == 1:
          return tensor.item()
  
      return tensor
  
file_path: ignite/ignite/metrics/accumulation.py
imports: import numbers
  from typing import Callable, Tuple, Union
  import torch
  from ignite.exceptions import NotComputableError
  from ignite.metrics.metric import Metric, reinit__is_reduced, sync_all_reduce
label_desc: Use image node_id 2 for calling the GeometricAverage obj's underlying member method code with example usage: obj.compute() and returns: tensor, tensor