def _contrastive(self, feats_, labels_):
    (anchor_num, n_view) = (feats_.shape[0], feats_.shape[1])
    labels_ = labels_.contiguous().view((- 1), 1)
    mask = torch.eq(labels_, torch.transpose(labels_, 0, 1)).float().cuda()
    contrast_count = n_view
    contrast_feature = torch.cat(torch.unbind(feats_, dim=1), dim=0)
    anchor_feature = contrast_feature
    anchor_count = contrast_count
    anchor_dot_contrast = torch.div(torch.matmul(anchor_feature, torch.transpose(contrast_feature, 0, 1)), self.temperature)
    (logits_max, _) = torch.max(anchor_dot_contrast, dim=1, keepdim=True)
    logits = (anchor_dot_contrast - logits_max.detach())
    mask = mask.repeat(anchor_count, contrast_count)
    neg_mask = (1 - mask)
    logits_mask = torch.ones_like(mask).scatter_(1, torch.arange((anchor_num * anchor_count)).view((- 1), 1).cuda(), 0)
    mask = (mask * logits_mask)
    neg_logits = (torch.exp(logits) * neg_mask)
    neg_logits = neg_logits.sum(1, keepdim=True)
    exp_logits = torch.exp(logits)
    log_prob = (logits - torch.log((exp_logits + neg_logits)))
    mean_log_prob_pos = ((mask * log_prob).sum(1) / mask.sum(1))
    loss = ((- (self.temperature / self.base_temperature)) * mean_log_prob_pos)
    loss = loss.mean()
    return loss
def _contrastive(self, feats_, labels_):
    (anchor_num, n_view) = (feats_.shape[0], feats_.shape[1])
    labels_ = labels_.contiguous().view((- 1), 1)
    mask = torch.eq(labels_, torch.transpose(labels_, 0, 1)).float().cuda()
    contrast_count = n_view
    contrast_feature = torch.cat(torch.unbind(feats_, dim=1), dim=0)
    anchor_feature = contrast_feature
    anchor_count = contrast_count
    anchor_dot_contrast = torch.div(torch.matmul(anchor_feature, torch.transpose(contrast_feature, 0, 1)), self.temperature)
    (logits_max, _) = torch.max(anchor_dot_contrast, dim=1, keepdim=True)
    logits = (anchor_dot_contrast - logits_max.detach())
    mask = mask.repeat(anchor_count, contrast_count)
    neg_mask = (1 - mask)
    logits_mask = torch.ones_like(mask).scatter_(1, torch.arange((anchor_num * anchor_count)).view((- 1), 1).cuda(), 0)
    mask = (mask * logits_mask)
    neg_logits = (torch.exp(logits) * neg_mask)
    neg_logits = neg_logits.sum(1, keepdim=True)
    exp_logits = torch.exp(logits)
    log_prob = (logits - torch.log((exp_logits + neg_logits)))
    mean_log_prob_pos = ((mask * log_prob).sum(1) / mask.sum(1))
    loss = ((- (self.temperature / self.base_temperature)) * mean_log_prob_pos)
    loss = loss.mean()
    return loss