Skip to contents

Converts the elements of an array to a different data type. Bare R inputs are directly materialized at the requested data type and are checked for out-of-range or missing values.

Usage

prim_convert(x, dtype)

Arguments

x

(arrayish)
One input. Can be any data type. An R value materializes at its default data type.

dtype

(character(1) | DataType)
Target data type. Can be any data type; the conversion is a value conversion, so it may lose precision or wrap around.

Value

(arrayish)
Has the given dtype and the input's shape.

Implemented Rules

  • stablehlo

  • quickr

  • reverse

StableHLO

Lowers to hlo_convert(), specified under convert.

See also

Examples

# the values are preserved, the data type changes
x <- nv_array(c(1L, 2L, 3L))
prim_convert(x, dtype = "f32")
#> AnvlArray
#>  1
#>  2
#>  3
#> [ CPUf32{3} ]