Skip to contents

Creates an n x n identity matrix.

nv_eye_like() is a variant where dtype and device default to those of like.

Usage

nv_eye(n, dtype = "f32", device = NULL)

nv_eye_like(like, n, dtype = NULL, device = NULL)

Arguments

n

(integer(1))
Size of the identity matrix.

dtype

(character(1) | tengen::DataType)
Data type.

device

( character(1) | PJRTDevice | quickr_device | NULL)
Device for data to live on.

like

(arrayish)
Existing array whose attributes are used as defaults (only for nv_eye_like()).

Value

arrayish
An n x n identity matrix.

See also

nv_diag() for general diagonal matrices.

Examples

nv_eye(3L)
#> AnvlArray
#>  1 0 0
#>  0 1 0
#>  0 0 1
#> [ CPUf32{3,3} ] 
x <- nv_array(matrix(0, nrow = 3, ncol = 3), dtype = "f64")
nv_eye_like(x, 3L)
#> AnvlArray
#>  1 0 0
#>  0 1 0
#>  0 0 1
#> [ CPUf64{3,3} ]