arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/poulpy-hal/src/delegates/vec_znx_big.rs
poulpy-hal/src/delegates/vec_znx_big.rsRaw
  1use crate::{
  2    api::{
  3        VecZnxBigAdd, VecZnxBigAddInplace, VecZnxBigAddNormal, VecZnxBigAddSmall, VecZnxBigAddSmallInplace, VecZnxBigAlloc,
  4        VecZnxBigAutomorphism, VecZnxBigAutomorphismInplace, VecZnxBigAutomorphismInplaceTmpBytes, VecZnxBigBytesOf,
  5        VecZnxBigFromBytes, VecZnxBigFromSmall, VecZnxBigNegate, VecZnxBigNegateInplace, VecZnxBigNormalize,
  6        VecZnxBigNormalizeTmpBytes, VecZnxBigSub, VecZnxBigSubInplace, VecZnxBigSubNegateInplace, VecZnxBigSubSmallA,
  7        VecZnxBigSubSmallB, VecZnxBigSubSmallInplace, VecZnxBigSubSmallNegateInplace,
  8    },
  9    layouts::{Backend, Module, Scratch, VecZnxBigOwned, VecZnxBigToMut, VecZnxBigToRef, VecZnxToMut, VecZnxToRef},
 10    oep::{
 11        VecZnxBigAddImpl, VecZnxBigAddInplaceImpl, VecZnxBigAddNormalImpl, VecZnxBigAddSmallImpl, VecZnxBigAddSmallInplaceImpl,
 12        VecZnxBigAllocBytesImpl, VecZnxBigAllocImpl, VecZnxBigAutomorphismImpl, VecZnxBigAutomorphismInplaceImpl,
 13        VecZnxBigAutomorphismInplaceTmpBytesImpl, VecZnxBigFromBytesImpl, VecZnxBigFromSmallImpl, VecZnxBigNegateImpl,
 14        VecZnxBigNegateInplaceImpl, VecZnxBigNormalizeImpl, VecZnxBigNormalizeTmpBytesImpl, VecZnxBigSubImpl,
 15        VecZnxBigSubInplaceImpl, VecZnxBigSubNegateInplaceImpl, VecZnxBigSubSmallAImpl, VecZnxBigSubSmallBImpl,
 16        VecZnxBigSubSmallInplaceImpl, VecZnxBigSubSmallNegateInplaceImpl,
 17    },
 18    source::Source,
 19};
 20
 21impl<B> VecZnxBigFromSmall<B> for Module<B>
 22where
 23    B: Backend + VecZnxBigFromSmallImpl<B>,
 24{
 25    fn vec_znx_big_from_small<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
 26    where
 27        R: VecZnxBigToMut<B>,
 28        A: VecZnxToRef,
 29    {
 30        B::vec_znx_big_from_small_impl(res, res_col, a, a_col);
 31    }
 32}
 33
 34impl<B> VecZnxBigAlloc<B> for Module<B>
 35where
 36    B: Backend + VecZnxBigAllocImpl<B>,
 37{
 38    fn vec_znx_big_alloc(&self, cols: usize, size: usize) -> VecZnxBigOwned<B> {
 39        B::vec_znx_big_alloc_impl(self.n(), cols, size)
 40    }
 41}
 42
 43impl<B> VecZnxBigFromBytes<B> for Module<B>
 44where
 45    B: Backend + VecZnxBigFromBytesImpl<B>,
 46{
 47    fn vec_znx_big_from_bytes(&self, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxBigOwned<B> {
 48        B::vec_znx_big_from_bytes_impl(self.n(), cols, size, bytes)
 49    }
 50}
 51
 52impl<B> VecZnxBigBytesOf for Module<B>
 53where
 54    B: Backend + VecZnxBigAllocBytesImpl,
 55{
 56    fn bytes_of_vec_znx_big(&self, cols: usize, size: usize) -> usize {
 57        B::vec_znx_big_bytes_of_impl(self.n(), cols, size)
 58    }
 59}
 60
 61impl<B> VecZnxBigAddNormal<B> for Module<B>
 62where
 63    B: Backend + VecZnxBigAddNormalImpl<B>,
 64{
 65    fn vec_znx_big_add_normal<R: VecZnxBigToMut<B>>(
 66        &self,
 67        base2k: usize,
 68        res: &mut R,
 69        res_col: usize,
 70        k: usize,
 71        source: &mut Source,
 72        sigma: f64,
 73        bound: f64,
 74    ) {
 75        B::add_normal_impl(self, base2k, res, res_col, k, source, sigma, bound);
 76    }
 77}
 78
 79impl<B> VecZnxBigAdd<B> for Module<B>
 80where
 81    B: Backend + VecZnxBigAddImpl<B>,
 82{
 83    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)
 84    where
 85        R: VecZnxBigToMut<B>,
 86        A: VecZnxBigToRef<B>,
 87        C: VecZnxBigToRef<B>,
 88    {
 89        B::vec_znx_big_add_impl(self, res, res_col, a, a_col, b, b_col);
 90    }
 91}
 92
 93impl<B> VecZnxBigAddInplace<B> for Module<B>
 94where
 95    B: Backend + VecZnxBigAddInplaceImpl<B>,
 96{
 97    fn vec_znx_big_add_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
 98    where
 99        R: VecZnxBigToMut<B>,
100        A: VecZnxBigToRef<B>,
101    {
102        B::vec_znx_big_add_inplace_impl(self, res, res_col, a, a_col);
103    }
104}
105
106impl<B> VecZnxBigAddSmall<B> for Module<B>
107where
108    B: Backend + VecZnxBigAddSmallImpl<B>,
109{
110    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)
111    where
112        R: VecZnxBigToMut<B>,
113        A: VecZnxBigToRef<B>,
114        C: VecZnxToRef,
115    {
116        B::vec_znx_big_add_small_impl(self, res, res_col, a, a_col, b, b_col);
117    }
118}
119
120impl<B> VecZnxBigAddSmallInplace<B> for Module<B>
121where
122    B: Backend + VecZnxBigAddSmallInplaceImpl<B>,
123{
124    fn vec_znx_big_add_small_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
125    where
126        R: VecZnxBigToMut<B>,
127        A: VecZnxToRef,
128    {
129        B::vec_znx_big_add_small_inplace_impl(self, res, res_col, a, a_col);
130    }
131}
132
133impl<B> VecZnxBigSub<B> for Module<B>
134where
135    B: Backend + VecZnxBigSubImpl<B>,
136{
137    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)
138    where
139        R: VecZnxBigToMut<B>,
140        A: VecZnxBigToRef<B>,
141        C: VecZnxBigToRef<B>,
142    {
143        B::vec_znx_big_sub_impl(self, res, res_col, a, a_col, b, b_col);
144    }
145}
146
147impl<B> VecZnxBigSubInplace<B> for Module<B>
148where
149    B: Backend + VecZnxBigSubInplaceImpl<B>,
150{
151    fn vec_znx_big_sub_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
152    where
153        R: VecZnxBigToMut<B>,
154        A: VecZnxBigToRef<B>,
155    {
156        B::vec_znx_big_sub_inplace_impl(self, res, res_col, a, a_col);
157    }
158}
159
160impl<B> VecZnxBigSubNegateInplace<B> for Module<B>
161where
162    B: Backend + VecZnxBigSubNegateInplaceImpl<B>,
163{
164    fn vec_znx_big_sub_negate_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
165    where
166        R: VecZnxBigToMut<B>,
167        A: VecZnxBigToRef<B>,
168    {
169        B::vec_znx_big_sub_negate_inplace_impl(self, res, res_col, a, a_col);
170    }
171}
172
173impl<B> VecZnxBigSubSmallA<B> for Module<B>
174where
175    B: Backend + VecZnxBigSubSmallAImpl<B>,
176{
177    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)
178    where
179        R: VecZnxBigToMut<B>,
180        A: VecZnxToRef,
181        C: VecZnxBigToRef<B>,
182    {
183        B::vec_znx_big_sub_small_a_impl(self, res, res_col, a, a_col, b, b_col);
184    }
185}
186
187impl<B> VecZnxBigSubSmallInplace<B> for Module<B>
188where
189    B: Backend + VecZnxBigSubSmallInplaceImpl<B>,
190{
191    fn vec_znx_big_sub_small_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
192    where
193        R: VecZnxBigToMut<B>,
194        A: VecZnxToRef,
195    {
196        B::vec_znx_big_sub_small_inplace_impl(self, res, res_col, a, a_col);
197    }
198}
199
200impl<B> VecZnxBigSubSmallB<B> for Module<B>
201where
202    B: Backend + VecZnxBigSubSmallBImpl<B>,
203{
204    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)
205    where
206        R: VecZnxBigToMut<B>,
207        A: VecZnxBigToRef<B>,
208        C: VecZnxToRef,
209    {
210        B::vec_znx_big_sub_small_b_impl(self, res, res_col, a, a_col, b, b_col);
211    }
212}
213
214impl<B> VecZnxBigSubSmallNegateInplace<B> for Module<B>
215where
216    B: Backend + VecZnxBigSubSmallNegateInplaceImpl<B>,
217{
218    fn vec_znx_big_sub_small_negate_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
219    where
220        R: VecZnxBigToMut<B>,
221        A: VecZnxToRef,
222    {
223        B::vec_znx_big_sub_small_negate_inplace_impl(self, res, res_col, a, a_col);
224    }
225}
226
227impl<B> VecZnxBigNegate<B> for Module<B>
228where
229    B: Backend + VecZnxBigNegateImpl<B>,
230{
231    fn vec_znx_big_negate<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
232    where
233        R: VecZnxBigToMut<B>,
234        A: VecZnxBigToRef<B>,
235    {
236        B::vec_znx_big_negate_impl(self, res, res_col, a, a_col);
237    }
238}
239
240impl<B> VecZnxBigNegateInplace<B> for Module<B>
241where
242    B: Backend + VecZnxBigNegateInplaceImpl<B>,
243{
244    fn vec_znx_big_negate_inplace<A>(&self, a: &mut A, a_col: usize)
245    where
246        A: VecZnxBigToMut<B>,
247    {
248        B::vec_znx_big_negate_inplace_impl(self, a, a_col);
249    }
250}
251
252impl<B> VecZnxBigNormalizeTmpBytes for Module<B>
253where
254    B: Backend + VecZnxBigNormalizeTmpBytesImpl<B>,
255{
256    fn vec_znx_big_normalize_tmp_bytes(&self) -> usize {
257        B::vec_znx_big_normalize_tmp_bytes_impl(self)
258    }
259}
260
261impl<B> VecZnxBigNormalize<B> for Module<B>
262where
263    B: Backend + VecZnxBigNormalizeImpl<B>,
264{
265    fn vec_znx_big_normalize<R, A>(
266        &self,
267        res: &mut R,
268        res_base2k: usize,
269        res_offset: i64,
270        res_col: usize,
271        a: &A,
272        a_base2k: usize,
273        a_col: usize,
274        scratch: &mut Scratch<B>,
275    ) where
276        R: VecZnxToMut,
277        A: VecZnxBigToRef<B>,
278    {
279        B::vec_znx_big_normalize_impl(self, res, res_base2k, res_offset, res_col, a, a_base2k, a_col, scratch);
280    }
281}
282
283impl<B> VecZnxBigAutomorphism<B> for Module<B>
284where
285    B: Backend + VecZnxBigAutomorphismImpl<B>,
286{
287    fn vec_znx_big_automorphism<R, A>(&self, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
288    where
289        R: VecZnxBigToMut<B>,
290        A: VecZnxBigToRef<B>,
291    {
292        B::vec_znx_big_automorphism_impl(self, k, res, res_col, a, a_col);
293    }
294}
295
296impl<B> VecZnxBigAutomorphismInplaceTmpBytes for Module<B>
297where
298    B: Backend + VecZnxBigAutomorphismInplaceTmpBytesImpl<B>,
299{
300    fn vec_znx_big_automorphism_inplace_tmp_bytes(&self) -> usize {
301        B::vec_znx_big_automorphism_inplace_tmp_bytes_impl(self)
302    }
303}
304
305impl<B> VecZnxBigAutomorphismInplace<B> for Module<B>
306where
307    B: Backend + VecZnxBigAutomorphismInplaceImpl<B>,
308{
309    fn vec_znx_big_automorphism_inplace<A>(&self, k: i64, a: &mut A, a_col: usize, scratch: &mut Scratch<B>)
310    where
311        A: VecZnxBigToMut<B>,
312    {
313        B::vec_znx_big_automorphism_inplace_impl(self, k, a, a_col, scratch);
314    }
315}