Skip to content
fn

triu_op

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

Python wrappers

Public Python APIs implemented by this engine symbol.

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

Zeros every element strictly below the k-th diagonal of the last two axes of a. Diagonal offset convention matches tril_op.

Math

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

Parameters

aTensorImplPtr
Input tensor of rank ≥2\ge 2.
kint
Diagonal offset. Default 0.

Returns

TensorImplPtr

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

Notes

Backward applies triu with the same k to the incoming gradient.