Skip to contents

Converts the elements of an array to a different data type.

Usage

prim_convert(operand, dtype, ambiguous = FALSE)

Arguments

operand

(arrayish)
Arrayish value of any data type.

dtype

(character(1) | tengen::DataType)
Target data type.

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.

Value

arrayish
Has the given dtype and the same shape as operand. Ambiguity is controlled by the ambiguous parameter.

Implemented Rules

  • stablehlo

  • quickr

  • reverse

StableHLO

Lowers to stablehlo::hlo_convert().

See also

Examples

x <- nv_array(c(1L, 2L, 3L))
prim_convert(x, dtype = "f32")
#> AnvlArray
#>  1
#>  2
#>  3
#> [ CPUf32{3} ]