Skip to content
fn

triu

→Tensor
triu(input: Tensor, diagonal: _int = ...)

Implementing kernel

C++ engine symbols that back this Python API.

Return the upper-triangular part of a 2-D-or-higher tensor.

Elements below the diagonal-th diagonal (where j < i + diagonal) are zeroed. Batched matrices are supported.

Parameters

inputTensor
Source tensor with ndim >= 2.
diagonalint= 0
Diagonal offset. Positive values exclude super-diagonals, negative values include sub-diagonals.

Returns

Tensor

Tensor of the same shape as input.

Notes

Together tril and triu decompose any matrix into its strict triangles plus the chosen diagonal.

Examples

>>> import lucid
>>> A = lucid.ones(3, 3)
>>> lucid.triu(A, diagonal=1)
tensor([[0., 1., 1.], [0., 0., 1.], [0., 0., 0.]])