arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/core/src/elem.rs
core/src/elem.rsRaw
 1use backend::hal::{
 2    api::{VecZnxCopy, VecZnxFillUniform, ZnxInfos},
 3    layouts::{Backend, Module},
 4};
 5
 6pub trait Infos {
 7    type Inner: ZnxInfos;
 8
 9    fn inner(&self) -> &Self::Inner;
10
11    /// Returns the ring degree of the polynomials.
12    fn n(&self) -> usize {
13        self.inner().n()
14    }
15
16    /// Returns the base two logarithm of the ring dimension of the polynomials.
17    fn log_n(&self) -> usize {
18        self.inner().log_n()
19    }
20
21    /// Returns the number of rows.
22    fn rows(&self) -> usize {
23        self.inner().rows()
24    }
25
26    /// Returns the number of polynomials in each row.
27    fn cols(&self) -> usize {
28        self.inner().cols()
29    }
30
31    fn rank(&self) -> usize {
32        self.cols() - 1
33    }
34
35    /// Returns the number of size per polynomial.
36    fn size(&self) -> usize {
37        let size: usize = self.inner().size();
38        debug_assert!(size >= self.k().div_ceil(self.basek()));
39        size
40    }
41
42    /// Returns the total number of small polynomials.
43    fn poly_count(&self) -> usize {
44        self.rows() * self.cols() * self.size()
45    }
46
47    /// Returns the base 2 logarithm of the ciphertext base.
48    fn basek(&self) -> usize;
49
50    /// Returns the bit precision of the ciphertext.
51    fn k(&self) -> usize;
52}
53
54pub trait SetMetaData {
55    fn set_basek(&mut self, basek: usize);
56    fn set_k(&mut self, k: usize);
57}
58
59pub trait Decompress<B: Backend, C> {
60    fn decompress(&mut self, module: &Module<B>, other: &C)
61    where
62        Module<B>: VecZnxFillUniform + VecZnxCopy;
63}