Skip to content
fn

cummax_op

→TensorImplPtr
int cummax_op(const int & a, int axis)

Python wrappers

Public Python APIs implemented by this engine symbol.

Inclusive cumulative maximum along a single axis, yk=max⁡j≤kxjy_k = \max_{j \le k} x_j.

Output is non-decreasing along axis. Backward credits the upstream gradient dykdy_k to the position that first achieved the running maximum up to kk (i.e. the unique i≤ki \le k at which the running max changed value); positions that merely tie with the running max receive no gradient.

Math

yk=max⁡j≤kxj,∂L∂xi=∑k≥idyk⋅1[ i=arg⁡max⁡j≤kxj ]. y_k = \max_{j \le k} x_j, \qquad \frac{\partial \mathcal{L}}{\partial x_i} = \sum_{k \ge i} dy_k \cdot \mathbb{1}[\,i = \arg\max_{j \le k} x_j\,].

Parameters

aTensorImplPtr
Input tensor of any non-scalar shape; only F32 / F64 are supported by the backward pass.
axisint
Axis along which to accumulate (negative wraps).

Returns

TensorImplPtr

Output tensor of the same shape and dtype as a.

Notes

Backward is computed by a right-to-left segmented accumulation on CPU (or evaluated on CPU after a GPU round-trip). Saves only the forward output; the input is not needed.