poulpy/backend/src/hal/api/scalar_znx.rs
backend/src/hal/api/scalar_znx.rsRaw
1use crate::hal::layouts::{ScalarZnxOwned, ScalarZnxToMut, ScalarZnxToRef};
2
3/// Allocates as [crate::hal::layouts::ScalarZnx].
4pub trait ScalarZnxAlloc {
5 fn scalar_znx_alloc(&self, cols: usize) -> ScalarZnxOwned;
6}
7
8/// Returns the size in bytes to allocate a [crate::hal::layouts::ScalarZnx].
9pub trait ScalarZnxAllocBytes {
10 fn scalar_znx_alloc_bytes(&self, cols: usize) -> usize;
11}
12
13/// Consume a vector of bytes into a [crate::hal::layouts::ScalarZnx].
14/// User must ensure that bytes is memory aligned and that it length is equal to [ScalarZnxAllocBytes].
15pub trait ScalarZnxFromBytes {
16 fn scalar_znx_from_bytes(&self, cols: usize, bytes: Vec<u8>) -> ScalarZnxOwned;
17}
18
19/// Applies the mapping X -> X^k to a\[a_col\] and write the result on res\[res_col\].
20pub trait ScalarZnxAutomorphism {
21 fn scalar_znx_automorphism<R, A>(&self, k: i64, res: &mut R, res_col: usize, a: &A, a_col: usize)
22 where
23 R: ScalarZnxToMut,
24 A: ScalarZnxToRef;
25}
26
27/// Applies the mapping X -> X^k on res\[res_col\].
28pub trait ScalarZnxAutomorphismInplace {
29 fn scalar_znx_automorphism_inplace<R>(&self, k: i64, res: &mut R, res_col: usize)
30 where
31 R: ScalarZnxToMut;
32}
33
34/// Multiply a\[a_col\] with (X^p - 1) and write the result on res\[res_col\].
35pub trait ScalarZnxMulXpMinusOne {
36 fn scalar_znx_mul_xp_minus_one<R, A>(&self, p: i64, r: &mut R, r_col: usize, a: &A, a_col: usize)
37 where
38 R: ScalarZnxToMut,
39 A: ScalarZnxToRef;
40}
41
42/// Multiply res\[res_col\] with (X^p - 1).
43pub trait ScalarZnxMulXpMinusOneInplace {
44 fn scalar_znx_mul_xp_minus_one_inplace<R>(&self, p: i64, res: &mut R, res_col: usize)
45 where
46 R: ScalarZnxToMut;
47}