import torch


def hinge_loss_rec(positive: torch.Tensor, negative: torch.Tensor, margin=1) -> torch.Tensor:
    """Hinge loss for recommendations"""
    dist = positive - negative
    return torch.sum(torch.maximum(margin - dist, torch.Tensor([0])))