use backend::hal::{ api::{ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxAlloc, VecZnxStd, VecZnxSubScalarInplace, ZnxZero}, layouts::{Backend, DataRef, Module, ScalarZnx, ScratchOwned}, oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl}, }; use crate::{GGLWECiphertext, GLWECiphertext, GLWEDecryptFamily, GLWEPlaintext, GLWESecretExec, Infos}; impl GGLWECiphertext { pub fn assert_noise( self, module: &Module, sk: &GLWESecretExec, pt_want: &ScalarZnx, max_noise: f64, ) where DataSk: DataRef, DataWant: DataRef, Module: GLWEDecryptFamily + VecZnxStd + VecZnxAlloc + VecZnxSubScalarInplace, B: TakeVecZnxDftImpl + TakeVecZnxBigImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, { let digits: usize = self.digits(); let basek: usize = self.basek(); let k: usize = self.k(); let mut scratch: ScratchOwned = ScratchOwned::alloc(GLWECiphertext::decrypt_scratch_space(module, basek, k)); let mut pt: GLWEPlaintext> = GLWEPlaintext::alloc(module, basek, k); (0..self.rank_in()).for_each(|col_i| { (0..self.rows()).for_each(|row_i| { self.at(row_i, col_i) .decrypt(&module, &mut pt, &sk, scratch.borrow()); module.vec_znx_sub_scalar_inplace( &mut pt.data, 0, (digits - 1) + row_i * digits, pt_want, col_i, ); let noise_have: f64 = module.vec_znx_std(basek, &pt.data, 0).log2(); assert!( noise_have <= max_noise, "noise_have: {} > max_noise: {}", noise_have, max_noise ); pt.data.zero(); }); }); } }