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