code: def test_matching_probas():
      num_classes = 11
      eps = 1e-8
      # Numpy
      embeddings_np = np.random.randn(2, 3, 7).astype(np.float32)
      test_embeddings_np = np.random.randn(2, 5, 7).astype(np.float32)
      targets_np = np.random.randint(num_classes, size=(2, 3))
  
      # PyTorch
      embeddings_th = torch.as_tensor(embeddings_np)
      test_embeddings_th = torch.as_tensor(test_embeddings_np)
      targets_th = torch.as_tensor(targets_np)
  
      probas_th = matching_probas(
          embeddings_th,
          targets_th,
          test_embeddings_th,
          num_classes,
          eps=eps,
      )
  
      assert probas_th.shape == (2, 11, 5)
      assert np.all(probas_th.numpy() >= 0.0)
      assert np.all(probas_th.numpy() <= 1.0)
      np.testing.assert_allclose(
          probas_th.sum(1).numpy(), 1.0, atol=1e-5
      )
  
      similarities_th = pairwise_cosine_similarity(
          embeddings_th, test_embeddings_th, eps=eps
      )
      exp_similarities_np = np.exp(similarities_th.numpy())
  
      probas_np = np.zeros((2, 11, 5), dtype=np.float32)
      for i in range(2):
          for j in range(3):
              l = targets_np[i, j]
              for k in range(5):
                  probas_np[i, l, k] += exp_similarities_np[
                      i, j, k
                  ] / np.sum(exp_similarities_np[i, :, k])
  
      np.testing.assert_allclose(
          probas_th.numpy(), probas_np, atol=1e-5
      )
  
file_path: pytorch-meta/torchmeta/tests/utils/test_matching.py
imports: import pytest
  from flaky import flaky
  import numpy
  import torch
  from torchmeta.utils.matching import pairwise_cosine_similarity, matching_log_probas, matching_probas, matching_loss
label_desc: Use image node_id 4 for calling a global function with example usage: test_matching_probas() without return types