Working schemes

This commit is contained in:
Pro7ech
2025-11-19 09:26:52 +01:00
parent 48757fac7c
commit c23cf7803b
3 changed files with 8 additions and 5 deletions

View File

@@ -14,7 +14,7 @@ use poulpy_core::{
}; };
use poulpy_hal::api::{ModuleN, ScratchTakeBasic}; use poulpy_hal::api::{ModuleN, ScratchTakeBasic};
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, Stats}; use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, Stats, ZnxZero};
pub struct FheUintPreparedDebug<D: Data, T: UnsignedInteger> { pub struct FheUintPreparedDebug<D: Data, T: UnsignedInteger> {
pub(crate) bits: Vec<GGSW<D>>, pub(crate) bits: Vec<GGSW<D>>,
@@ -99,6 +99,7 @@ impl<D: DataRef, T: UnsignedInteger + ToBits> FheUintPreparedDebug<D, T> {
for (i, ggsw) in self.bits.iter().enumerate() { for (i, ggsw) in self.bits.iter().enumerate() {
use poulpy_hal::layouts::ZnxViewMut; use poulpy_hal::layouts::ZnxViewMut;
let (mut pt_want, scratch_1) = scratch.take_scalar_znx(self.n().into(), 1); let (mut pt_want, scratch_1) = scratch.take_scalar_znx(self.n().into(), 1);
pt_want.zero();
pt_want.at_mut(0, 0)[0] = want.bit(i) as i64; pt_want.at_mut(0, 0)[0] = want.bit(i) as i64;
stats.push(ggsw.noise(module, row, col, &pt_want, sk, scratch_1)); stats.push(ggsw.noise(module, row, col, &pt_want, sk, scratch_1));
} }

View File

@@ -84,8 +84,10 @@ where
for row in 0..c_enc_prep_debug.dnum().as_usize() { for row in 0..c_enc_prep_debug.dnum().as_usize() {
for col in 0..c_enc_prep_debug.rank().as_usize() + 1 { for col in 0..c_enc_prep_debug.rank().as_usize() + 1 {
let stats: Vec<Stats> = c_enc_prep_debug.noise(module, row, col, value, sk_glwe_prep, scratch.borrow()); let stats: Vec<Stats> = c_enc_prep_debug.noise(module, row, col, value, sk_glwe_prep, scratch.borrow());
for stat in &stats { for (i, stat) in stats.iter().enumerate() {
assert!(stat.std().log2() <= max_noise(col)) let noise_have: f64 = stat.std().log2();
let noise_max: f64 = max_noise(col);
assert!(noise_have <= noise_max, "bit: {i} noise_have: {noise_have} > noise_max: {noise_max}")
} }
} }
} }