Skip to contents

Reshapes a tensor to a new shape without changing the underlying data. Returns the input unchanged if it already has the target shape.

Usage

nv_reshape(operand, shape)

Arguments

operand

(tensorish)
Operand.

shape

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

Value

tensorish
Has the given shape and the same data type as operand.

Details

Note that row-major order is used, which differs from R's column-major order.

See also

nvl_reshape() for the underlying primitive.

Examples

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