Logsumexp implementation