code: def _compute_loss(self, mat, pos_mask, neg_mask):
      if pos_mask.bool().any() and neg_mask.bool().any():
          # if dealing with actual distances, use negative distances
          if not self.distance.is_inverted:
              mat = -mat
          mat = mat / self.temperature
          mat_max, _ = mat.max(dim=1, keepdim=True)
          mat = mat - mat_max.detach()  # for numerical stability
  
          denominator = lmu.logsumexp(
              mat,
              keep_mask=(pos_mask + neg_mask).bool(),
              add_one=False,
              dim=1,
          )
          log_prob = mat - denominator
          mean_log_prob_pos = (pos_mask * log_prob).sum(dim=1) / (
              pos_mask.sum(dim=1) + c_f.small_val(mat.dtype)
          )
  
          return {
              "loss": {
                  "losses": -mean_log_prob_pos,
                  "indices": c_f.torch_arange_from_size(mat),
                  "reduction_type": "element",
              }
          }
      return self.zero_losses()
  
file_path: pytorch-metric-learning/src/pytorch_metric_learning/losses/supcon_loss.py
imports: from ..distances import CosineSimilarity
  from ..reducers import AvgNonZeroReducer
  from ..utils import common_functions
  from ..utils import loss_and_miner_utils
  from .generic_pair_loss import GenericPairLoss
label_desc: Use image node_id 2 for calling the SupConLoss obj's underlying member method code with example usage: obj._compute_loss(mat, pos_mask, neg_mask) and returns: self, dict