class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def log_mean_exp_trick(x, dim=-1, keepdim=False):
    &#34;&#34;&#34;Computes log(mean(exp(x), dim=dim, keepdim=keepdim)) safely.

    Uses the logsumexp trick for the computation of this quantity.
    &#34;&#34;&#34;
    N = x.size(dim)

    return log_sum_exp_trick(x, dim=dim, keepdim=keepdim) - np.log(N)</code></pre>
</details>
</dd>
<dt id="flow.utils.log_sum_exp_trick"><code class="name flex">
<span>def <span