use crate::ffi::vec_znx_big; use crate::znx_base::{GetZnxBase, ZnxAlloc, ZnxBase, 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(&self) -> &mut Self::D { &mut self.data } } impl> ZnxView for VecZnxBig { type Scalar = i64; } impl>, B: Backend> VecZnxBig { pub(crate) fn bytes_of(module: &Module, cols: usize, size: usize) -> usize { unsafe { vec_znx_big::bytes_of_vec_znx_big(module.ptr, size as u64) as usize * cols } } pub(crate) fn new(module: &Module, cols: usize, size: usize) -> Self { let data = alloc_aligned::(Self::bytes_of(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() == Self::bytes_of(module, cols, size)); Self { data: data.into(), n: module.n(), cols, size, _phantom: PhantomData, } } } pub type VecZnxBigOwned = VecZnxBig, B>; // impl VecZnxBig { // pub fn print(&self, n: usize, col: usize) { // (0..self.size()).for_each(|i| println!("{}: {:?}", i, &self.at(col, i)[..n])); // } // }