Triu

## triu(input, diagonal=0, out=NULL) -> Tensor

Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices
`input`

, the other elements of the result tensor `out`

are set to 0.

The upper triangular part of the matrix is defined as the elements on and above the diagonal.

The argument `diagonal`

controls which diagonal to consider. If
`diagonal`

= 0, all elements on and above the main diagonal are
retained. A positive value excludes just as many diagonals above the main
diagonal, and similarly a negative value includes just as many diagonals below
the main diagonal. The main diagonal are the set of indices
\(\lbrace (i, i) \rbrace\) for \(i \in [0, \min\{d_{1}, d_{2}\} - 1]\) where
\(d_{1}, d_{2}\) are the dimensions of the matrix.

## Examples

```
if (torch_is_installed()) {
a = torch_randn(c(3, 3))
a
torch_triu(a)
torch_triu(a, diagonal=1)
torch_triu(a, diagonal=-1)
b = torch_randn(c(4, 6))
b
torch_triu(b, diagonal=1)
torch_triu(b, diagonal=-1)
}
#> torch_tensor
#> 0.9049 2.4049 0.6814 -0.8608 0.8645 -1.2702
#> 0.3937 -0.5322 -1.8465 0.4023 -1.6824 0.6052
#> 0.0000 -0.0315 -0.2579 -0.0215 0.5096 0.5564
#> 0.0000 0.0000 0.0134 0.7134 0.3574 0.5761
#> [ CPUFloatType{4,6} ]
```