code: def cmPrecision(
      cm: ConfusionMatrix, average: bool = True
  ) -> MetricsLambda:
      """Calculates precision using :class:`~ignite.metrics.metric.ConfusionMatrix` metric.
  
      Args:
          cm: instance of confusion matrix metric
          average: if True metric value is averaged over all classes
      Returns:
          MetricsLambda
      """
  
      # Increase floating point precision and pass to CPU
      cm = cm.to(torch.double)
      precision: MetricsLambda = cm.diag() / (cm.sum(dim=0) + 1e-15)
      if average:
          mean: MetricsLambda = precision.mean()
          return mean
      return precision
  
imports: import numbers
  from typing import Callable, Optional, Sequence, Tuple, Union
  import torch
  from ignite.exceptions import NotComputableError
  from ignite.metrics.metric import Metric, reinit__is_reduced, sync_all_reduce
  from ignite.metrics.metrics_lambda import MetricsLambda
label_desc: Use image node_id 4 for calling a global function with example usage: cmPrecision(cm, average) and returns: precision, mean