arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/poulpy-hal/src/api/vec_znx_big.rs
poulpy-hal/src/api/vec_znx_big.rsRaw
  1use crate::{
  2    layouts::{Backend, Scratch, VecZnxBigOwned, VecZnxBigToMut, VecZnxBigToRef, VecZnxToMut, VecZnxToRef},
  3    source::Source,
  4};
  5
  6pub trait VecZnxBigFromSmall<B: Backend> {
  7    fn vec_znx_big_from_small<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
  8    where
  9        R: VecZnxBigToMut<B>,
 10        A: VecZnxToRef;
 11}
 12
 13/// Allocates as [crate::layouts::VecZnxBig].
 14pub trait VecZnxBigAlloc<B: Backend> {
 15    fn vec_znx_big_alloc(&self, cols: usize, size: usize) -> VecZnxBigOwned<B>;
 16}
 17
 18/// Returns the size in bytes to allocate a [crate::layouts::VecZnxBig].
 19pub trait VecZnxBigAllocBytes {
 20    fn vec_znx_big_alloc_bytes(&self, cols: usize, size: usize) -> usize;
 21}
 22
 23/// Consume a vector of bytes into a [crate::layouts::VecZnxBig].
 24/// User must ensure that bytes is memory aligned and that it length is equal to [VecZnxBigAllocBytes].
 25pub trait VecZnxBigFromBytes<B: Backend> {
 26    fn vec_znx_big_from_bytes(&self, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxBigOwned<B>;
 27}
 28
 29#[allow(clippy::too_many_arguments)]
 30/// Add a discrete normal distribution on res.
 31///
 32/// # Arguments
 33/// * `basek`: base two logarithm of the bivariate representation
 34/// * `res`: receiver.
 35/// * `res_col`: column of the receiver on which the operation is performed/stored.
 36/// * `k`:
 37/// * `source`: random coin source.
 38/// * `sigma`: standard deviation of the discrete normal distribution.
 39/// * `bound`: rejection sampling bound.
 40pub trait VecZnxBigAddNormal<B: Backend> {
 41    fn vec_znx_big_add_normal<R: VecZnxBigToMut<B>>(
 42        &self,
 43        basek: usize,
 44        res: &mut R,
 45        res_col: usize,
 46        k: usize,
 47        source: &mut Source,
 48        sigma: f64,
 49        bound: f64,
 50    );
 51}
 52
 53pub trait VecZnxBigAdd<B: Backend> {
 54    /// Adds `a` to `b` and stores the result on `c`.
 55    fn vec_znx_big_add<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
 56    where
 57        R: VecZnxBigToMut<B>,
 58        A: VecZnxBigToRef<B>,
 59        C: VecZnxBigToRef<B>;
 60}
 61
 62pub trait VecZnxBigAddInplace<B: Backend> {
 63    /// Adds `a` to `b` and stores the result on `b`.
 64    fn vec_znx_big_add_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
 65    where
 66        R: VecZnxBigToMut<B>,
 67        A: VecZnxBigToRef<B>;
 68}
 69
 70pub trait VecZnxBigAddSmall<B: Backend> {
 71    /// Adds `a` to `b` and stores the result on `c`.
 72    fn vec_znx_big_add_small<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
 73    where
 74        R: VecZnxBigToMut<B>,
 75        A: VecZnxBigToRef<B>,
 76        C: VecZnxToRef;
 77}
 78
 79pub trait VecZnxBigAddSmallInplace<B: Backend> {
 80    /// Adds `a` to `b` and stores the result on `b`.
 81    fn vec_znx_big_add_small_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
 82    where
 83        R: VecZnxBigToMut<B>,
 84        A: VecZnxToRef;
 85}
 86
 87pub trait VecZnxBigSub<B: Backend> {
 88    /// Subtracts `a` to `b` and stores the result on `c`.
 89    fn vec_znx_big_sub<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
 90    where
 91        R: VecZnxBigToMut<B>,
 92        A: VecZnxBigToRef<B>,
 93        C: VecZnxBigToRef<B>;
 94}
 95
 96pub trait VecZnxBigSubABInplace<B: Backend> {
 97    /// Subtracts `a` from `b` and stores the result on `b`.
 98    fn vec_znx_big_sub_ab_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
 99    where
100        R: VecZnxBigToMut<B>,
101        A: VecZnxBigToRef<B>;
102}
103
104pub trait VecZnxBigSubBAInplace<B: Backend> {
105    /// Subtracts `b` from `a` and stores the result on `b`.
106    fn vec_znx_big_sub_ba_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
107    where
108        R: VecZnxBigToMut<B>,
109        A: VecZnxBigToRef<B>;
110}
111
112pub trait VecZnxBigSubSmallA<B: Backend> {
113    /// Subtracts `b` from `a` and stores the result on `c`.
114    fn vec_znx_big_sub_small_a<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
115    where
116        R: VecZnxBigToMut<B>,
117        A: VecZnxToRef,
118        C: VecZnxBigToRef<B>;
119}
120
121pub trait VecZnxBigSubSmallAInplace<B: Backend> {
122    /// Subtracts `a` from `res` and stores the result on `res`.
123    fn vec_znx_big_sub_small_a_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
124    where
125        R: VecZnxBigToMut<B>,
126        A: VecZnxToRef;
127}
128
129pub trait VecZnxBigSubSmallB<B: Backend> {
130    /// Subtracts `b` from `a` and stores the result on `c`.
131    fn vec_znx_big_sub_small_b<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
132    where
133        R: VecZnxBigToMut<B>,
134        A: VecZnxBigToRef<B>,
135        C: VecZnxToRef;
136}
137
138pub trait VecZnxBigSubSmallBInplace<B: Backend> {
139    /// Subtracts `res` from `a` and stores the result on `res`.
140    fn vec_znx_big_sub_small_b_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
141    where
142        R: VecZnxBigToMut<B>,
143        A: VecZnxToRef;
144}
145
146pub trait VecZnxBigNegate<B: Backend> {
147    fn vec_znx_big_negate<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
148    where
149        R: VecZnxBigToMut<B>,
150        A: VecZnxBigToRef<B>;
151}
152
153pub trait VecZnxBigNegateInplace<B: Backend> {
154    fn vec_znx_big_negate_inplace<R>(&self, res: &mut R, res_col: usize)
155    where
156        R: VecZnxBigToMut<B>;
157}
158
159pub trait VecZnxBigNormalizeTmpBytes {
160    fn vec_znx_big_normalize_tmp_bytes(&self) -> usize;
161}
162
163pub trait VecZnxBigNormalize<B: Backend> {
164    fn vec_znx_big_normalize<R, A>(
165        &self,
166        basek: usize,
167        res: &mut R,
168        res_col: usize,
169        a: &A,
170        a_col: usize,
171        scratch: &mut Scratch<B>,
172    ) where
173        R: VecZnxToMut,
174        A: VecZnxBigToRef<B>;
175}
176
177pub trait VecZnxBigAutomorphismInplaceTmpBytes {
178    fn vec_znx_big_automorphism_inplace_tmp_bytes(&self) -> usize;
179}
180
181pub trait VecZnxBigAutomorphism<B: Backend> {
182    /// Applies the automorphism X^i -> X^ik on `a` and stores the result on `b`.
183    fn vec_znx_big_automorphism<R, A>(&self, p: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
184    where
185        R: VecZnxBigToMut<B>,
186        A: VecZnxBigToRef<B>;
187}
188
189pub trait VecZnxBigAutomorphismInplace<B: Backend> {
190    /// Applies the automorphism X^i -> X^ik on `a` and stores the result on `a`.
191    fn vec_znx_big_automorphism_inplace<R>(&self, p: i64, res: &mut R, res_col: usize, scratch: &mut Scratch<B>)
192    where
193        R: VecZnxBigToMut<B>;
194}