Skip to contents

Reshapes a tensor to a new shape without changing the underlying data. Note that row-major order is used, which differs from R's column-major order.

Usage

nvl_reshape(operand, shape)

Arguments

operand

(tensorish)
Tensorish value of any data type.

shape

(integer())
Target shape. Must have the same number of elements as operand.

Value

tensorish
Has the same data type as the input and the given shape. It is ambiguous if the input is ambiguous.

Implemented Rules

  • stablehlo

  • backward

StableHLO

Lowers to stablehlo::hlo_reshape().

See also

Examples

jit_eval({
  x <- nv_tensor(1:6)
  nvl_reshape(x, shape = c(2, 3))
})
#> AnvilTensor
#>  1 2 3
#>  4 5 6
#> [ CPUi32{2,3} ]