import torch


def get_top_k(k, outputs, compare):
    """
    Returns the number of elements in ``compare`` for which the corresponding
    entry in ``outputs`` has the value of ``compare`` in its top-k.
    """
    rep_compare = compare.unsqueeze(1).repeat(1, k)
    return torch.sum((outputs.topk(k)[1] == rep_compare)).item()