Skip to contents

Reshapes an array 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

prim_reshape(x, shape)

Arguments

x

(arrayish)
Arrayish value of any data type.

shape

(integer())
Target shape. Must have the same number of elements as x. At most one entry may be -1, in which case its extent is inferred from the remaining entries and the number of elements of x.

Value

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

Implemented Rules

  • stablehlo

  • quickr

  • reverse

StableHLO

Lowers to hlo_reshape().

See also

Examples

x <- nv_array(1:6)
prim_reshape(x, shape = c(2, 3))
#> AnvlArray
#>  1 2 3
#>  4 5 6
#> [ CPUi32{2,3} ]