code: def test_accuracy_calculator(self):
      query_labels = torch.tensor(
          [1, 1, 2, 3, 4, 0], device=TEST_DEVICE
      )
  
      knn_labels1 = torch.tensor(
          [
              [0, 1, 1, 2, 2],
              [1, 0, 1, 1, 3],
              [4, 4, 4, 4, 2],
              [3, 1, 3, 1, 3],
              [0, 0, 4, 2, 2],
              [1, 2, 3, 4, 5],
          ],
          device=TEST_DEVICE,
      )
      label_counts1 = ([0, 1, 2, 3, 4], [2, 3, 5, 4, 5])
  
      knn_labels2 = knn_labels1 + 5
      label_counts2 = ([5, 6, 7, 8, 9], [2, 3, 5, 4, 5])
  
      for avg_of_avgs in [False, True]:
          for return_per_class in [False, True]:
              for i, (knn_labels, label_counts) in enumerate(
                  [
                      (knn_labels1, label_counts1),
                      (knn_labels2, label_counts2),
                  ]
              ):
                  init_kwargs = {
                      "exclude": ("NMI", "AMI"),
                      "avg_of_avgs": avg_of_avgs,
                      "return_per_class": return_per_class,
                      "device": TEST_DEVICE,
                  }
  
                  if avg_of_avgs and return_per_class:
                      self.assertRaises(
                          ValueError,
                          lambda: accuracy_calculator.AccuracyCalculator(
                              **init_kwargs
                          ),
                      )
                      continue
  
                  AC = accuracy_calculator.AccuracyCalculator(
                      **init_kwargs
                  )
                  kwargs = {
                      "query_labels": query_labels,
                      "label_counts": label_counts,
                      "knn_labels": knn_labels,
                      "not_lone_query_mask": torch.ones(
                          6, dtype=torch.bool
                      )
                      if i == 0
                      else torch.zeros(6, dtype=torch.bool),
                  }
  
                  function_dict = AC.get_function_dict()
  
                  for ecfss in [False, True]:
                      if ecfss:
                          kwargs["knn_labels"] = kwargs["knn_labels"][
                              :, 1:
                          ]
                      kwargs["ref_includes_query"] = ecfss
                      acc = AC._get_accuracy(function_dict, **kwargs)
                      if i == 1:
                          self.assertTrue(
                              np.all(np.isnan(acc["precision_at_1"]))
                          )
                          self.assertTrue(
                              np.all(np.isnan(acc["r_precision"]))
                          )
                          self.assertTrue(
                              np.all(
                                  np.isnan(
                                      acc["mean_average_precision_at_r"]
                                  )
                              )
                          )
                          self.assertTrue(
                              np.all(
                                  np.isnan(
                                      acc["mean_average_precision"]
                                  )
                              )
                          )
                          self.assertTrue(
                              np.all(
                                  np.isnan(acc["mean_reciprocal_rank"])
                              )
                          )
                      else:
                          self.assertTrue(
                              isclose(
                                  acc["precision_at_1"],
                                  self.correct_precision_at_1(
                                      ecfss,
                                      avg_of_avgs,
                                      return_per_class,
                                  ),
                                  many=return_per_class,
                              )
                          )
                          self.assertTrue(
                              isclose(
                                  acc["r_precision"],
                                  self.correct_r_precision(
                                      ecfss,
                                      avg_of_avgs,
                                      return_per_class,
                                  ),
                                  many=return_per_class,
                              )
                          )
                          self.assertTrue(
                              isclose(
                                  acc["mean_average_precision_at_r"],
                                  self.correct_mean_average_precision_at_r(
                                      ecfss,
                                      avg_of_avgs,
                                      return_per_class,
                                  ),
                                  many=return_per_class,
                              )
                          )
                          self.assertTrue(
                              isclose(
                                  acc["mean_average_precision"],
                                  self.correct_mean_average_precision(
                                      ecfss,
                                      avg_of_avgs,
                                      return_per_class,
                                  ),
                                  many=return_per_class,
                              )
                          )
                          self.assertTrue(
                              isclose(
                                  acc["mean_reciprocal_rank"],
                                  self.correct_mean_reciprocal_rank(
                                      ecfss,
                                      avg_of_avgs,
                                      return_per_class,
                                  ),
                                  many=return_per_class,
                              )
                          )
  
imports: import itertools
  import logging
  import unittest
  import numpy
  import torch
  from pytorch_metric_learning.distances import LpDistance
  from pytorch_metric_learning.utils import accuracy_calculator
  from pytorch_metric_learning.utils.common_functions import LOGGER
  from pytorch_metric_learning.utils.inference import CustomKNN, FaissKMeans, FaissKNN
  from ..None import TEST_DEVICE
label_desc: Use image node_id 1 for calling the TestCalculateAccuracies obj's underlying member method code with example usage: obj.test_accuracy_calculator() without return types