Skip to contents

Converts the elements of a tensor to a different data type.

Usage

nvl_convert(operand, dtype, ambiguous = FALSE)

Arguments

operand

(tensorish)
Tensorish value of any data type.

dtype

(character(1) | stablehlo::TensorDataType)
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

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

Implemented Rules

  • stablehlo

  • backward

StableHLO

Lowers to stablehlo::hlo_convert().

See also

Examples

jit_eval({
  x <- nv_tensor(c(1L, 2L, 3L))
  nvl_convert(x, dtype = "f32")
})
#> AnvilTensor
#>  1
#>  2
#>  3
#> [ CPUf32{3} ]