poulpy_hal/delegates/
vec_znx.rs

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