poulpy/backend/src/hal/delegates/vec_znx.rs
backend/src/hal/delegates/vec_znx.rsRaw
1use sampling::source::Source;
2
3use crate::hal::{
4 api::{
5 VecZnxAdd, VecZnxAddDistF64, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism,
6 VecZnxAutomorphismInplace, VecZnxCopy, VecZnxDecodeCoeffsi64, VecZnxDecodeVecFloat, VecZnxDecodeVeci64,
7 VecZnxEncodeCoeffsi64, VecZnxEncodeVeci64, VecZnxFillDistF64, VecZnxFillNormal, VecZnxFillUniform, VecZnxLshInplace,
8 VecZnxMerge, VecZnxMulXpMinusOne, VecZnxMulXpMinusOneInplace, VecZnxNegate, VecZnxNegateInplace, VecZnxNormalize,
9 VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace, VecZnxRshInplace, VecZnxSplit,
10 VecZnxStd, VecZnxSub, VecZnxSubABInplace, VecZnxSubBAInplace, VecZnxSubScalarInplace, VecZnxSwithcDegree,
11 },
12 layouts::{Backend, Module, ScalarZnxToRef, Scratch, VecZnxToMut, VecZnxToRef},
13 oep::{
14 VecZnxAddDistF64Impl, VecZnxAddImpl, VecZnxAddInplaceImpl, VecZnxAddNormalImpl, VecZnxAddScalarInplaceImpl,
15 VecZnxAutomorphismImpl, VecZnxAutomorphismInplaceImpl, VecZnxCopyImpl, VecZnxDecodeCoeffsi64Impl,
16 VecZnxDecodeVecFloatImpl, VecZnxDecodeVeci64Impl, VecZnxEncodeCoeffsi64Impl, VecZnxEncodeVeci64Impl,
17 VecZnxFillDistF64Impl, VecZnxFillNormalImpl, VecZnxFillUniformImpl, VecZnxLshInplaceImpl, VecZnxMergeImpl,
18 VecZnxMulXpMinusOneImpl, VecZnxMulXpMinusOneInplaceImpl, VecZnxNegateImpl, VecZnxNegateInplaceImpl, VecZnxNormalizeImpl,
19 VecZnxNormalizeInplaceImpl, VecZnxNormalizeTmpBytesImpl, VecZnxRotateImpl, VecZnxRotateInplaceImpl, VecZnxRshInplaceImpl,
20 VecZnxSplitImpl, VecZnxStdImpl, VecZnxSubABInplaceImpl, VecZnxSubBAInplaceImpl, VecZnxSubImpl,
21 VecZnxSubScalarInplaceImpl, VecZnxSwithcDegreeImpl,
22 },
23};
24
25impl<B> VecZnxNormalizeTmpBytes for Module<B>
26where
27 B: Backend + VecZnxNormalizeTmpBytesImpl<B>,
28{
29 fn vec_znx_normalize_tmp_bytes(&self, n: usize) -> usize {
30 B::vec_znx_normalize_tmp_bytes_impl(self, n)
31 }
32}
33
34impl<B> VecZnxNormalize<B> for Module<B>
35where
36 B: Backend + VecZnxNormalizeImpl<B>,
37{
38 fn vec_znx_normalize<R, A>(&self, basek: usize, res: &mut R, res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>)
39 where
40 R: VecZnxToMut,
41 A: VecZnxToRef,
42 {
43 B::vec_znx_normalize_impl(self, basek, res, res_col, a, a_col, scratch)
44 }
45}
46
47impl<B> VecZnxNormalizeInplace<B> for Module<B>
48where
49 B: Backend + VecZnxNormalizeInplaceImpl<B>,
50{
51 fn vec_znx_normalize_inplace<A>(&self, basek: usize, a: &mut A, a_col: usize, scratch: &mut Scratch<B>)
52 where
53 A: VecZnxToMut,
54 {
55 B::vec_znx_normalize_inplace_impl(self, basek, a, a_col, scratch)
56 }
57}
58
59impl<B> VecZnxAdd for Module<B>
60where
61 B: Backend + VecZnxAddImpl<B>,
62{
63 fn vec_znx_add<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
64 where
65 R: VecZnxToMut,
66 A: VecZnxToRef,
67 C: VecZnxToRef,
68 {
69 B::vec_znx_add_impl(self, res, res_col, a, a_col, b, b_col)
70 }
71}
72
73impl<B> VecZnxAddInplace for Module<B>
74where
75 B: Backend + VecZnxAddInplaceImpl<B>,
76{
77 fn vec_znx_add_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
78 where
79 R: VecZnxToMut,
80 A: VecZnxToRef,
81 {
82 B::vec_znx_add_inplace_impl(self, res, res_col, a, a_col)
83 }
84}
85
86impl<B> VecZnxAddScalarInplace for Module<B>
87where
88 B: Backend + VecZnxAddScalarInplaceImpl<B>,
89{
90 fn vec_znx_add_scalar_inplace<R, A>(&self, res: &mut R, res_col: usize, res_limb: usize, a: &A, a_col: usize)
91 where
92 R: VecZnxToMut,
93 A: ScalarZnxToRef,
94 {
95 B::vec_znx_add_scalar_inplace_impl(self, res, res_col, res_limb, a, a_col)
96 }
97}
98
99impl<B> VecZnxSub for Module<B>
100where
101 B: Backend + VecZnxSubImpl<B>,
102{
103 fn vec_znx_sub<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
104 where
105 R: VecZnxToMut,
106 A: VecZnxToRef,
107 C: VecZnxToRef,
108 {
109 B::vec_znx_sub_impl(self, res, res_col, a, a_col, b, b_col)
110 }
111}
112
113impl<B> VecZnxSubABInplace for Module<B>
114where
115 B: Backend + VecZnxSubABInplaceImpl<B>,
116{
117 fn vec_znx_sub_ab_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
118 where
119 R: VecZnxToMut,
120 A: VecZnxToRef,
121 {
122 B::vec_znx_sub_ab_inplace_impl(self, res, res_col, a, a_col)
123 }
124}
125
126impl<B> VecZnxSubBAInplace for Module<B>
127where
128 B: Backend + VecZnxSubBAInplaceImpl<B>,
129{
130 fn vec_znx_sub_ba_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
131 where
132 R: VecZnxToMut,
133 A: VecZnxToRef,
134 {
135 B::vec_znx_sub_ba_inplace_impl(self, res, res_col, a, a_col)
136 }
137}
138
139impl<B> VecZnxSubScalarInplace for Module<B>
140where
141 B: Backend + VecZnxSubScalarInplaceImpl<B>,
142{
143 fn vec_znx_sub_scalar_inplace<R, A>(&self, res: &mut R, res_col: usize, res_limb: usize, a: &A, a_col: usize)
144 where
145 R: VecZnxToMut,
146 A: ScalarZnxToRef,
147 {
148 B::vec_znx_sub_scalar_inplace_impl(self, res, res_col, res_limb, a, a_col)
149 }
150}
151
152impl<B> VecZnxNegate for Module<B>
153where
154 B: Backend + VecZnxNegateImpl<B>,
155{
156 fn vec_znx_negate<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
157 where
158 R: VecZnxToMut,
159 A: VecZnxToRef,
160 {
161 B::vec_znx_negate_impl(self, res, res_col, a, a_col)
162 }
163}
164
165impl<B> VecZnxNegateInplace for Module<B>
166where
167 B: Backend + VecZnxNegateInplaceImpl<B>,
168{
169 fn vec_znx_negate_inplace<A>(&self, a: &mut A, a_col: usize)
170 where
171 A: VecZnxToMut,
172 {
173 B::vec_znx_negate_inplace_impl(self, a, a_col)
174 }
175}
176
177impl<B> VecZnxLshInplace for Module<B>
178where
179 B: Backend + VecZnxLshInplaceImpl<B>,
180{
181 fn vec_znx_lsh_inplace<A>(&self, basek: usize, k: usize, a: &mut A)
182 where
183 A: VecZnxToMut,
184 {
185 B::vec_znx_lsh_inplace_impl(self, basek, k, a)
186 }
187}
188
189impl<B> VecZnxRshInplace for Module<B>
190where
191 B: Backend + VecZnxRshInplaceImpl<B>,
192{
193 fn vec_znx_rsh_inplace<A>(&self, basek: usize, k: usize, a: &mut A)
194 where
195 A: VecZnxToMut,
196 {
197 B::vec_znx_rsh_inplace_impl(self, basek, k, a)
198 }
199}
200
201impl<B> VecZnxRotate for Module<B>
202where
203 B: Backend + VecZnxRotateImpl<B>,
204{
205 fn vec_znx_rotate<R, A>(&self, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
206 where
207 R: VecZnxToMut,
208 A: VecZnxToRef,
209 {
210 B::vec_znx_rotate_impl(self, k, res, res_col, a, a_col)
211 }
212}
213
214impl<B> VecZnxRotateInplace for Module<B>
215where
216 B: Backend + VecZnxRotateInplaceImpl<B>,
217{
218 fn vec_znx_rotate_inplace<A>(&self, k: i64, a: &mut A, a_col: usize)
219 where
220 A: VecZnxToMut,
221 {
222 B::vec_znx_rotate_inplace_impl(self, k, a, a_col)
223 }
224}
225
226impl<B> VecZnxAutomorphism for Module<B>
227where
228 B: Backend + VecZnxAutomorphismImpl<B>,
229{
230 fn vec_znx_automorphism<R, A>(&self, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
231 where
232 R: VecZnxToMut,
233 A: VecZnxToRef,
234 {
235 B::vec_znx_automorphism_impl(self, k, res, res_col, a, a_col)
236 }
237}
238
239impl<B> VecZnxAutomorphismInplace for Module<B>
240where
241 B: Backend + VecZnxAutomorphismInplaceImpl<B>,
242{
243 fn vec_znx_automorphism_inplace<A>(&self, k: i64, a: &mut A, a_col: usize)
244 where
245 A: VecZnxToMut,
246 {
247 B::vec_znx_automorphism_inplace_impl(self, k, a, a_col)
248 }
249}
250
251impl<B> VecZnxMulXpMinusOne for Module<B>
252where
253 B: Backend + VecZnxMulXpMinusOneImpl<B>,
254{
255 fn vec_znx_mul_xp_minus_one<R, A>(&self, p: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
256 where
257 R: VecZnxToMut,
258 A: VecZnxToRef,
259 {
260 B::vec_znx_mul_xp_minus_one_impl(self, p, res, res_col, a, a_col);
261 }
262}
263
264impl<B> VecZnxMulXpMinusOneInplace for Module<B>
265where
266 B: Backend + VecZnxMulXpMinusOneInplaceImpl<B>,
267{
268 fn vec_znx_mul_xp_minus_one_inplace<R>(&self, p: i64, res: &mut R, res_col: usize)
269 where
270 R: VecZnxToMut,
271 {
272 B::vec_znx_mul_xp_minus_one_inplace_impl(self, p, res, res_col);
273 }
274}
275
276impl<B> VecZnxSplit<B> for Module<B>
277where
278 B: Backend + VecZnxSplitImpl<B>,
279{
280 fn vec_znx_split<R, A>(&self, res: &mut Vec<R>, res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>)
281 where
282 R: VecZnxToMut,
283 A: VecZnxToRef,
284 {
285 B::vec_znx_split_impl(self, res, res_col, a, a_col, scratch)
286 }
287}
288
289impl<B> VecZnxMerge for Module<B>
290where
291 B: Backend + VecZnxMergeImpl<B>,
292{
293 fn vec_znx_merge<R, A>(&self, res: &mut R, res_col: usize, a: Vec<A>, a_col: usize)
294 where
295 R: VecZnxToMut,
296 A: VecZnxToRef,
297 {
298 B::vec_znx_merge_impl(self, res, res_col, a, a_col)
299 }
300}
301
302impl<B> VecZnxSwithcDegree for Module<B>
303where
304 B: Backend + VecZnxSwithcDegreeImpl<B>,
305{
306 fn vec_znx_switch_degree<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
307 where
308 R: VecZnxToMut,
309 A: VecZnxToRef,
310 {
311 B::vec_znx_switch_degree_impl(self, res, res_col, a, a_col)
312 }
313}
314
315impl<B> VecZnxCopy for Module<B>
316where
317 B: Backend + VecZnxCopyImpl<B>,
318{
319 fn vec_znx_copy<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
320 where
321 R: VecZnxToMut,
322 A: VecZnxToRef,
323 {
324 B::vec_znx_copy_impl(self, res, res_col, a, a_col)
325 }
326}
327
328impl<B> VecZnxStd for Module<B>
329where
330 B: Backend + VecZnxStdImpl<B>,
331{
332 fn vec_znx_std<A>(&self, basek: usize, a: &A, a_col: usize) -> f64
333 where
334 A: VecZnxToRef,
335 {
336 B::vec_znx_std_impl(self, basek, a, a_col)
337 }
338}
339
340impl<B> VecZnxFillUniform for Module<B>
341where
342 B: Backend + VecZnxFillUniformImpl<B>,
343{
344 fn vec_znx_fill_uniform<R>(&self, basek: usize, res: &mut R, res_col: usize, k: usize, source: &mut Source)
345 where
346 R: VecZnxToMut,
347 {
348 B::vec_znx_fill_uniform_impl(self, basek, res, res_col, k, source);
349 }
350}
351
352impl<B> VecZnxFillDistF64 for Module<B>
353where
354 B: Backend + VecZnxFillDistF64Impl<B>,
355{
356 fn vec_znx_fill_dist_f64<R, D: rand::prelude::Distribution<f64>>(
357 &self,
358 basek: usize,
359 res: &mut R,
360 res_col: usize,
361 k: usize,
362 source: &mut Source,
363 dist: D,
364 bound: f64,
365 ) where
366 R: VecZnxToMut,
367 {
368 B::vec_znx_fill_dist_f64_impl(self, basek, res, res_col, k, source, dist, bound);
369 }
370}
371
372impl<B> VecZnxAddDistF64 for Module<B>
373where
374 B: Backend + VecZnxAddDistF64Impl<B>,
375{
376 fn vec_znx_add_dist_f64<R, D: rand::prelude::Distribution<f64>>(
377 &self,
378 basek: usize,
379 res: &mut R,
380 res_col: usize,
381 k: usize,
382 source: &mut Source,
383 dist: D,
384 bound: f64,
385 ) where
386 R: VecZnxToMut,
387 {
388 B::vec_znx_add_dist_f64_impl(self, basek, res, res_col, k, source, dist, bound);
389 }
390}
391
392impl<B> VecZnxFillNormal for Module<B>
393where
394 B: Backend + VecZnxFillNormalImpl<B>,
395{
396 fn vec_znx_fill_normal<R>(
397 &self,
398 basek: usize,
399 res: &mut R,
400 res_col: usize,
401 k: usize,
402 source: &mut Source,
403 sigma: f64,
404 bound: f64,
405 ) where
406 R: VecZnxToMut,
407 {
408 B::vec_znx_fill_normal_impl(self, basek, res, res_col, k, source, sigma, bound);
409 }
410}
411
412impl<B> VecZnxAddNormal for Module<B>
413where
414 B: Backend + VecZnxAddNormalImpl<B>,
415{
416 fn vec_znx_add_normal<R>(
417 &self,
418 basek: usize,
419 res: &mut R,
420 res_col: usize,
421 k: usize,
422 source: &mut Source,
423 sigma: f64,
424 bound: f64,
425 ) where
426 R: VecZnxToMut,
427 {
428 B::vec_znx_add_normal_impl(self, basek, res, res_col, k, source, sigma, bound);
429 }
430}
431
432impl<B> VecZnxEncodeVeci64 for Module<B>
433where
434 B: Backend + VecZnxEncodeVeci64Impl<B>,
435{
436 fn encode_vec_i64<R>(&self, basek: usize, res: &mut R, res_col: usize, k: usize, data: &[i64], log_max: usize)
437 where
438 R: VecZnxToMut,
439 {
440 B::encode_vec_i64_impl(self, basek, res, res_col, k, data, log_max);
441 }
442}
443
444impl<B> VecZnxEncodeCoeffsi64 for Module<B>
445where
446 B: Backend + VecZnxEncodeCoeffsi64Impl<B>,
447{
448 fn encode_coeff_i64<R>(&self, basek: usize, res: &mut R, res_col: usize, k: usize, i: usize, data: i64, log_max: usize)
449 where
450 R: VecZnxToMut,
451 {
452 B::encode_coeff_i64_impl(self, basek, res, res_col, k, i, data, log_max);
453 }
454}
455
456impl<B> VecZnxDecodeVeci64 for Module<B>
457where
458 B: Backend + VecZnxDecodeVeci64Impl<B>,
459{
460 fn decode_vec_i64<R>(&self, basek: usize, res: &R, res_col: usize, k: usize, data: &mut [i64])
461 where
462 R: VecZnxToRef,
463 {
464 B::decode_vec_i64_impl(self, basek, res, res_col, k, data);
465 }
466}
467
468impl<B> VecZnxDecodeCoeffsi64 for Module<B>
469where
470 B: Backend + VecZnxDecodeCoeffsi64Impl<B>,
471{
472 fn decode_coeff_i64<R>(&self, basek: usize, res: &R, res_col: usize, k: usize, i: usize) -> i64
473 where
474 R: VecZnxToRef,
475 {
476 B::decode_coeff_i64_impl(self, basek, res, res_col, k, i)
477 }
478}
479
480impl<B> VecZnxDecodeVecFloat for Module<B>
481where
482 B: Backend + VecZnxDecodeVecFloatImpl<B>,
483{
484 fn decode_vec_float<R>(&self, basek: usize, res: &R, col_i: usize, data: &mut [rug::Float])
485 where
486 R: VecZnxToRef,
487 {
488 B::decode_vec_float_impl(self, basek, res, col_i, data);
489 }
490}