code: def test_soft_triple_loss(self):
      embedding_size = 2
      num_classes = 11
      reg_weight = 0.2
      margin = 0.01
  
      for dtype in TEST_DTYPES:
          la = 1 if dtype == torch.float16 else 20
          gamma = 1 if dtype == torch.float16 else 0.1
          for centers_per_class in range(1, 12):
              if centers_per_class > 1:
                  weight_regularizer = SparseCentersRegularizer(
                      num_classes, centers_per_class
                  )
              else:
                  weight_regularizer = None
              loss_func = SoftTripleLoss(
                  num_classes,
                  embedding_size,
                  centers_per_class=centers_per_class,
                  la=la,
                  gamma=gamma,
                  margin=margin,
                  weight_regularizer=weight_regularizer,
                  weight_reg_weight=reg_weight,
              ).to(TEST_DEVICE)
              original_loss_func = OriginalImplementationSoftTriple(
                  la,
                  gamma,
                  reg_weight,
                  margin,
                  embedding_size,
                  num_classes,
                  centers_per_class,
              ).to(TEST_DEVICE)
  
              original_loss_func.fc.data = (
                  original_loss_func.fc.data.type(dtype)
              )
              loss_func.fc = original_loss_func.fc
  
              embedding_angles = torch.arange(0, 180)
              embeddings = torch.tensor(
                  [angle_to_coord(a) for a in embedding_angles],
                  requires_grad=True,
                  dtype=dtype,
              ).to(
                  TEST_DEVICE
              )  # 2D embeddings
              labels = torch.randint(low=0, high=10, size=(180,)).to(
                  TEST_DEVICE
              )
  
              loss = loss_func(embeddings, labels)
              loss.backward()
              correct_loss = original_loss_func(
                  F.normalize(embeddings), labels
              )
              self.assertTrue(torch.isclose(loss, correct_loss))
  
file_path: pytorch-metric-learning/tests/losses/test_soft_triple_loss.py
imports: import math
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn import init
  from torch.nn.parameter import Parameter
  from pytorch_metric_learning.utils import common_functions
  from ..zzz_testing_utils.testing_utils import angle_to_coord
  import unittest
  from pytorch_metric_learning.losses import SoftTripleLoss
  from pytorch_metric_learning.regularizers import SparseCentersRegularizer
  from ..None import TEST_DEVICE, TEST_DTYPES
label_desc: Use image node_id 1 for calling the TestSoftTripleLoss obj's underlying member method code with example usage: obj.test_soft_triple_loss() without return types