import torch


def cal_negative_logistic_loss(preds, targets, reduction="mean", **kwargs):
    """
    preds: (batch_size, vector_size)
    targets: (batch_size, vector_size)
    """
    # (batch_size, )
    scalar_product = torch.matmul(preds, targets.transpose(0, 1)).diagonal()
    loss = torch.log(1 + torch.exp(scalar_product))
    if reduction == "mean":
        loss = torch.mean(loss)
    elif reduction == "sum":
        loss = torch.sum(loss)
    return loss