

def logsumexp(array):
    if (len(array) == 0):
        return float('-inf')
    m = max(array)
    if (math.isinf(m) and (min(array) != (- m)) and all(((not math.isnan(a)) for a in array))):
        return m
    return (m + math.log(sum((math.exp((a - m)) for a in array))))

dataset/ETHPy150Open probcomp/bayeslite/src/math_util.py logsumexp/original