import torch


def tp_fp_fn_with_ignore(preds, targets):
    """
    Calculates True Positives, False Positives and False Negatives ignoring pixels where the target is 255.

    Args:
        preds (float tensor): Prediction tensor
        targets (long tensor): Target tensor
        c_i (int, optional): Class value of target for the positive class. Defaults to 1.

    Returns:
        tps, fps, fns: True Positives, False Positives and False Negatives 
    """
    preds = preds.flatten()
    targets = targets.flatten()

    # ignore missing label pixels
    no_ignore = targets.ne(255)
    preds = preds.masked_select(no_ignore)
    targets = targets.masked_select(no_ignore)

    # calculate TPs/FPs/FNs on all water
    tps = torch.sum(preds * (targets == 1))
    fps = torch.sum(preds) - tps
    fns = torch.sum(targets == 1) - tps

    return tps, fps, fns