Skip to contents

Reinterprets the bits of an array as a different data type without modifying the underlying data.

Usage

prim_bitcast_convert(x, dtype)

Arguments

x

(arrayish)
Arrayish value of any data type.

dtype

(character(1) | DataType)
Target data type. If it has the same bit width as the input, the output shape is unchanged. If narrower, an extra trailing axis is added. If wider, the last axis is consumed.

Value

arrayish
Has the given dtype.

Implemented Rules

  • stablehlo

  • reverse

StableHLO

Lowers to hlo_bitcast_convert().

Examples

x <- nv_array(1L)
prim_bitcast_convert(x, dtype = "i8")
#> AnvlArray
#>  1 0 0 0
#> [ CPUi8{1,4} ] 
x <- nv_array(rep(1L, 4), dtype = "i8")
prim_bitcast_convert(x, dtype = "i32")
#> AnvlArray
#>  1.6843e+07
#> [ CPUi32{} ]