Skip to main content

singe_kernel/cpu/
shape.rs

1//! Copies, transposes, padding, slicing, tiling, and layout transforms.
2
3pub fn transpose_2d(input: &[f32], rows: usize, cols: usize) -> Vec<f32> {
4    let mut output = vec![0.0; input.len()];
5    for row in 0..rows {
6        for col in 0..cols {
7            output[col * rows + row] = input[row * cols + col];
8        }
9    }
10    output
11}
12
13pub fn pack_downsample_2d(input: &[f32], rows: usize, cols: usize, factor: usize) -> Vec<f32> {
14    let mut output = vec![0.0; input.len()];
15    let output_rows = rows / factor;
16    let output_cols = cols * factor;
17    for row in 0..output_rows {
18        for packed in 0..output_cols {
19            let offset = packed / cols;
20            let feature = packed % cols;
21            output[row * output_cols + packed] = input[(row * factor + offset) * cols + feature];
22        }
23    }
24    output
25}