Skip to main content

transpose

Function transpose 

Source
pub fn transpose<T: Copy + Send + Sync>(
    input: &[T],
    output: &mut [T],
    width: usize,
    height: usize,
)
Expand description

Transpose a matrix from row-major input to row-major output.

Given an input matrix with height rows and width columns, produces an output matrix with width rows and height columns.

§Memory Layout

Both input and output are stored in row-major order.

    Input (height=2, width=3):       Output (height=3, width=2):

    Row 0: [ a, b, c ]               Row 0: [ a, d ]
    Row 1: [ d, e, f ]               Row 1: [ b, e ]
                                     Row 2: [ c, f ]

    Memory: [a, b, c, d, e, f]       Memory: [a, d, b, e, c, f]

§Index Transformation

  • Initial element at input[row * width + col],
  • Transposed position is output[col * height + row].

§Arguments

  • input - Source matrix in row-major order
  • output - Destination buffer in row-major order
  • width - Number of columns in the input matrix
  • height - Number of rows in the input matrix

§Panics

Panics if:

  • input.len() != width * height
  • output.len() != width * height