arnaucube
arnaucube/poulpyPublic Self-hosted repository
fixed overflow
Jean-Philippe Bossuat jeanphilippe.bossuat@gmail.com
Thu, 16 Jan 2025 17:59:01 +0100
commit

3b7d88997197eae0b16b1c5aa08f42240a0d0aff

parent

556346d623c5a433172c9e52a846f28ac55328d4

3 files changed, 18 insertions(+), 4 deletions(-)

jump to
M math/src/automorphism.rs → math/src/automorphism.rs

@@ -18,7 +18,12 @@ self.0.insert(perm.gal_el, perm);

gal_el } - pub fn gen<O: Unsigned, const NTT: bool>(&mut self, ring: &Ring<O>, gen_1: usize, gen_2: bool) -> usize { + pub fn gen<O: Unsigned, const NTT: bool>( + &mut self, + ring: &Ring<O>, + gen_1: usize, + gen_2: bool, + ) -> usize { self.insert(AutoPerm::new::<O, NTT>(ring, gen_1, gen_2)) }

@@ -27,7 +32,9 @@ self.0.get(gal_el)

} } +#[derive(Debug)] pub struct AutoPerm { + pub ntt: bool, pub gal_el: usize, pub permutation: Vec<usize>, }

@@ -64,6 +71,7 @@ }

} Self { + ntt: NTT, gal_el: gal_el, permutation: permutation, }
M math/src/ring.rs → math/src/ring.rs

@@ -45,11 +45,10 @@ gen_1_pow = gen_1_pow.wrapping_mul(gen_1_pow);

e >>= 1; } - let nth_root = 1 << self.cyclotomic_order; - gal_el &= nth_root - 1; + gal_el &= self.cyclotomic_order - 1; if gen_2 { - return nth_root - gal_el; + return self.cyclotomic_order - gal_el; } gal_el }
M math/src/ring/impl_u64/automorphism.rs → math/src/ring/impl_u64/automorphism.rs

@@ -158,6 +158,13 @@ a.n(),

b.n() ); + assert!( + NTT == auto_perm.ntt, + "missmatch between AutoPerm NTT flag={} and method NTT flag={}", + auto_perm.ntt, + NTT + ); + let b_vec: &mut Vec<u64> = &mut b.0; let a_vec: &Vec<u64> = &a.0;