arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/poulpy-hal/src/delegates/vec_znx.rs
poulpy-hal/src/delegates/vec_znx.rsRaw
  1use crate::{
  2    api::{
  3        VecZnxAdd, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalar, VecZnxAddScalarInplace, VecZnxAutomorphism,
  4        VecZnxAutomorphismInplace, VecZnxAutomorphismInplaceTmpBytes, VecZnxCopy, VecZnxFillNormal, VecZnxFillUniform, VecZnxLsh,
  5        VecZnxLshInplace, VecZnxLshTmpBytes, VecZnxMergeRings, VecZnxMergeRingsTmpBytes, VecZnxMulXpMinusOne,
  6        VecZnxMulXpMinusOneInplace, VecZnxMulXpMinusOneInplaceTmpBytes, VecZnxNegate, VecZnxNegateInplace, VecZnxNormalize,
  7        VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace, VecZnxRotateInplaceTmpBytes,
  8        VecZnxRsh, VecZnxRshInplace, VecZnxRshTmpBytes, VecZnxSplitRing, VecZnxSplitRingTmpBytes, VecZnxSub, VecZnxSubInplace,
  9        VecZnxSubNegateInplace, VecZnxSubScalar, VecZnxSubScalarInplace, VecZnxSwitchRing, VecZnxZero,
 10    },
 11    layouts::{Backend, Module, ScalarZnxToRef, Scratch, VecZnxToMut, VecZnxToRef},
 12    oep::{
 13        VecZnxAddImpl, VecZnxAddInplaceImpl, VecZnxAddNormalImpl, VecZnxAddScalarImpl, VecZnxAddScalarInplaceImpl,
 14        VecZnxAutomorphismImpl, VecZnxAutomorphismInplaceImpl, VecZnxAutomorphismInplaceTmpBytesImpl, VecZnxCopyImpl,
 15        VecZnxFillNormalImpl, VecZnxFillUniformImpl, VecZnxLshImpl, VecZnxLshInplaceImpl, VecZnxLshTmpBytesImpl,
 16        VecZnxMergeRingsImpl, VecZnxMergeRingsTmpBytesImpl, VecZnxMulXpMinusOneImpl, VecZnxMulXpMinusOneInplaceImpl,
 17        VecZnxMulXpMinusOneInplaceTmpBytesImpl, VecZnxNegateImpl, VecZnxNegateInplaceImpl, VecZnxNormalizeImpl,
 18        VecZnxNormalizeInplaceImpl, VecZnxNormalizeTmpBytesImpl, VecZnxRotateImpl, VecZnxRotateInplaceImpl,
 19        VecZnxRotateInplaceTmpBytesImpl, VecZnxRshImpl, VecZnxRshInplaceImpl, VecZnxRshTmpBytesImpl, VecZnxSplitRingImpl,
 20        VecZnxSplitRingTmpBytesImpl, VecZnxSubImpl, VecZnxSubInplaceImpl, VecZnxSubNegateInplaceImpl, VecZnxSubScalarImpl,
 21        VecZnxSubScalarInplaceImpl, VecZnxSwitchRingImpl, VecZnxZeroImpl,
 22    },
 23    source::Source,
 24};
 25
 26impl<B> VecZnxZero for Module<B>
 27where
 28    B: Backend + VecZnxZeroImpl<B>,
 29{
 30    fn vec_znx_zero<R>(&self, res: &mut R, res_col: usize)
 31    where
 32        R: VecZnxToMut,
 33    {
 34        B::vec_znx_zero_impl(self, res, res_col);
 35    }
 36}
 37
 38impl<B> VecZnxNormalizeTmpBytes for Module<B>
 39where
 40    B: Backend + VecZnxNormalizeTmpBytesImpl<B>,
 41{
 42    fn vec_znx_normalize_tmp_bytes(&self) -> usize {
 43        B::vec_znx_normalize_tmp_bytes_impl(self)
 44    }
 45}
 46
 47impl<B> VecZnxNormalize<B> for Module<B>
 48where
 49    B: Backend + VecZnxNormalizeImpl<B>,
 50{
 51    #[allow(clippy::too_many_arguments)]
 52    fn vec_znx_normalize<R, A>(
 53        &self,
 54        res: &mut R,
 55        res_base2k: usize,
 56        res_offset: i64,
 57        res_col: usize,
 58        a: &A,
 59        a_base2k: usize,
 60        a_col: usize,
 61        scratch: &mut Scratch<B>,
 62    ) where
 63        R: VecZnxToMut,
 64        A: VecZnxToRef,
 65    {
 66        B::vec_znx_normalize_impl(self, res, res_base2k, res_offset, res_col, a, a_base2k, a_col, scratch)
 67    }
 68}
 69
 70impl<B> VecZnxNormalizeInplace<B> for Module<B>
 71where
 72    B: Backend + VecZnxNormalizeInplaceImpl<B>,
 73{
 74    fn vec_znx_normalize_inplace<A>(&self, base2k: usize, a: &mut A, a_col: usize, scratch: &mut Scratch<B>)
 75    where
 76        A: VecZnxToMut,
 77    {
 78        B::vec_znx_normalize_inplace_impl(self, base2k, a, a_col, scratch)
 79    }
 80}
 81
 82impl<B> VecZnxAdd for Module<B>
 83where
 84    B: Backend + VecZnxAddImpl<B>,
 85{
 86    fn vec_znx_add<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
 87    where
 88        R: VecZnxToMut,
 89        A: VecZnxToRef,
 90        C: VecZnxToRef,
 91    {
 92        B::vec_znx_add_impl(self, res, res_col, a, a_col, b, b_col)
 93    }
 94}
 95
 96impl<B> VecZnxAddInplace for Module<B>
 97where
 98    B: Backend + VecZnxAddInplaceImpl<B>,
 99{
100    fn vec_znx_add_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
101    where
102        R: VecZnxToMut,
103        A: VecZnxToRef,
104    {
105        B::vec_znx_add_inplace_impl(self, res, res_col, a, a_col)
106    }
107}
108
109impl<B> VecZnxAddScalar for Module<B>
110where
111    B: Backend + VecZnxAddScalarImpl<B>,
112{
113    fn vec_znx_add_scalar<R, A, D>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &D, b_col: usize, b_limb: usize)
114    where
115        R: VecZnxToMut,
116        A: ScalarZnxToRef,
117        D: VecZnxToRef,
118    {
119        B::vec_znx_add_scalar_impl(self, res, res_col, a, a_col, b, b_col, b_limb)
120    }
121}
122
123impl<B> VecZnxAddScalarInplace for Module<B>
124where
125    B: Backend + VecZnxAddScalarInplaceImpl<B>,
126{
127    fn vec_znx_add_scalar_inplace<R, A>(&self, res: &mut R, res_col: usize, res_limb: usize, a: &A, a_col: usize)
128    where
129        R: VecZnxToMut,
130        A: ScalarZnxToRef,
131    {
132        B::vec_znx_add_scalar_inplace_impl(self, res, res_col, res_limb, a, a_col)
133    }
134}
135
136impl<B> VecZnxSub for Module<B>
137where
138    B: Backend + VecZnxSubImpl<B>,
139{
140    fn vec_znx_sub<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
141    where
142        R: VecZnxToMut,
143        A: VecZnxToRef,
144        C: VecZnxToRef,
145    {
146        B::vec_znx_sub_impl(self, res, res_col, a, a_col, b, b_col)
147    }
148}
149
150impl<B> VecZnxSubInplace for Module<B>
151where
152    B: Backend + VecZnxSubInplaceImpl<B>,
153{
154    fn vec_znx_sub_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
155    where
156        R: VecZnxToMut,
157        A: VecZnxToRef,
158    {
159        B::vec_znx_sub_inplace_impl(self, res, res_col, a, a_col)
160    }
161}
162
163impl<B> VecZnxSubNegateInplace for Module<B>
164where
165    B: Backend + VecZnxSubNegateInplaceImpl<B>,
166{
167    fn vec_znx_sub_negate_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
168    where
169        R: VecZnxToMut,
170        A: VecZnxToRef,
171    {
172        B::vec_znx_sub_negate_inplace_impl(self, res, res_col, a, a_col)
173    }
174}
175
176impl<B> VecZnxSubScalar for Module<B>
177where
178    B: Backend + VecZnxSubScalarImpl<B>,
179{
180    fn vec_znx_sub_scalar<R, A, D>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &D, b_col: usize, b_limb: usize)
181    where
182        R: VecZnxToMut,
183        A: ScalarZnxToRef,
184        D: VecZnxToRef,
185    {
186        B::vec_znx_sub_scalar_impl(self, res, res_col, a, a_col, b, b_col, b_limb)
187    }
188}
189
190impl<B> VecZnxSubScalarInplace for Module<B>
191where
192    B: Backend + VecZnxSubScalarInplaceImpl<B>,
193{
194    fn vec_znx_sub_scalar_inplace<R, A>(&self, res: &mut R, res_col: usize, res_limb: usize, a: &A, a_col: usize)
195    where
196        R: VecZnxToMut,
197        A: ScalarZnxToRef,
198    {
199        B::vec_znx_sub_scalar_inplace_impl(self, res, res_col, res_limb, a, a_col)
200    }
201}
202
203impl<B> VecZnxNegate for Module<B>
204where
205    B: Backend + VecZnxNegateImpl<B>,
206{
207    fn vec_znx_negate<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
208    where
209        R: VecZnxToMut,
210        A: VecZnxToRef,
211    {
212        B::vec_znx_negate_impl(self, res, res_col, a, a_col)
213    }
214}
215
216impl<B> VecZnxNegateInplace for Module<B>
217where
218    B: Backend + VecZnxNegateInplaceImpl<B>,
219{
220    fn vec_znx_negate_inplace<A>(&self, a: &mut A, a_col: usize)
221    where
222        A: VecZnxToMut,
223    {
224        B::vec_znx_negate_inplace_impl(self, a, a_col)
225    }
226}
227
228impl<B> VecZnxRshTmpBytes for Module<B>
229where
230    B: Backend + VecZnxRshTmpBytesImpl<B>,
231{
232    fn vec_znx_rsh_tmp_bytes(&self) -> usize {
233        B::vec_znx_rsh_tmp_bytes_impl(self)
234    }
235}
236
237impl<B> VecZnxLshTmpBytes for Module<B>
238where
239    B: Backend + VecZnxLshTmpBytesImpl<B>,
240{
241    fn vec_znx_lsh_tmp_bytes(&self) -> usize {
242        B::vec_znx_lsh_tmp_bytes_impl(self)
243    }
244}
245
246impl<B> VecZnxLsh<B> for Module<B>
247where
248    B: Backend + VecZnxLshImpl<B>,
249{
250    fn vec_znx_lsh<R, A>(
251        &self,
252        base2k: usize,
253        k: usize,
254        res: &mut R,
255        res_col: usize,
256        a: &A,
257        a_col: usize,
258        scratch: &mut Scratch<B>,
259    ) where
260        R: VecZnxToMut,
261        A: VecZnxToRef,
262    {
263        B::vec_znx_lsh_impl(self, base2k, k, res, res_col, a, a_col, scratch);
264    }
265}
266
267impl<B> VecZnxRsh<B> for Module<B>
268where
269    B: Backend + VecZnxRshImpl<B>,
270{
271    fn vec_znx_rsh<R, A>(
272        &self,
273        base2k: usize,
274        k: usize,
275        res: &mut R,
276        res_col: usize,
277        a: &A,
278        a_col: usize,
279        scratch: &mut Scratch<B>,
280    ) where
281        R: VecZnxToMut,
282        A: VecZnxToRef,
283    {
284        B::vec_znx_rsh_impl(self, base2k, k, res, res_col, a, a_col, scratch);
285    }
286}
287
288impl<B> VecZnxLshInplace<B> for Module<B>
289where
290    B: Backend + VecZnxLshInplaceImpl<B>,
291{
292    fn vec_znx_lsh_inplace<A>(&self, base2k: usize, k: usize, a: &mut A, a_col: usize, scratch: &mut Scratch<B>)
293    where
294        A: VecZnxToMut,
295    {
296        B::vec_znx_lsh_inplace_impl(self, base2k, k, a, a_col, scratch)
297    }
298}
299
300impl<B> VecZnxRshInplace<B> for Module<B>
301where
302    B: Backend + VecZnxRshInplaceImpl<B>,
303{
304    fn vec_znx_rsh_inplace<A>(&self, base2k: usize, k: usize, a: &mut A, a_col: usize, scratch: &mut Scratch<B>)
305    where
306        A: VecZnxToMut,
307    {
308        B::vec_znx_rsh_inplace_impl(self, base2k, k, a, a_col, scratch)
309    }
310}
311
312impl<B> VecZnxRotate for Module<B>
313where
314    B: Backend + VecZnxRotateImpl<B>,
315{
316    fn vec_znx_rotate<R, A>(&self, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
317    where
318        R: VecZnxToMut,
319        A: VecZnxToRef,
320    {
321        B::vec_znx_rotate_impl(self, k, res, res_col, a, a_col)
322    }
323}
324
325impl<B> VecZnxRotateInplaceTmpBytes for Module<B>
326where
327    B: Backend + VecZnxRotateInplaceTmpBytesImpl<B>,
328{
329    fn vec_znx_rotate_inplace_tmp_bytes(&self) -> usize {
330        B::vec_znx_rotate_inplace_tmp_bytes_impl(self)
331    }
332}
333
334impl<B> VecZnxRotateInplace<B> for Module<B>
335where
336    B: Backend + VecZnxRotateInplaceImpl<B>,
337{
338    fn vec_znx_rotate_inplace<A>(&self, k: i64, a: &mut A, a_col: usize, scratch: &mut Scratch<B>)
339    where
340        A: VecZnxToMut,
341    {
342        B::vec_znx_rotate_inplace_impl(self, k, a, a_col, scratch)
343    }
344}
345
346impl<B> VecZnxAutomorphism for Module<B>
347where
348    B: Backend + VecZnxAutomorphismImpl<B>,
349{
350    fn vec_znx_automorphism<R, A>(&self, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
351    where
352        R: VecZnxToMut,
353        A: VecZnxToRef,
354    {
355        B::vec_znx_automorphism_impl(self, k, res, res_col, a, a_col)
356    }
357}
358
359impl<B> VecZnxAutomorphismInplaceTmpBytes for Module<B>
360where
361    B: Backend + VecZnxAutomorphismInplaceTmpBytesImpl<B>,
362{
363    fn vec_znx_automorphism_inplace_tmp_bytes(&self) -> usize {
364        B::vec_znx_automorphism_inplace_tmp_bytes_impl(self)
365    }
366}
367
368impl<B> VecZnxAutomorphismInplace<B> for Module<B>
369where
370    B: Backend + VecZnxAutomorphismInplaceImpl<B>,
371{
372    fn vec_znx_automorphism_inplace<R>(&self, k: i64, res: &mut R, res_col: usize, scratch: &mut Scratch<B>)
373    where
374        R: VecZnxToMut,
375    {
376        B::vec_znx_automorphism_inplace_impl(self, k, res, res_col, scratch)
377    }
378}
379
380impl<B> VecZnxMulXpMinusOne for Module<B>
381where
382    B: Backend + VecZnxMulXpMinusOneImpl<B>,
383{
384    fn vec_znx_mul_xp_minus_one<R, A>(&self, p: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
385    where
386        R: VecZnxToMut,
387        A: VecZnxToRef,
388    {
389        B::vec_znx_mul_xp_minus_one_impl(self, p, res, res_col, a, a_col);
390    }
391}
392
393impl<B> VecZnxMulXpMinusOneInplaceTmpBytes for Module<B>
394where
395    B: Backend + VecZnxMulXpMinusOneInplaceTmpBytesImpl<B>,
396{
397    fn vec_znx_mul_xp_minus_one_inplace_tmp_bytes(&self) -> usize {
398        B::vec_znx_mul_xp_minus_one_inplace_tmp_bytes_impl(self)
399    }
400}
401
402impl<B> VecZnxMulXpMinusOneInplace<B> for Module<B>
403where
404    B: Backend + VecZnxMulXpMinusOneInplaceImpl<B>,
405{
406    fn vec_znx_mul_xp_minus_one_inplace<R>(&self, p: i64, res: &mut R, res_col: usize, scratch: &mut Scratch<B>)
407    where
408        R: VecZnxToMut,
409    {
410        B::vec_znx_mul_xp_minus_one_inplace_impl(self, p, res, res_col, scratch);
411    }
412}
413
414impl<B> VecZnxSplitRingTmpBytes for Module<B>
415where
416    B: Backend + VecZnxSplitRingTmpBytesImpl<B>,
417{
418    fn vec_znx_split_ring_tmp_bytes(&self) -> usize {
419        B::vec_znx_split_ring_tmp_bytes_impl(self)
420    }
421}
422
423impl<B> VecZnxSplitRing<B> for Module<B>
424where
425    B: Backend + VecZnxSplitRingImpl<B>,
426{
427    fn vec_znx_split_ring<R, A>(&self, res: &mut [R], res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>)
428    where
429        R: VecZnxToMut,
430        A: VecZnxToRef,
431    {
432        B::vec_znx_split_ring_impl(self, res, res_col, a, a_col, scratch)
433    }
434}
435
436impl<B> VecZnxMergeRingsTmpBytes for Module<B>
437where
438    B: Backend + VecZnxMergeRingsTmpBytesImpl<B>,
439{
440    fn vec_znx_merge_rings_tmp_bytes(&self) -> usize {
441        B::vec_znx_merge_rings_tmp_bytes_impl(self)
442    }
443}
444
445impl<B> VecZnxMergeRings<B> for Module<B>
446where
447    B: Backend + VecZnxMergeRingsImpl<B>,
448{
449    fn vec_znx_merge_rings<R, A>(&self, res: &mut R, res_col: usize, a: &[A], a_col: usize, scratch: &mut Scratch<B>)
450    where
451        R: VecZnxToMut,
452        A: VecZnxToRef,
453    {
454        B::vec_znx_merge_rings_impl(self, res, res_col, a, a_col, scratch)
455    }
456}
457
458impl<B> VecZnxSwitchRing for Module<B>
459where
460    B: Backend + VecZnxSwitchRingImpl<B>,
461{
462    fn vec_znx_switch_ring<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
463    where
464        R: VecZnxToMut,
465        A: VecZnxToRef,
466    {
467        B::vec_znx_switch_ring_impl(self, res, res_col, a, a_col)
468    }
469}
470
471impl<B> VecZnxCopy for Module<B>
472where
473    B: Backend + VecZnxCopyImpl<B>,
474{
475    fn vec_znx_copy<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
476    where
477        R: VecZnxToMut,
478        A: VecZnxToRef,
479    {
480        B::vec_znx_copy_impl(self, res, res_col, a, a_col)
481    }
482}
483
484impl<B> VecZnxFillUniform for Module<B>
485where
486    B: Backend + VecZnxFillUniformImpl<B>,
487{
488    fn vec_znx_fill_uniform<R>(&self, base2k: usize, res: &mut R, res_col: usize, source: &mut Source)
489    where
490        R: VecZnxToMut,
491    {
492        B::vec_znx_fill_uniform_impl(self, base2k, res, res_col, source);
493    }
494}
495
496impl<B> VecZnxFillNormal for Module<B>
497where
498    B: Backend + VecZnxFillNormalImpl<B>,
499{
500    fn vec_znx_fill_normal<R>(
501        &self,
502        base2k: usize,
503        res: &mut R,
504        res_col: usize,
505        k: usize,
506        source: &mut Source,
507        sigma: f64,
508        bound: f64,
509    ) where
510        R: VecZnxToMut,
511    {
512        B::vec_znx_fill_normal_impl(self, base2k, res, res_col, k, source, sigma, bound);
513    }
514}
515
516impl<B> VecZnxAddNormal for Module<B>
517where
518    B: Backend + VecZnxAddNormalImpl<B>,
519{
520    fn vec_znx_add_normal<R>(
521        &self,
522        base2k: usize,
523        res: &mut R,
524        res_col: usize,
525        k: usize,
526        source: &mut Source,
527        sigma: f64,
528        bound: f64,
529    ) where
530        R: VecZnxToMut,
531    {
532        B::vec_znx_add_normal_impl(self, base2k, res, res_col, k, source, sigma, bound);
533    }
534}