use crate::ffi::vec_znx_big; use crate::znx_base::{ZnxInfos, ZnxView}; use crate::{Backend, DataView, DataViewMut, FFT64, Module, alloc_aligned}; use std::marker::PhantomData; // const VEC_ZNX_BIG_ROWS: usize = 1; /// VecZnxBig is `Backend` dependent, denoted with backend generic `B` pub struct VecZnxBig { data: D, n: usize, cols: usize, size: usize, _phantom: PhantomData, } impl ZnxInfos for VecZnxBig { fn cols(&self) -> usize { self.cols } fn rows(&self) -> usize { 1 } fn n(&self) -> usize { self.n } fn size(&self) -> usize { self.size } fn sl(&self) -> usize { self.cols() * self.n() } } impl DataView for VecZnxBig { type D = D; fn data(&self) -> &Self::D { &self.data } } impl DataViewMut for VecZnxBig { fn data_mut(&mut self) -> &mut Self::D { &mut self.data } } impl> ZnxView for VecZnxBig { type Scalar = i64; } pub(crate) fn bytes_of_vec_znx_big(module: &Module, cols: usize, size: usize) -> usize { unsafe { vec_znx_big::bytes_of_vec_znx_big(module.ptr, size as u64) as usize * cols } } impl>, B: Backend> VecZnxBig { pub(crate) fn new(module: &Module, cols: usize, size: usize) -> Self { let data = alloc_aligned::(bytes_of_vec_znx_big(module, cols, size)); Self { data: data.into(), n: module.n(), cols, size, _phantom: PhantomData, } } pub(crate) fn new_from_bytes(module: &Module, cols: usize, size: usize, bytes: impl Into>) -> Self { let data: Vec = bytes.into(); assert!(data.len() == bytes_of_vec_znx_big(module, cols, size)); Self { data: data.into(), n: module.n(), cols, size, _phantom: PhantomData, } } } impl VecZnxBig { pub(crate) fn from_data(data: D, n: usize, cols: usize, size: usize) -> Self { Self { data, n, cols, size, _phantom: PhantomData, } } } pub type VecZnxBigOwned = VecZnxBig, B>; impl VecZnxBig, B> { pub fn to_mut(&mut self) -> VecZnxBig<&mut [u8], B> { VecZnxBig { data: self.data.as_mut_slice(), n: self.n, cols: self.cols, size: self.size, _phantom: PhantomData, } } pub fn to_ref(&self) -> VecZnxBig<&[u8], B> { VecZnxBig { data: self.data.as_slice(), n: self.n, cols: self.cols, size: self.size, _phantom: PhantomData, } } }