import torch


def nav_error(target, prediction, args):
    """ Calculate Navigation Error (in metre) between 2 points that are in metres

    Args:
        target (torch[.cuda].LongTensor): (batch_size, timesteps, 2)
        prediction (torch[.cuda].LongTensor): (batch_size, timesteps, 2)
        args

    Returns:
        error (torch[.cuda].FloatTensor): Timestep-wise nav error
                                          shape: (batch_size, timesteps)
        averaged_error (float): Nav Error averaged over timesteps
                                shape: (batch_size)
    """
    error_yx_metre = prediction - target
    error = (error_yx_metre[:, :, 0]**2 + error_yx_metre[:, :, 1]**2)**0.5

    averaged_error = torch.sum(error, dim=1).float()/ args.timesteps

    return error, averaged_error