logsumexp

Undocumented in source. Be warned that the author may not have intended to support it.
pure nothrow @nogc
logsumexp
(
S
)
(
S x
)
if (
isSlice!S &&
)

Examples

import numir;
import mir.ndslice;

// import mir.math;
import std.math;

// FIXME: add static after dmd 2.082.0 fixed
immutable x = [-1.0, 2.0, 3.0];
immutable e = log(exp(-1.0) + exp(2.0) + exp(3.0));
assert(approxEqual(x.sliced.logsumexp, e));
immutable xs = [-1.0, 2.0, 3.0, -1.0, 2.0, 3.0, -1.0, 2.0, 3.0];
immutable es = [e, e, e];
assert(approxEqual(xs.sliced(3, 3).alongDim!1
        .map!logsumexp, es));

Meta