poulpy/core/src/glwe_plaintext.rs
core/src/glwe_plaintext.rsRaw
1use backend::{Backend, Module, VecZnx, VecZnxAlloc, VecZnxToMut, VecZnxToRef};
2
3use crate::{elem::Infos, utils::derive_size};
4
5pub struct GLWEPlaintext<C> {
6 pub data: VecZnx<C>,
7 pub basek: usize,
8 pub k: usize,
9}
10
11impl<T> Infos for GLWEPlaintext<T> {
12 type Inner = VecZnx<T>;
13
14 fn inner(&self) -> &Self::Inner {
15 &self.data
16 }
17
18 fn basek(&self) -> usize {
19 self.basek
20 }
21
22 fn k(&self) -> usize {
23 self.k
24 }
25}
26
27impl<C> VecZnxToMut for GLWEPlaintext<C>
28where
29 VecZnx<C>: VecZnxToMut,
30{
31 fn to_mut(&mut self) -> VecZnx<&mut [u8]> {
32 self.data.to_mut()
33 }
34}
35
36impl<C> VecZnxToRef for GLWEPlaintext<C>
37where
38 VecZnx<C>: VecZnxToRef,
39{
40 fn to_ref(&self) -> VecZnx<&[u8]> {
41 self.data.to_ref()
42 }
43}
44
45impl GLWEPlaintext<Vec<u8>> {
46 pub fn alloc<B: Backend>(module: &Module<B>, basek: usize, k: usize) -> Self {
47 Self {
48 data: module.new_vec_znx(1, derive_size(basek, k)),
49 basek: basek,
50 k,
51 }
52 }
53}