import torch


def get_valid_positive_mask(labels):

	"""
	To be a valid positive pair (a,p),
		- a and p are different embeddings
		- a and p have the same label
	"""
	indices_equal = torch.eye(labels.size(0)).byte()
	indices_not_equal = ~indices_equal

	label_equal = torch.eq(labels.unsqueeze(1), labels.unsqueeze(0))

	mask = indices_not_equal & label_equal
	return mask