Skip to contents

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

Usage

nvl_bitcast_convert(operand, dtype)

Arguments

operand

(tensorish)
Tensorish value of any data type.

dtype

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

Value

tensorish
Has the given dtype.

Implemented Rules

  • stablehlo

  • backward

StableHLO

Lowers to stablehlo::hlo_bitcast_convert().

Examples

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