code: def helper(
      self,
      embeddings,
      labels,
      pos_pairs,
      neg_pairs,
      dtype,
      ref_emb=None,
      ref_labels=None,
  ):
      temperature = 0.1
      loss_funcA = NTXentLoss(temperature=temperature)
      loss_funcB = NTXentLoss(
          temperature=temperature, distance=LpDistance()
      )
      loss_funcC = NTXentLoss(
          temperature=temperature,
          reducer=PerAnchorReducer(AvgNonZeroReducer()),
      )
      loss_funcD = SupConLoss(temperature=temperature)
      loss_funcE = SupConLoss(
          temperature=temperature, distance=LpDistance()
      )
  
      obtained_losses = [
          x(embeddings, labels, ref_emb=ref_emb, ref_labels=ref_labels)
          for x in [
              loss_funcA,
              loss_funcB,
              loss_funcC,
              loss_funcD,
              loss_funcE,
          ]
      ]
  
      loss_len = 4 if ref_emb is not None else 5
      (
          total_lossA,
          total_lossB,
          total_lossC,
          total_lossD,
          total_lossE,
      ) = (
          0,
          0,
          torch.zeros(loss_len, device=TEST_DEVICE, dtype=dtype),
          torch.zeros(loss_len, device=TEST_DEVICE, dtype=dtype),
          torch.zeros(loss_len, device=TEST_DEVICE, dtype=dtype),
      )
      for a1, p in pos_pairs:
          anchor = embeddings[a1]
          positive = embeddings[p] if ref_emb is None else ref_emb[p]
          numeratorA = torch.exp(
              torch.matmul(anchor, positive) / temperature
          )
          numeratorB = torch.exp(
              -torch.sqrt(torch.sum((anchor - positive) ** 2))
              / temperature
          )
          denominatorA = numeratorA.clone()
          denominatorB = numeratorB.clone()
          denominatorD = 0
          denominatorE = 0
          for a2, n in pos_pairs + neg_pairs:
              if a2 == a1:
                  negative = (
                      embeddings[n] if ref_emb is None else ref_emb[n]
                  )
                  curr_denomD = torch.exp(
                      torch.matmul(anchor, negative) / temperature
                  )
                  curr_denomE = torch.exp(
                      -torch.sqrt(torch.sum((anchor - negative) ** 2))
                      / temperature
                  )
                  denominatorD += curr_denomD
                  denominatorE += curr_denomE
                  if (a2, n) not in pos_pairs:
                      denominatorA += curr_denomD
                      denominatorB += curr_denomE
              else:
                  continue
  
          curr_lossA = -torch.log(numeratorA / denominatorA)
          curr_lossB = -torch.log(numeratorB / denominatorB)
          curr_lossD = -torch.log(numeratorA / denominatorD)
          curr_lossE = -torch.log(numeratorB / denominatorE)
          total_lossA += curr_lossA
          total_lossB += curr_lossB
          total_lossC[a1] += curr_lossA
          total_lossD[a1] += curr_lossD
          total_lossE[a1] += curr_lossE
  
      total_lossA /= len(pos_pairs)
      total_lossB /= len(pos_pairs)
      if ref_emb is not None:
          pos_pair_per_anchor = torch.tensor([1, 1, 1, 1])
      else:
          pos_pair_per_anchor = torch.tensor([2, 2, 2, 1, 1])
      pos_pair_per_anchor = pos_pair_per_anchor.to(TEST_DEVICE).type(
          dtype
      )
      total_lossC, total_lossD, total_lossE = [
          torch.mean(x / pos_pair_per_anchor)
          for x in [total_lossC, total_lossD, total_lossE]
      ]
  
      rtol = 1e-2 if dtype == torch.float16 else 1e-5
      self.assertTrue(
          torch.isclose(obtained_losses[0], total_lossA, rtol=rtol)
      )
      self.assertTrue(
          torch.isclose(obtained_losses[1], total_lossB, rtol=rtol)
      )
      self.assertTrue(
          torch.isclose(obtained_losses[2], total_lossC, rtol=rtol)
      )
      self.assertTrue(
          torch.isclose(obtained_losses[3], total_lossD, rtol=rtol)
      )
      self.assertTrue(
          torch.isclose(obtained_losses[4], total_lossE, rtol=rtol)
      )
  
file_path: pytorch-metric-learning/tests/losses/test_ntxent_loss.py
imports: import unittest
  import torch
  from pytorch_metric_learning.distances import LpDistance
  from pytorch_metric_learning.losses import NTXentLoss, SupConLoss
  from pytorch_metric_learning.reducers import AvgNonZeroReducer, PerAnchorReducer
  from ..None import TEST_DEVICE, TEST_DTYPES
  from ..zzz_testing_utils.testing_utils import angle_to_coord
  from .utils import get_pair_embeddings_with_ref
label_desc: Use image node_id 3 for calling the TestNTXentLoss obj's underlying member method code with example usage: obj.helper(embeddings, labels, pos_pairs, neg_pairs, dtype, ref_emb, ref_labels) without return types