Skip to contents

Permutes the axes of an array.

Usage

prim_transpose(x, permutation)

Arguments

x

(arrayish)
One input. Can be any data type. An R value materializes at its default data type.

permutation

(integer())
Specifies the new ordering of axes. Must be a permutation of seq_len(naxes(x)), the axis indices of x. Negative values count from the end, i.e. -1 refers to the last axis.

Value

(arrayish)
Has the input's data type and shape shape(x)[permutation].

Implemented Rules

  • stablehlo

  • quickr

  • reverse

StableHLO

Lowers to hlo_transpose(), specified under transpose.

See also

Examples

# the 2x3 becomes a 3x2, keeping its data type
x <- nv_matrix(1:6, nrow = 2)
prim_transpose(x, permutation = c(2L, 1L))
#> AnvlArray
#>  1 2
#>  3 4
#>  5 6
#> [ CPUi32{3,2} ]