Skip to contents

Creates an array with values increasing along the specified dimension, starting from start.

nv_iota_like() is a variant where dtype, shape, ambiguous, and device default to those of like.

Usage

nv_iota(dim, dtype, shape, start = 1L, ambiguous = FALSE, device = NULL)

nv_iota_like(
  like,
  dim,
  shape = NULL,
  start = 1L,
  dtype = NULL,
  ambiguous = NULL,
  device = NULL
)

Arguments

dim

(integer(1))
Dimension along which values increase.

dtype

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

shape

(integer())
Shape.

start

(integer(1))
Starting value (default 1).

ambiguous

(logical(1))
Whether the type is ambiguous. Ambiguous types usually arise from R literals (e.g., 1L, 1.0) and follow special promotion rules. See the vignette("type-promotion") for more details.

device

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

like

(AnvlArray)
Existing array whose attributes are used as defaults (only for nv_iota_like()).

Value

arrayish
Has the given dtype and shape.

See also

nv_seq() for a simpler 1-D sequence, prim_iota() for the underlying primitive.

Examples

nv_iota(dim = 1L, dtype = "i32", shape = 5L)
#> AnvlArray
#>  1
#>  2
#>  3
#>  4
#>  5
#> [ CPUi32{5} ] 
x <- nv_array(matrix(0L, nrow = 2, ncol = 3))
nv_iota_like(x, dim = 1L)
#> AnvlArray
#>  1 1 1
#>  2 2 2
#> [ CPUi32{2,3} ]