@staticmethod
def euclidean_distance(F, X, Y, sqrt=False):
    """Compute the distance between each X and Y.

        Args:
            X: a (m x d) tensor
            Y: a (d x n) tensor
            sqrt:

        Returns:
            diffs: an m x n distance matrix.
        """
    XX = F.sum(F.square(X), 1, keepdims=True)
    YY = F.sum(F.square(Y), 0, keepdims=True)
    XY = F.dot(X, Y)
    diffs = XX + YY - 2 * XY
    diffs = F.relu(diffs)
    if sqrt:
        diffs = F.sqrt(diffs)
    return diffs
