Creates an array with values increasing along the specified axis,
starting from start.
nv_iota_like() is a variant where dtype, shape, and
device default to those of like.
Usage
nv_iota(axis, dtype, shape, start = 1L, device = NULL)
nv_iota_like(like, axis, shape = NULL, start = 1L, dtype = NULL, device = NULL)Arguments
- axis
(
integer(1))
Axis along which values increase. Negative values count from the end ofshape, i.e.-1refers to the last axis.- dtype
(
character(1)|DataType)
Data type of the result, required here. Can be any numeric data type. Fornv_iota_like()it may beNULL, which usesdtype(like).- shape
(
integer())
Shape of the result.- start
(
integer(1))
Starting value (default 1). Built atdtype, as the increments are.- device
(
NULL|character(1)| device)
The device the data lives on, given either as:a device string naming the platform (e.g.
"cpu","cuda","cuda:<n>"), which is resolved against the backend in use, ora device object as returned by
nv_device(): aPJRTDevicefor the"pjrt"backend or aquickr_devicefor the"quickr"backend. Because a device object is backend-specific, it also determines the backend.
The default (
NULL) usesdefault_device().- like
(
AnvlArray)
Existing array whose attributes are used as defaults (only fornv_iota_like()).
Value
(arrayish)
Has the given dtype and shape.
See also
nv_seq() for a simpler 1-D sequence, nv_linspace() for evenly
spaced values, prim_iota() for the underlying primitive.
Examples
# the sequence is built at the requested data type
nv_iota(axis = 1L, dtype = "i32", shape = 5L)
#> AnvlArray
#> 1
#> 2
#> 3
#> 4
#> 5
#> [ CPUi32{5} ]
# `_like` takes shape, data type and device from an existing array
x <- nv_fill(0L, shape = c(2, 3))
nv_iota_like(x, axis = 1L)
#> AnvlArray
#> 1 1 1
#> 2 2 2
#> [ CPUi32{2,3} ]