import torch


def accuracy(predictions, labels):
    """
    Compute the average accuracy of the given predictions.
    Inspired on
    https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html
    Args:
        predictions (torch.Tensor): Tensor containing the output of the linear
            output layer of the network.
        labels (torch.Tensor): Tensor containing the labels of the mini-batch
    Returns (float): average accuracy of the given predictions
    """

    _, pred_labels = torch.max(predictions.data, 1)
    total = labels.size(0)
    correct = (pred_labels == labels).sum().item()

    return correct/total