mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
[ring]: added ring degree switching
This commit is contained in:
@@ -100,9 +100,17 @@ impl Table<u64> {
|
||||
let n: usize = a.len();
|
||||
assert!(
|
||||
n & n - 1 == 0,
|
||||
"invalid x.len()= {} must be a power of two",
|
||||
"invalid a.len()={} must be a power of two",
|
||||
n
|
||||
);
|
||||
|
||||
assert!(
|
||||
n <= self.psi_forward_rev.len(),
|
||||
"invalid a.len()={} > psi_forward_rev.len()={}",
|
||||
n,
|
||||
self.psi_forward_rev.len()
|
||||
);
|
||||
|
||||
let log_n: u32 = usize::BITS - ((n as usize) - 1).leading_zeros();
|
||||
|
||||
let start: u32 = SKIPSTART as u32;
|
||||
@@ -204,6 +212,14 @@ impl Table<u64> {
|
||||
"invalid x.len()= {} must be a power of two",
|
||||
n
|
||||
);
|
||||
|
||||
assert!(
|
||||
n <= self.psi_backward_rev.len(),
|
||||
"invalid a.len()={} > psi_backward_rev.len()={}",
|
||||
n,
|
||||
self.psi_backward_rev.len()
|
||||
);
|
||||
|
||||
let log_n = usize::BITS - ((n as usize) - 1).leading_zeros();
|
||||
|
||||
let start: u32 = SKIPEND as u32;
|
||||
|
||||
@@ -2,5 +2,6 @@ pub mod automorphism;
|
||||
pub mod rescaling_rns;
|
||||
pub mod ring;
|
||||
pub mod ring_rns;
|
||||
pub mod ring_switch;
|
||||
pub mod sampling;
|
||||
pub mod utils;
|
||||
|
||||
43
math/src/ring/impl_u64/ring_switch.rs
Normal file
43
math/src/ring/impl_u64/ring_switch.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use crate::poly::Poly;
|
||||
use crate::ring::Ring;
|
||||
|
||||
impl Ring<u64> {
|
||||
pub fn switch_degree<const NTT: bool>(
|
||||
&self,
|
||||
a: &Poly<u64>,
|
||||
buf: &mut Poly<u64>,
|
||||
b: &mut Poly<u64>,
|
||||
) {
|
||||
let (n_in, n_out) = (a.n(), b.n());
|
||||
|
||||
if n_in > n_out {
|
||||
let (gap_in, gap_out) = (1, n_in / n_out);
|
||||
if NTT {
|
||||
self.intt::<false>(&a, buf);
|
||||
b.0.iter_mut()
|
||||
.step_by(gap_in)
|
||||
.zip(buf.0.iter().step_by(gap_out))
|
||||
.for_each(|(x_out, x_in)| *x_out = *x_in);
|
||||
self.ntt_inplace::<false>(b);
|
||||
} else {
|
||||
b.0.iter_mut()
|
||||
.step_by(gap_in)
|
||||
.zip(a.0.iter().step_by(gap_out))
|
||||
.for_each(|(x_out, x_in)| *x_out = *x_in);
|
||||
}
|
||||
} else {
|
||||
let gap: usize = n_out / n_in;
|
||||
|
||||
if NTT {
|
||||
a.0.iter()
|
||||
.enumerate()
|
||||
.for_each(|(i, &c)| (0..gap).for_each(|j| b.0[i * gap + j] = c));
|
||||
} else {
|
||||
b.0.iter_mut()
|
||||
.step_by(gap)
|
||||
.zip(a.0.iter())
|
||||
.for_each(|(x_out, x_in)| *x_out = *x_in);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user