Skip to contents

Creates a diagonal matrix from a 1-D tensor.

Usage

nv_diag(x)

Arguments

x

(tensorish)
A 1-D tensor of length n whose elements become the diagonal entries.

Value

tensorish
An n x n matrix with x on the diagonal and zeros elsewhere.

Examples

jit_eval({
  nv_diag(nv_tensor(c(1, 2, 3)))
})
#> AnvilTensor
#>  1 0 0
#>  0 2 0
#>  0 0 3
#> [ CPUf32{3,3} ]