poulpy/poulpy-hal/src/api/svp_ppol.rs
poulpy-hal/src/api/svp_ppol.rsRaw
1use crate::layouts::{
2 Backend, ScalarZnxToRef, SvpPPolOwned, SvpPPolToMut, SvpPPolToRef, VecZnxDftToMut, VecZnxDftToRef, VecZnxToRef,
3};
4
5/// Allocates as [crate::layouts::SvpPPol].
6pub trait SvpPPolAlloc<B: Backend> {
7 fn svp_ppol_alloc(&self, cols: usize) -> SvpPPolOwned<B>;
8}
9
10/// Returns the size in bytes to allocate a [crate::layouts::SvpPPol].
11pub trait SvpPPolAllocBytes {
12 fn svp_ppol_bytes_of(&self, cols: usize) -> usize;
13}
14
15/// Consume a vector of bytes into a [crate::layouts::MatZnx].
16/// User must ensure that bytes is memory aligned and that it length is equal to [SvpPPolAllocBytes].
17pub trait SvpPPolFromBytes<B: Backend> {
18 fn svp_ppol_from_bytes(&self, cols: usize, bytes: Vec<u8>) -> SvpPPolOwned<B>;
19}
20
21/// Prepare a [crate::layouts::ScalarZnx] into an [crate::layouts::SvpPPol].
22pub trait SvpPrepare<B: Backend> {
23 fn svp_prepare<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
24 where
25 R: SvpPPolToMut<B>,
26 A: ScalarZnxToRef;
27}
28
29/// Apply a scalar-vector product between `a[a_col]` and `b[b_col]` and stores the result on `res[res_col]`.
30pub trait SvpApplyDft<B: Backend> {
31 fn svp_apply_dft<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
32 where
33 R: VecZnxDftToMut<B>,
34 A: SvpPPolToRef<B>,
35 C: VecZnxToRef;
36}
37
38/// Apply a scalar-vector product between `a[a_col]` and `b[b_col]` and stores the result on `res[res_col]`.
39pub trait SvpApplyDftToDft<B: Backend> {
40 fn svp_apply_dft_to_dft<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
41 where
42 R: VecZnxDftToMut<B>,
43 A: SvpPPolToRef<B>,
44 C: VecZnxDftToRef<B>;
45}
46
47/// Apply a scalar-vector product between `a[a_col]` and `b[b_col]` and adds the result on `res[res_col]`.
48pub trait SvpApplyDftToDftAdd<B: Backend> {
49 fn svp_apply_dft_to_dft_add<R, A, C>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, b: &C, b_col: usize)
50 where
51 R: VecZnxDftToMut<B>,
52 A: SvpPPolToRef<B>,
53 C: VecZnxDftToRef<B>;
54}
55
56/// Apply a scalar-vector product between `res[res_col]` and `a[a_col]` and stores the result on `res[res_col]`.
57pub trait SvpApplyDftToDftInplace<B: Backend> {
58 fn svp_apply_dft_to_dft_inplace<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize)
59 where
60 R: VecZnxDftToMut<B>,
61 A: SvpPPolToRef<B>;
62}