def precision(tp: int, fp: int, zero_division: int = 0) -> float:
    """Calculates precision (a.k.a. positive predictive value) for binary
    classification and segmentation.

    Args:
        tp: number of true positives
        fp: number of false positives
        zero_division: int value,
            should be one of 0 or 1; if both tp==0 and fp==0 return this
            value as s result

    Returns:
        precision value (0-1)
    """
    # originally precision is: ppv = tp / (tp + fp + eps)
    # but when both masks are empty this gives: tp=0 and fp=0 => ppv=0
    # so here precision is defined as ppv := 1 - fdr (false discovery rate)
    if tp == 0 and fp == 0:
        return zero_division
    return 1 - fp / (tp + fp)
Calculates precision (a.k.a. positive predictive value) for binary
    classification and segmentation.

    Args:
        tp: number of true positives
        fp: number of false positives
        zero_division: int value,
            should be one of 0 or 1; if both tp==0 and fp==0 return this
            value as s result

    Returns:
        precision value (0-1)
    
catalyst/metrics/functional/_classification.py