use rand_distr::Distribution; use sampling::source::Source; use crate::hal::layouts::{Backend, Scratch, VecZnxBigOwned, VecZnxBigToMut, VecZnxBigToRef, VecZnxToMut, VecZnxToRef}; /// Allocates as [crate::hal::layouts::VecZnxBig]. pub trait VecZnxBigAlloc { fn vec_znx_big_alloc(&self, n: usize, cols: usize, size: usize) -> VecZnxBigOwned; } /// Returns the size in bytes to allocate a [crate::hal::layouts::VecZnxBig]. pub trait VecZnxBigAllocBytes { fn vec_znx_big_alloc_bytes(&self, n: usize, cols: usize, size: usize) -> usize; } /// Consume a vector of bytes into a [crate::hal::layouts::VecZnxBig]. /// User must ensure that bytes is memory aligned and that it length is equal to [VecZnxBigAllocBytes]. pub trait VecZnxBigFromBytes { fn vec_znx_big_from_bytes(&self, n: usize, cols: usize, size: usize, bytes: Vec) -> VecZnxBigOwned; } #[allow(clippy::too_many_arguments)] /// Add a discrete normal distribution on res. /// /// # Arguments /// * `basek`: base two logarithm of the bivariate representation /// * `res`: receiver. /// * `res_col`: column of the receiver on which the operation is performed/stored. /// * `k`: /// * `source`: random coin source. /// * `sigma`: standard deviation of the discrete normal distribution. /// * `bound`: rejection sampling bound. pub trait VecZnxBigAddNormal { fn vec_znx_big_add_normal>( &self, basek: usize, res: &mut R, res_col: usize, k: usize, source: &mut Source, sigma: f64, bound: f64, ); } #[allow(clippy::too_many_arguments)] pub trait VecZnxBigFillNormal { fn vec_znx_big_fill_normal>( &self, basek: usize, res: &mut R, res_col: usize, k: usize, source: &mut Source, sigma: f64, bound: f64, ); } #[allow(clippy::too_many_arguments)] pub trait VecZnxBigFillDistF64 { fn vec_znx_big_fill_dist_f64, D: Distribution>( &self, basek: usize, res: &mut R, res_col: usize, k: usize, source: &mut Source, dist: D, bound: f64, ); } #[allow(clippy::too_many_arguments)] pub trait VecZnxBigAddDistF64 { fn vec_znx_big_add_dist_f64, D: Distribution>( &self, basek: usize, res: &mut R, res_col: usize, k: usize, source: &mut Source, dist: D, bound: f64, ); } pub trait VecZnxBigAdd { /// Adds `a` to `b` and stores the result on `c`. fn vec_znx_big_add(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where R: VecZnxBigToMut, A: VecZnxBigToRef, C: VecZnxBigToRef; } pub trait VecZnxBigAddInplace { /// Adds `a` to `b` and stores the result on `b`. fn vec_znx_big_add_inplace(&self, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxBigToMut, A: VecZnxBigToRef; } pub trait VecZnxBigAddSmall { /// Adds `a` to `b` and stores the result on `c`. fn vec_znx_big_add_small(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where R: VecZnxBigToMut, A: VecZnxBigToRef, C: VecZnxToRef; } pub trait VecZnxBigAddSmallInplace { /// Adds `a` to `b` and stores the result on `b`. fn vec_znx_big_add_small_inplace(&self, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxBigToMut, A: VecZnxToRef; } pub trait VecZnxBigSub { /// Subtracts `a` to `b` and stores the result on `c`. fn vec_znx_big_sub(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where R: VecZnxBigToMut, A: VecZnxBigToRef, C: VecZnxBigToRef; } pub trait VecZnxBigSubABInplace { /// Subtracts `a` from `b` and stores the result on `b`. fn vec_znx_big_sub_ab_inplace(&self, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxBigToMut, A: VecZnxBigToRef; } pub trait VecZnxBigSubBAInplace { /// Subtracts `b` from `a` and stores the result on `b`. fn vec_znx_big_sub_ba_inplace(&self, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxBigToMut, A: VecZnxBigToRef; } pub trait VecZnxBigSubSmallA { /// Subtracts `b` from `a` and stores the result on `c`. fn vec_znx_big_sub_small_a(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where R: VecZnxBigToMut, A: VecZnxToRef, C: VecZnxBigToRef; } pub trait VecZnxBigSubSmallAInplace { /// Subtracts `a` from `res` and stores the result on `res`. fn vec_znx_big_sub_small_a_inplace(&self, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxBigToMut, A: VecZnxToRef; } pub trait VecZnxBigSubSmallB { /// Subtracts `b` from `a` and stores the result on `c`. fn vec_znx_big_sub_small_b(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize) where R: VecZnxBigToMut, A: VecZnxBigToRef, C: VecZnxToRef; } pub trait VecZnxBigSubSmallBInplace { /// Subtracts `res` from `a` and stores the result on `res`. fn vec_znx_big_sub_small_b_inplace(&self, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxBigToMut, A: VecZnxToRef; } pub trait VecZnxBigNegateInplace { fn vec_znx_big_negate_inplace(&self, a: &mut A, a_col: usize) where A: VecZnxBigToMut; } pub trait VecZnxBigNormalizeTmpBytes { fn vec_znx_big_normalize_tmp_bytes(&self, n: usize) -> usize; } pub trait VecZnxBigNormalize { fn vec_znx_big_normalize( &self, basek: usize, res: &mut R, res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch, ) where R: VecZnxToMut, A: VecZnxBigToRef; } pub trait VecZnxBigAutomorphism { /// Applies the automorphism X^i -> X^ik on `a` and stores the result on `b`. fn vec_znx_big_automorphism(&self, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize) where R: VecZnxBigToMut, A: VecZnxBigToRef; } pub trait VecZnxBigAutomorphismInplace { /// Applies the automorphism X^i -> X^ik on `a` and stores the result on `a`. fn vec_znx_big_automorphism_inplace(&self, k: i64, a: &mut A, a_col: usize) where A: VecZnxBigToMut; }