def euclidean(feat, query, featl2norm=None, qryl2norm=None):
    """ Euclidean distance.
    Args:
        feat:       N x D feature matrix
        query:      Q x D feature vector
        featl2norm: 1 x N vector
        qryl2norm:  Q x 1 vector

    Returns:
        dist:       1 x N vector
    """
    dotprod = query.dot(feat.T)
    if qryl2norm is None:
        qryl2norm = (query ** 2).sum(1).reshape(-1, 1)
    if featl2norm is None:
        featl2norm = (feat ** 2).sum(1).reshape(1, -1)
    return -2 * dotprod + qryl2norm + featl2norm
