import torch


def calc_clf_acc(logits, labels):
    """
    Args:
        logits:
            [batch_size, n_labels] FloatTensor or
            [batch_size] FloatTensor (i.e. when classifier is being trained with MSE)
        labels: [batch_size] LongTensor
    Returns: float
    """
    batch_size = logits.size(0)
    if logits.dim() == 1:
        indices = logits.round().long()
    else:
        _, indices = torch.max(logits, dim=1)
    acc = torch.eq(indices, labels).sum().float() / batch_size
    return acc