code: def pairwise_distance_torch(embeddings, device):
      """Computes the pairwise distance matrix with numerical stability.
      output[i, j] = || feature[i, :] - feature[j, :] ||_2
      Args:
        embeddings: 2-D Tensor of size [number of data, feature dimension].
      Returns:
        pairwise_distances: 2-D Tensor of size [number of data, number of data].
      """
  
      # pairwise distance matrix with precise embeddings
      precise_embeddings = embeddings.to(dtype=torch.float32)
  
      c1 = torch.pow(precise_embeddings, 2).sum(axis=-1)
      c2 = torch.pow(precise_embeddings.transpose(0, 1), 2).sum(axis=0)
      c3 = precise_embeddings @ precise_embeddings.transpose(0, 1)
  
      c1 = c1.reshape((c1.shape[0], 1))
      c2 = c2.reshape((1, c2.shape[0]))
      c12 = c1 + c2
      pairwise_distances_squared = c12 - 2.0 * c3
  
      # Deal with numerical inaccuracies. Set small negatives to zero.
      pairwise_distances_squared = torch.max(
          pairwise_distances_squared, torch.tensor([0.0]).to(device)
      )
      # Get the mask where the zero distances are at.
      error_mask = pairwise_distances_squared.clone()
      error_mask[error_mask > 0.0] = 1.0
      error_mask[error_mask <= 0.0] = 0.0
  
      pairwise_distances = torch.mul(
          pairwise_distances_squared, error_mask
      )
  
      # Explicitly set diagonals to zero.
      mask_offdiagonals = torch.ones(
          (pairwise_distances.shape[0], pairwise_distances.shape[1])
      ) - torch.diag(torch.ones(pairwise_distances.shape[0]))
      pairwise_distances = torch.mul(
          pairwise_distances.to(device), mask_offdiagonals.to(device)
      )
      return pairwise_distances
  
file_path: backprop/backprop/utils/losses/triplet_loss.py
imports: import torch
  import torch.nn
label_desc: Use image node_id 1 for calling a global function with example usage: pairwise_distance_torch(embeddings, device) and returns: pairwise_distances