import torch


def pdist(vectors):
    """
    vectors shape: (batch_size, k-dimensions)
    compute the Euclidean distance between any two pairs.
    using formula distance = ||A - B||^2 = A'A + B'B - 2A'B
    note: A, B represent vector, respectively. A' denotes transpose of A
    :param vectors: embeddings of batch_size samples.
    :return: distance matrix
    """
    distance_matrix = -2 * vectors.mm(torch.t(vectors)) + vectors.pow(2).sum(dim=1).view(1, -1) + vectors.pow(2).sum(
        dim=1).view(-1, 1)
    return distance_matrix