Skip to content
fn

logsumexp_op

→TensorImplPtr
int logsumexp_op(const int & a, const int & axes, bool keepdims)

Python wrappers

Public Python APIs implemented by this engine symbol.

Numerically-stable log⁡∑iexp⁡(xi)\log \sum_i \exp(x_i) via the max-shift trick.

Composite over max_op + sub_op + exp_op + sum_op + log_op + add_op (+ squeeze_op). Subtracting the per-reduction-group max keeps the largest exponent argument at 00 so the rest underflow rather than overflow; the offset is added back outside the log. Gradient flows through MaxBackward, SubBackward, ExpBackward, SumBackward, LogBackward, and AddBackward automatically — no dedicated backward node is registered.

Math

y=m+ln⁡ ⁣(∑i∈axesexp⁡(xi−m)),m=max⁡i∈axesxi y = m + \ln \!\left( \sum_{i \in \mathrm{axes}} \exp(x_i - m) \right), \qquad m = \max_{i \in \mathrm{axes}} x_i

See Also

logaddexp_op — two-operand elementwise variant.

Parameters

aTensorImplPtr
Input tensor.
axesvector<int>
Axes to reduce. Negative values wrap modulo a.ndim. An empty list reduces over all axes per the primitive's convention.
keepdimsbool
If true, retain size-1 placeholders at the reduced positions. Otherwise, the reduced axes are squeezed off (in descending order so each remaining index stays valid through the sequential squeeze loop).

Returns

TensorImplPtr

Reduced tensor. Dtype matches a.

Notes

The intermediate max_op is computed with keepdims=true so the broadcast subtract is well defined; the optional axis collapse is done at the end on the keep-dim result.