Skip to content
fn

tril_op

→TensorImplPtr
int tril_op(const int & a, int k)

Python wrappers

Public Python APIs implemented by this engine symbol.

Lower-triangular part of a matrix (or batch of matrices).

Zeros every element strictly above the k-th diagonal of the last two axes of a. The main diagonal is k = 0; positive k shifts the diagonal toward the upper-right (keeping more elements); negative k toward the lower-left (keeping fewer).

Math

a_{\ldots,i,j} & \text{if } j - i \le k \\ 0 & \text{otherwise} \end{cases}$$ **See Also** triu_op : Upper-triangular counterpart.

Parameters

aTensorImplPtr
Input tensor of rank ≥2\ge 2. The mask is applied to the trailing two axes; leading axes are treated as batch dimensions.
kint
Diagonal offset. Default 0 (main diagonal).

Returns

TensorImplPtr

Tensor of the same shape and dtype as a with the upper triangle (relative to k) zeroed.

Notes

Backward applies tril with the same k to the incoming gradient, preserving only the gradient at positions retained in the forward pass.