code: def _test_accuracy_calculator_custom_comparison_function(
      self, use_numpy
  ):
      def label_comparison_fn(x, y):
          return (x[..., 0] == y[..., 0]) & (x[..., 1] != y[..., 1])
  
      self.assertRaises(
          NotImplementedError,
          lambda: accuracy_calculator.AccuracyCalculator(
              include=("NMI", "AMI"),
              avg_of_avgs=False,
              label_comparison_fn=label_comparison_fn,
              device=TEST_DEVICE,
          ),
      )
  
      AC_global_average = accuracy_calculator.AccuracyCalculator(
          exclude=("NMI", "AMI"),
          avg_of_avgs=False,
          label_comparison_fn=label_comparison_fn,
          device=TEST_DEVICE,
      )
  
      AC_per_class_average = accuracy_calculator.AccuracyCalculator(
          exclude=("NMI", "AMI"),
          avg_of_avgs=True,
          label_comparison_fn=label_comparison_fn,
          device=TEST_DEVICE,
      )
  
      query_labels = [
          (0, 2),
          (0, 2),
          (0, 2),
          (0, 2),
          (0, 2),
          (0, 2),
          (0, 2),
          (0, 2),
          (0, 2),
          (1, 2),
      ]
  
      reference_labels = [
          (1, 3),
          (0, 3),
          (0, 3),
          (0, 3),
          (0, 3),
          (0, 3),
          (0, 3),
          (0, 3),
          (0, 3),
          (0, 3),
      ]
  
      if use_numpy:
          query = np.arange(10)[:, None]
          reference = np.arange(10)[:, None]
          query_labels = np.array(query_labels)
          reference_labels = np.array(reference_labels)
      else:
          query = torch.arange(10, device=TEST_DEVICE).unsqueeze(1)
          reference = torch.arange(10, device=TEST_DEVICE).unsqueeze(1)
          query_labels = torch.tensor(query_labels, device=TEST_DEVICE)
          reference_labels = torch.tensor(
              reference_labels, device=TEST_DEVICE
          )
  
      query[-1] = 100
      reference[0] = -100
  
      acc = AC_global_average.get_accuracy(
          query, query_labels, reference, reference_labels, False
      )
      self.assertTrue(isclose(acc["precision_at_1"], 0.9))
      self.assertTrue(isclose(acc["r_precision"], 0.9))
      self.assertTrue(isclose(acc["mean_average_precision_at_r"], 0.9))
      self.assertTrue(
          isclose(acc["mean_average_precision"], 0.9 + 0.01)
      )
  
      acc = AC_per_class_average.get_accuracy(
          query, query_labels, reference, reference_labels, False
      )
      self.assertTrue(isclose(acc["precision_at_1"], 0.5))
      self.assertTrue(isclose(acc["r_precision"], 0.5))
      self.assertTrue(isclose(acc["mean_average_precision_at_r"], 0.5))
      self.assertTrue(
          isclose(acc["mean_average_precision"], (1 + 0.1) / 2)
      )
  
      query_labels = [
          (1, 3),
          (7, 3),
      ]
  
      reference_labels = [
          (1, 3),
          (7, 4),
          (1, 4),
          (1, 5),
          (1, 6),
      ]
  
      # SIMPLE CASE
      if use_numpy:
          query = np.arange(2)[:, None]
          reference = np.arange(5)[:, None]
          query_labels = np.array(query_labels)
          reference_labels = np.array(reference_labels)
      else:
          query = torch.arange(2, device=TEST_DEVICE).unsqueeze(1)
          reference = torch.arange(5, device=TEST_DEVICE).unsqueeze(1)
          query_labels = torch.tensor(query_labels, device=TEST_DEVICE)
          reference_labels = torch.tensor(
              reference_labels, device=TEST_DEVICE
          )
  
      correct = {
          "precision_at_1": 0.5,
          "r_precision": (1.0 / 3 + 1) / 2,
          "mean_average_precision_at_r": ((1.0 / 3) / 3 + 1) / 2,
          "mean_average_precision": (
              (1.0 / 3 + 2.0 / 4 + 3.0 / 5) / 3 + 1
          )
          / 2,
      }
  
      acc = AC_global_average.get_accuracy(
          query, query_labels, reference, reference_labels, False
      )
  
      for k in correct:
          self.assertTrue(isclose(acc[k], correct[k]))
  
      acc = AC_per_class_average.get_accuracy(
          query, query_labels, reference, reference_labels, False
      )
  
      for k in correct:
          self.assertTrue(isclose(acc[k], correct[k]))
  
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 4 for calling the TestCalculateAccuraciesAndFaiss obj's underlying member method code with example usage: obj._test_accuracy_calculator_custom_comparison_function(use_numpy) and returns: unknown