If input is a vector (1-D tensor), then returns a 2-D square tensor with the elements of input as the diagonal. If input is a tensor with more than one dimension, then returns a 2-D tensor with diagonal elements equal to a flattened input. The argument offset controls which diagonal to consider:
tch_diagflat(x, offset = 0)
x | tensor object |
---|---|
offset | the offset to consider |
If offset = 0, it is the main diagonal.
If offset > 0, it is above the main diagonal.
If offset < 0, it is below the main diagonal.
#> tensor #> 1 0 0 0 0 0 0 0 0 0 #> 0 2 0 0 0 0 0 0 0 0 #> 0 0 3 0 0 0 0 0 0 0 #> 0 0 0 4 0 0 0 0 0 0 #> 0 0 0 0 5 0 0 0 0 0 #> 0 0 0 0 0 6 0 0 0 0 #> 0 0 0 0 0 0 7 0 0 0 #> 0 0 0 0 0 0 0 8 0 0 #> 0 0 0 0 0 0 0 0 9 0 #> 0 0 0 0 0 0 0 0 0 10 #> [ Variable[CPUIntType]{10,10} ]