import torch
from typing import Tuple
from typing import List


def correct(outputs: torch.Tensor, targets: torch.Tensor,
            top: Tuple[int, ...] = (1, )) -> List[torch.Tensor]:
    """
    Calculate how many examples are correct for multiple top-k values

    Parameters
    ----------
    outputs : torch.Tensor
    target : torch.Tensor
    top : Tuple[int], default (1, )

    Returns
    -------
    tops : List[torch.Tensor]
    """
    _, predictions = outputs.topk(max(top), dim=1, largest=True, sorted=True)
    targets = targets.view(-1, 1).expand_as(predictions)

    corrects = predictions.eq(targets).cpu().int().cumsum(1).sum(0)
    tops = list(map(lambda k: corrects.data[k - 1], top))
    return tops