poulpy/base2k/src/vec_znx_big.rs
base2k/src/vec_znx_big.rsRaw
1use crate::ffi::vec_znx_big;
2use crate::znx_base::{GetZnxBase, ZnxAlloc, ZnxBase, ZnxBasics, ZnxInfos, ZnxLayout, ZnxSliceSize};
3use crate::{Backend, FFT64, Module, NTT120};
4use std::marker::PhantomData;
5
6const VEC_ZNX_BIG_ROWS: usize = 1;
7
8pub struct VecZnxBig<B: Backend> {
9 pub inner: ZnxBase,
10 pub _marker: PhantomData<B>,
11}
12
13impl<B: Backend> GetZnxBase for VecZnxBig<B> {
14 fn znx(&self) -> &ZnxBase {
15 &self.inner
16 }
17
18 fn znx_mut(&mut self) -> &mut ZnxBase {
19 &mut self.inner
20 }
21}
22
23impl<B: Backend> ZnxInfos for VecZnxBig<B> {}
24
25impl<B: Backend> ZnxAlloc<B> for VecZnxBig<B> {
26 type Scalar = u8;
27
28 fn from_bytes_borrow(module: &Module<B>, _rows: usize, cols: usize, size: usize, bytes: &mut [u8]) -> Self {
29 VecZnxBig {
30 inner: ZnxBase::from_bytes_borrow(module.n(), VEC_ZNX_BIG_ROWS, cols, size, bytes),
31 _marker: PhantomData,
32 }
33 }
34
35 fn bytes_of(module: &Module<B>, _rows: usize, cols: usize, size: usize) -> usize {
36 debug_assert_eq!(
37 _rows, VEC_ZNX_BIG_ROWS,
38 "rows != {} not supported for VecZnxBig",
39 VEC_ZNX_BIG_ROWS
40 );
41 unsafe { vec_znx_big::bytes_of_vec_znx_big(module.ptr, size as u64) as usize * cols }
42 }
43}
44
45impl ZnxLayout for VecZnxBig<FFT64> {
46 type Scalar = i64;
47}
48
49impl ZnxLayout for VecZnxBig<NTT120> {
50 type Scalar = i128;
51}
52
53impl ZnxBasics for VecZnxBig<FFT64> {}
54
55impl ZnxSliceSize for VecZnxBig<FFT64> {
56 fn sl(&self) -> usize {
57 self.n()
58 }
59}
60
61impl ZnxSliceSize for VecZnxBig<NTT120> {
62 fn sl(&self) -> usize {
63 self.n() * 4
64 }
65}
66
67impl ZnxBasics for VecZnxBig<NTT120> {}
68
69impl VecZnxBig<FFT64> {
70 pub fn print(&self, n: usize) {
71 (0..self.size()).for_each(|i| println!("{}: {:?}", i, &self.at_limb(i)[..n]));
72 }
73}