import torch


def smape(y, y_):
    """
    Symmetric mean absolute percentage error.
    :param y: target
    :param y_: prediction
    :return: SMAPE
    """
    return torch.mean(
        torch.sum(torch.abs(y_ - y) / (torch.abs(y) + torch.abs(y_)), dim=1)
        * (1.0 / y.shape[1]),
        dim=0,
    )