arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/core/src/elem.rs
core/src/elem.rsRaw
 1use base2k::{Backend, Module, VecZnxDft, VecZnxDftToMut, VecZnxDftToRef, ZnxInfos};
 2
 3use crate::{glwe_ciphertext_fourier::GLWECiphertextFourier, utils::derive_size};
 4
 5pub trait Infos {
 6    type Inner: ZnxInfos;
 7
 8    fn inner(&self) -> &Self::Inner;
 9
10    /// Returns the ring degree of the polynomials.
11    fn n(&self) -> usize {
12        self.inner().n()
13    }
14
15    /// Returns the base two logarithm of the ring dimension of the polynomials.
16    fn log_n(&self) -> usize {
17        self.inner().log_n()
18    }
19
20    /// Returns the number of rows.
21    fn rows(&self) -> usize {
22        self.inner().rows()
23    }
24
25    /// Returns the number of polynomials in each row.
26    fn cols(&self) -> usize {
27        self.inner().cols()
28    }
29
30    /// Returns the number of size per polynomial.
31    fn size(&self) -> usize {
32        let size: usize = self.inner().size();
33        debug_assert_eq!(size, derive_size(self.basek(), self.k()));
34        size
35    }
36
37    /// Returns the total number of small polynomials.
38    fn poly_count(&self) -> usize {
39        self.rows() * self.cols() * self.size()
40    }
41
42    /// Returns the base 2 logarithm of the ciphertext base.
43    fn basek(&self) -> usize;
44
45    /// Returns the bit precision of the ciphertext.
46    fn k(&self) -> usize;
47}
48
49pub trait GetRow<B: Backend> {
50    fn get_row<R>(&self, module: &Module<B>, row_i: usize, col_j: usize, res: &mut GLWECiphertextFourier<R, B>)
51    where
52        VecZnxDft<R, B>: VecZnxDftToMut<B>;
53}
54
55pub trait SetRow<B: Backend> {
56    fn set_row<A>(&mut self, module: &Module<B>, row_i: usize, col_j: usize, a: &GLWECiphertextFourier<A, B>)
57    where
58        VecZnxDft<A, B>: VecZnxDftToRef<B>;
59}