poulpy/poulpy-hal/src/reference/znx/switch_ring.rs
poulpy-hal/src/reference/znx/switch_ring.rsRaw
1use crate::reference::znx::{copy::znx_copy_ref, zero::znx_zero_ref};
2
3pub fn znx_switch_ring_ref(res: &mut [i64], a: &[i64]) {
4 let (n_in, n_out) = (a.len(), res.len());
5
6 #[cfg(debug_assertions)]
7 {
8 assert!(n_in.is_power_of_two());
9 assert!(n_in.max(n_out).is_multiple_of(n_in.min(n_out)))
10 }
11
12 if n_in == n_out {
13 znx_copy_ref(res, a);
14 return;
15 }
16
17 let (gap_in, gap_out): (usize, usize);
18 if n_in > n_out {
19 (gap_in, gap_out) = (n_in / n_out, 1)
20 } else {
21 (gap_in, gap_out) = (1, n_out / n_in);
22 znx_zero_ref(res);
23 }
24
25 res.iter_mut()
26 .step_by(gap_out)
27 .zip(a.iter().step_by(gap_in))
28 .for_each(|(x_out, x_in)| *x_out = *x_in);
29}