code: def mine(self, embeddings, labels, ref_emb, ref_labels):
      mat = self.distance(embeddings, ref_emb)
      a1, p, a2, n = lmu.get_all_pairs_indices(labels, ref_labels)
  
      if len(a1) == 0 or len(a2) == 0:
          empty = torch.tensor(
              [], device=labels.device, dtype=torch.long
          )
          return (
              empty.clone(),
              empty.clone(),
              empty.clone(),
              empty.clone(),
          )
  
      mat_neg_sorting = mat
      mat_pos_sorting = mat.clone()
  
      dtype = mat.dtype
      pos_ignore = (
          c_f.pos_inf(dtype)
          if self.distance.is_inverted
          else c_f.neg_inf(dtype)
      )
      neg_ignore = (
          c_f.neg_inf(dtype)
          if self.distance.is_inverted
          else c_f.pos_inf(dtype)
      )
  
      mat_pos_sorting[a2, n] = pos_ignore
      mat_neg_sorting[a1, p] = neg_ignore
      if embeddings is ref_emb:
          mat_pos_sorting.fill_diagonal_(pos_ignore)
          mat_neg_sorting.fill_diagonal_(neg_ignore)
  
      pos_sorted, pos_sorted_idx = torch.sort(mat_pos_sorting, dim=1)
      neg_sorted, neg_sorted_idx = torch.sort(mat_neg_sorting, dim=1)
  
      if self.distance.is_inverted:
          hard_pos_idx = torch.where(
              pos_sorted - self.epsilon < neg_sorted[:, -1].unsqueeze(1)
          )
          hard_neg_idx = torch.where(
              neg_sorted + self.epsilon > pos_sorted[:, 0].unsqueeze(1)
          )
      else:
          hard_pos_idx = torch.where(
              pos_sorted + self.epsilon > neg_sorted[:, 0].unsqueeze(1)
          )
          hard_neg_idx = torch.where(
              neg_sorted - self.epsilon < pos_sorted[:, -1].unsqueeze(1)
          )
  
      a1 = hard_pos_idx[0]
      p = pos_sorted_idx[a1, hard_pos_idx[1]]
      a2 = hard_neg_idx[0]
      n = neg_sorted_idx[a2, hard_neg_idx[1]]
  
      return a1, p, a2, n
  
file_path: pytorch-metric-learning/src/pytorch_metric_learning/miners/multi_similarity_miner.py
imports: import torch
  from ..distances import CosineSimilarity
  from ..utils import common_functions
  from ..utils import loss_and_miner_utils
  from .base_miner import BaseMiner
label_desc: Use image node_id 2 for calling the MultiSimilarityMiner obj's underlying member method code with example usage: obj.mine(embeddings, labels, ref_emb, ref_labels) and returns: a1,  p,  a2,  n, empty,  empty,  empty,  empty