code: def test_precision():
      prec_calculator = Precision(num_classes=3, average=True)
  
      # start with multiclass classification
      pred = torch.FloatTensor([[0.4, 0.5, 0.1], [0.1, 0.8, 0.1]])
      target = torch.LongTensor([[2], [1]])
  
      for i in range(2):
          prec_calculator.update(
              output=pred[i, :].unsqueeze(0),
              target=target[i, :].unsqueeze(0),
          )
  
      assert round(prec_calculator.value, 2) == 0.33
  
      prec_calculator = Precision(num_classes=3, average=False)
  
      # start with multiclass classification
      pred = torch.FloatTensor([[0.4, 0.5, 0.1], [0.1, 0.8, 0.1]])
      target = torch.LongTensor([[2], [1]])
  
      for i in range(2):
          prec_calculator.update(
              output=pred[i, :].unsqueeze(0),
              target=target[i, :].unsqueeze(0),
          )
  
      assert np.allclose(
          np.array(prec_calculator.value), np.array([0, 1, 0])
      )
  
imports: import os
  from pathlib import Path
  import numpy
  import pytest
  import shutil
  import torch
  from hypothesis import given
  from torch_hypothesis import classification_logits_and_labels
  from baal.utils.metrics import Loss, Accuracy, Precision, ECE, ClassificationReport, PRAuC, ECE_PerCLs
label_desc: Use image node_id 10 for calling a global function with example usage: test_precision() without return types