Converts the elements of an array to a different data type.
Note that R objects are handled differently than AnvlArray
inputs.
For R objects, we check whether the requested data type can
meaningfully hold the provided data and otherwise err.
For AnvlArray inputs such a check is not performed.
Value
(arrayish)
Has the given dtype and the input's shape.
See also
prim_convert() for the underlying primitive.
Examples
# the values are preserved, the data type changes
x <- nv_array(c(1L, 2L, 3L))
# For R inputs, we check compatability
nv_convert(x, dtype = "f32")
#> AnvlArray
#> 1
#> 2
#> 3
#> [ CPUf32{3} ]
try(nv_convert(257L, dtype = "i8"))
#> Error : Value 257 cannot be converted to "i8" without overflow.
# For AnvlArrays, we wrap around
nv_convert(nv_scalar(257L), dtype = "i8")
#> AnvlArray
#> 1
#> [ CPUi8{} ]