def METHOD_NAME(pred, targ, mask, reduce=True):
    if pred.ndim == 3:
        pred = pred.squeeze(2)
    else:
        assert pred.ndim == 2
    loss = (pred.float() - targ.float()).abs() * (~mask).float()
    loss = loss.sum() if reduce else loss.view(-1)
    return loss