Computes log(sum(exp(x))) for a numeric vector in a numerically
stable way.
Details
Subtracts the maximum before exponentiating to prevent overflow: $$\log\sum_i \exp(x_i) = \max_i x_i + \log\sum_i \exp(x_i - \max_i x_i)$$
Special cases:
If all entries are
-Inf, returns-Inf.If any entry is
Inf, returnsInf.Empty vector throws an error.
See also
logsumexp for binary operation