oneflow.tril

oneflow.tril()

Returns the lower triangular part of a matrix (2-D tensor) or batch of matrices input along the specified diagonal, the other elements of the result tensor out are set to 0.

Note

  • if diagonal = 0, the diagonal of the returned tensor will be the main diagonal,

  • if diagonal > 0, the diagonal of the returned tensor will be above the main diagonal,

  • if diagonal < 0, the diagonal of the returned tensor will be below the main diagonal.

Parameters
  • input (Tensor) – the input tensor.

  • diagonal (int, optional) – the diagonal to specify.

For example:

>>> import oneflow as flow
>>> import numpy as np

>>> x = flow.tensor(np.ones(shape=(3, 3)).astype(np.float32))
>>> flow.tril(x)
tensor([[1., 0., 0.],
        [1., 1., 0.],
        [1., 1., 1.]], dtype=oneflow.float32)