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