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