
Last chance! 50% off unlimited learning
Sale ends in
Triu_indices
torch_triu_indices(
row,
col,
offset = 0,
dtype = torch_long(),
device = "cpu",
layout = torch_strided()
)
(int
) number of rows in the 2-D matrix.
(int
) number of columns in the 2-D matrix.
(int
) diagonal offset from the main diagonal. Default: if not provided, 0.
(torch.dtype
, optional) the desired data type of returned tensor. Default: if NULL
, torch_long
.
(torch.device
, optional) the desired device of returned tensor. Default: if NULL
, uses the current device for the default tensor type (see torch_set_default_tensor_type
). device
will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.
(torch.layout
, optional) currently only support torch_strided
.
Returns the indices of the upper triangular part of a row
by
col
matrix in a 2-by-N Tensor, where the first row contains row
coordinates of all indices and the second row contains column coordinates.
Indices are ordered based on rows and then columns.
The upper triangular part of the matrix is defined as the elements on and above the diagonal.
The argument offset
controls which diagonal to consider. If
offset
= 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
# NOT RUN {
if (torch_is_installed()) {
# }
# NOT RUN {
a = torch_triu_indices(3, 3)
a
a = torch_triu_indices(4, 3, -1)
a
a = torch_triu_indices(4, 3, 1)
a
# }
# NOT RUN {
}
# }
Run the code above in your browser using DataLab