Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.

tch_eye(n, m = n, dtype = NULL, layout = NULL, device = NULL,
  requires_grad = FALSE)

Arguments

n

integer. The number of rows.

m

(optional) integer. The number of columns with default being n.

dtype

the desired data type of returned tensor. Default: if NULL, infers data type from x.

device

the desired device of returned tensor. Default: if NULL, uses the current device for the default tensor type (see tch_set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

requires_grad

If autograd should record operations on the returned tensor. Default: FALSE.

the

desired layout of returned Tensor. Default: 'strided'

Examples

tch_eye(3)
#> tensor #> 1 0 0 #> 0 1 0 #> 0 0 1 #> [ Variable[CPUFloatType]{3,3} ]
tch_eye(2, 4)
#> tensor #> 1 0 0 0 #> 0 1 0 0 #> [ Variable[CPUFloatType]{2,4} ]