use crate::ffi::vec_znx_big; use crate::znx_base::{GetZnxBase, ZnxAlloc, ZnxBase, ZnxInfos, ZnxLayout, ZnxSliceSize, ZnxZero}; use crate::{Backend, FFT64, Module, NTT120}; use std::marker::PhantomData; const VEC_ZNX_BIG_ROWS: usize = 1; pub struct VecZnxBig { pub inner: ZnxBase, pub _marker: PhantomData, } impl GetZnxBase for VecZnxBig { fn znx(&self) -> &ZnxBase { &self.inner } fn znx_mut(&mut self) -> &mut ZnxBase { &mut self.inner } } impl ZnxInfos for VecZnxBig {} impl ZnxAlloc for VecZnxBig { type Scalar = u8; fn from_bytes_borrow(module: &Module, _rows: usize, cols: usize, size: usize, bytes: &mut [u8]) -> Self { debug_assert_eq!(bytes.len(), Self::bytes_of(module, _rows, cols, size)); VecZnxBig { inner: ZnxBase::from_bytes_borrow(module.n(), VEC_ZNX_BIG_ROWS, cols, size, bytes), _marker: PhantomData, } } fn bytes_of(module: &Module, _rows: usize, cols: usize, size: usize) -> usize { debug_assert_eq!( _rows, VEC_ZNX_BIG_ROWS, "rows != {} not supported for VecZnxBig", VEC_ZNX_BIG_ROWS ); unsafe { vec_znx_big::bytes_of_vec_znx_big(module.ptr, size as u64) as usize * cols } } } impl ZnxLayout for VecZnxBig { type Scalar = i64; } impl ZnxLayout for VecZnxBig { type Scalar = i128; } impl ZnxZero for VecZnxBig {} impl ZnxSliceSize for VecZnxBig { fn sl(&self) -> usize { self.n() * self.cols() } } impl ZnxSliceSize for VecZnxBig { fn sl(&self) -> usize { self.n() * 4 * self.cols() } } impl ZnxZero for VecZnxBig {} impl VecZnxBig { pub fn print(&self, n: usize, col: usize) { (0..self.size()).for_each(|i| println!("{}: {:?}", i, &self.at(col, i)[..n])); } }