Shorthands for nv_array() with the data type fixed by the function name:
nv_float32(data) is nv_array(data, dtype = "f32").
| Function | Data type |
nv_bool() | bool |
nv_int8() | i8 |
nv_int16() | i16 |
nv_int32() | i32 |
nv_int64() | i64 |
nv_uint8() | ui8 |
nv_uint16() | ui16 |
nv_uint32() | ui32 |
nv_uint64() | ui64 |
nv_float32() | f32 |
nv_float64() | f64 |
Usage
nv_bool(data, shape = NULL, device = NULL, byrow = FALSE)
nv_int8(data, shape = NULL, device = NULL, byrow = FALSE)
nv_int16(data, shape = NULL, device = NULL, byrow = FALSE)
nv_int32(data, shape = NULL, device = NULL, byrow = FALSE)
nv_int64(data, shape = NULL, device = NULL, byrow = FALSE)
nv_uint8(data, shape = NULL, device = NULL, byrow = FALSE)
nv_uint16(data, shape = NULL, device = NULL, byrow = FALSE)
nv_uint32(data, shape = NULL, device = NULL, byrow = FALSE)
nv_uint64(data, shape = NULL, device = NULL, byrow = FALSE)
nv_float32(data, shape = NULL, device = NULL, byrow = FALSE)
nv_float64(data, shape = NULL, device = NULL, byrow = FALSE)Arguments
- data
(any)
integer(),double(), orlogical()scalar, vector, or array. Alternatively araw()vector holding the native little-endian byte payload ofprod(shape)elements ofdtype; bothdtypeandshapeare then required (only supported on the"pjrt"backend). Raw payloads are read in column-major element order, or row-major withbyrow = TRUE. An existingAnvlArrayis returned unchanged if theshape,dtypeanddevicegiven agree with it, and is an error otherwise.- shape
(
NULL|integer())
The output shape of the array. The default (NULL) is to infer it from the data if possible. Note thatnv_arrayinterprets length 1 vectors as having shape(1). Empty data has no shape to infer –0,c(2, 0)andc(0, 3)all hold no elements – soshapeis required there. To create a "scalar" with no axes (shape()), usenv_scalaror explicitly specifyshape = integer().- 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. It must belong to the active backend (active_backend()); a device of another backend is an error.
The default (
NULL) usesdefault_device().- byrow
(
logical(1))
When constructing from an R object and the result has at least two axes, fill the array in row-major order rather than the default column-major order. Only allowed whendatais an R object — passing an existingAnvlArraytogether withbyrow = TRUEis an error.
Out of Range values
Because base R has fewer data types than anvl, creating AnvlArrays from R often involves
type conversions.
When such conversions are performed, anvl performs a scan of the inputs to ensure that the
requested data type can actually hold the input data.
For example, trying to create an unsigned integer from a negative R integer() fails.
The same holds where an R value takes its data type from the array it meets
rather than from an argument: nv_scalar(1L, "ui8") + (-2L) is refused, where
converting an array with nv_convert() wraps around.
See also
nv_array(), nv_convert() to change the data type of an existing array.