docstr: Return value of the metric for `average` options `'weighted'` and `'macro'` is computed as follows.
  
  .. math::
      \text{Precision/Recall} = \frac{ numerator }{ denominator } \cdot weight
  
  wherein `weight` is the internal variable `_weight` for `'weighted'` option and :math:`1/C`
  for the `macro` one. :math:`C` is the number of classes/labels.
  
  Return value of the metric for `average` options `'micro'`, `'samples'`, `False` and None is as follows.
  
  .. math::
      \text{Precision/Recall} = \frac{ numerator }{ denominator }
docstr_tok: ["Return","value","of","the","metric","for","`","average","`","options","`","'weighted","'","`","and","`","'macro","'","`","is","computed","as","follows",".","..","math",":",":","\\text","{","Precision\/Recall","}","=","\\frac","{","numerator","}","{","denominator","}","\\cdot","weight","wherein","`","weight","`","is","the","internal","variable","`","_weight","`","for","`","'weighted","'","`","option","and",":","math",":","`","1\/C","`","for","the","`","macro","`","one",".",":","math",":","`","C","`","is","the","number","of","classes\/labels",".","Return","value","of","the","metric","for","`","average","`","options","`","'micro","'","`",",","`","'samples","'","`",",","`","False","`","and","None","is","as","follows",".","..","math",":",":","\\text","{","Precision\/Recall","}","=","\\frac","{","numerator","}","{","denominator","}"]
code: def compute(self) -> Union[torch.Tensor, float]:
      r"""
      Return value of the metric for `average` options `'weighted'` and `'macro'` is computed as follows.
  
      .. math::
          \text{Precision/Recall} = \frac{ numerator }{ denominator } \cdot weight
  
      wherein `weight` is the internal variable `_weight` for `'weighted'` option and :math:`1/C`
      for the `macro` one. :math:`C` is the number of classes/labels.
  
      Return value of the metric for `average` options `'micro'`, `'samples'`, `False` and None is as follows.
  
      .. math::
          \text{Precision/Recall} = \frac{ numerator }{ denominator }
      """
  
      if not self._updated:
          raise NotComputableError(
              f"{self.__class__.__name__} must have at least one example before it can be computed."
          )
  
      fraction = self._numerator / (
          self._denominator
          + (self.eps if self._average != "samples" else 0)
      )
  
      if self._average == "weighted":
          _weight = idist.all_reduce(self._weight.clone())  # type: ignore[union-attr]
          sum_of_weights = cast(torch.Tensor, _weight).sum() + self.eps
          return ((fraction @ _weight) / sum_of_weights).item()  # type: ignore
      elif self._average == "micro" or self._average == "samples":
          return cast(torch.Tensor, fraction).item()
      elif self._average == "macro":
          return cast(torch.Tensor, fraction).mean().item()
      else:
          return fraction
  
file_path: ignite/ignite/metrics/precision.py
imports: import warnings
  from typing import Callable, cast, Optional, Sequence, Union
  import torch
  import ignite.distributed
  from ignite.exceptions import NotComputableError
  from ignite.metrics.accuracy import _BaseClassification
  from ignite.metrics.metric import reinit__is_reduced, sync_all_reduce
  from ignite.utils import to_onehot
label_desc: Use image node_id 5 for calling the _BasePrecisionRecall obj's underlying member method code with example usage: obj.compute() and returns: unknown, cast, cast, fraction