This commit is contained in:
Pro7ech
2025-10-14 18:46:25 +02:00
parent 0533cdff8a
commit 72dca47cbe
153 changed files with 3099 additions and 1956 deletions

View File

@@ -9,7 +9,7 @@ pub trait SvpPPolAlloc<B: Backend> {
/// Returns the size in bytes to allocate a [crate::layouts::SvpPPol].
pub trait SvpPPolAllocBytes {
fn svp_ppol_alloc_bytes(&self, cols: usize) -> usize;
fn svp_ppol_bytes_of(&self, cols: usize) -> usize;
}
/// Consume a vector of bytes into a [crate::layouts::MatZnx].

View File

@@ -17,7 +17,7 @@ pub trait VecZnxBigAlloc<B: Backend> {
/// Returns the size in bytes to allocate a [crate::layouts::VecZnxBig].
pub trait VecZnxBigAllocBytes {
fn vec_znx_big_alloc_bytes(&self, cols: usize, size: usize) -> usize;
fn vec_znx_big_bytes_of(&self, cols: usize, size: usize) -> usize;
}
/// Consume a vector of bytes into a [crate::layouts::VecZnxBig].

View File

@@ -11,7 +11,7 @@ pub trait VecZnxDftFromBytes<B: Backend> {
}
pub trait VecZnxDftAllocBytes {
fn vec_znx_dft_alloc_bytes(&self, cols: usize, size: usize) -> usize;
fn vec_znx_dft_bytes_of(&self, cols: usize, size: usize) -> usize;
}
pub trait VecZnxDftApply<B: Backend> {

View File

@@ -7,7 +7,7 @@ pub trait VmpPMatAlloc<B: Backend> {
}
pub trait VmpPMatAllocBytes {
fn vmp_pmat_alloc_bytes(&self, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize;
fn vmp_pmat_bytes_of(&self, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize;
}
pub trait VmpPMatFromBytes<B: Backend> {

View File

@@ -34,8 +34,8 @@ impl<B> SvpPPolAllocBytes for Module<B>
where
B: Backend + SvpPPolAllocBytesImpl<B>,
{
fn svp_ppol_alloc_bytes(&self, cols: usize) -> usize {
B::svp_ppol_alloc_bytes_impl(self.n(), cols)
fn svp_ppol_bytes_of(&self, cols: usize) -> usize {
B::svp_ppol_bytes_of_impl(self.n(), cols)
}
}

View File

@@ -53,8 +53,8 @@ impl<B> VecZnxBigAllocBytes for Module<B>
where
B: Backend + VecZnxBigAllocBytesImpl<B>,
{
fn vec_znx_big_alloc_bytes(&self, cols: usize, size: usize) -> usize {
B::vec_znx_big_alloc_bytes_impl(self.n(), cols, size)
fn vec_znx_big_bytes_of(&self, cols: usize, size: usize) -> usize {
B::vec_znx_big_bytes_of_impl(self.n(), cols, size)
}
}

View File

@@ -28,8 +28,8 @@ impl<B> VecZnxDftAllocBytes for Module<B>
where
B: Backend + VecZnxDftAllocBytesImpl<B>,
{
fn vec_znx_dft_alloc_bytes(&self, cols: usize, size: usize) -> usize {
B::vec_znx_dft_alloc_bytes_impl(self.n(), cols, size)
fn vec_znx_dft_bytes_of(&self, cols: usize, size: usize) -> usize {
B::vec_znx_dft_bytes_of_impl(self.n(), cols, size)
}
}

View File

@@ -27,8 +27,8 @@ impl<B> VmpPMatAllocBytes for Module<B>
where
B: Backend + VmpPMatAllocBytesImpl<B>,
{
fn vmp_pmat_alloc_bytes(&self, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize {
B::vmp_pmat_alloc_bytes_impl(self.n(), rows, cols_in, cols_out, size)
fn vmp_pmat_bytes_of(&self, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize {
B::vmp_pmat_bytes_of_impl(self.n(), rows, cols_in, cols_out, size)
}
}

View File

@@ -114,12 +114,12 @@ impl<D: Data> MatZnx<D> {
}
impl MatZnx<Vec<u8>> {
pub fn alloc_bytes(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize {
rows * cols_in * VecZnx::<Vec<u8>>::alloc_bytes(n, cols_out, size)
pub fn bytes_of(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize {
rows * cols_in * VecZnx::<Vec<u8>>::bytes_of(n, cols_out, size)
}
pub fn alloc(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> Self {
let data: Vec<u8> = alloc_aligned(Self::alloc_bytes(n, rows, cols_in, cols_out, size));
let data: Vec<u8> = alloc_aligned(Self::bytes_of(n, rows, cols_in, cols_out, size));
Self {
data,
n,
@@ -132,7 +132,7 @@ impl MatZnx<Vec<u8>> {
pub fn from_bytes(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize, bytes: impl Into<Vec<u8>>) -> Self {
let data: Vec<u8> = bytes.into();
assert!(data.len() == Self::alloc_bytes(n, rows, cols_in, cols_out, size));
assert!(data.len() == Self::bytes_of(n, rows, cols_in, cols_out, size));
Self {
data,
n,
@@ -153,7 +153,7 @@ impl<D: DataRef> MatZnx<D> {
}
let self_ref: MatZnx<&[u8]> = self.to_ref();
let nb_bytes: usize = VecZnx::<Vec<u8>>::alloc_bytes(self.n, self.cols_out, self.size);
let nb_bytes: usize = VecZnx::<Vec<u8>>::bytes_of(self.n, self.cols_out, self.size);
let start: usize = nb_bytes * self.cols() * row + col * nb_bytes;
let end: usize = start + nb_bytes;
@@ -181,7 +181,7 @@ impl<D: DataMut> MatZnx<D> {
let size: usize = self.size();
let self_ref: MatZnx<&mut [u8]> = self.to_mut();
let nb_bytes: usize = VecZnx::<Vec<u8>>::alloc_bytes(n, cols_out, size);
let nb_bytes: usize = VecZnx::<Vec<u8>>::bytes_of(n, cols_out, size);
let start: usize = nb_bytes * cols_in * row + col * nb_bytes;
let end: usize = start + nb_bytes;

View File

@@ -132,18 +132,18 @@ impl<D: DataMut> ScalarZnx<D> {
}
impl ScalarZnx<Vec<u8>> {
pub fn alloc_bytes(n: usize, cols: usize) -> usize {
pub fn bytes_of(n: usize, cols: usize) -> usize {
n * cols * size_of::<i64>()
}
pub fn alloc(n: usize, cols: usize) -> Self {
let data: Vec<u8> = alloc_aligned::<u8>(Self::alloc_bytes(n, cols));
let data: Vec<u8> = alloc_aligned::<u8>(Self::bytes_of(n, cols));
Self { data, n, cols }
}
pub fn from_bytes(n: usize, cols: usize, bytes: impl Into<Vec<u8>>) -> Self {
let data: Vec<u8> = bytes.into();
assert!(data.len() == Self::alloc_bytes(n, cols));
assert!(data.len() == Self::bytes_of(n, cols));
Self { data, n, cols }
}
}

View File

@@ -77,7 +77,7 @@ where
B: SvpPPolAllocBytesImpl<B>,
{
pub fn alloc(n: usize, cols: usize) -> Self {
let data: Vec<u8> = alloc_aligned::<u8>(B::svp_ppol_alloc_bytes_impl(n, cols));
let data: Vec<u8> = alloc_aligned::<u8>(B::svp_ppol_bytes_of_impl(n, cols));
Self {
data: data.into(),
n,
@@ -88,7 +88,7 @@ where
pub fn from_bytes(n: usize, cols: usize, bytes: impl Into<Vec<u8>>) -> Self {
let data: Vec<u8> = bytes.into();
assert!(data.len() == B::svp_ppol_alloc_bytes_impl(n, cols));
assert!(data.len() == B::svp_ppol_bytes_of_impl(n, cols));
Self {
data: data.into(),
n,

View File

@@ -125,12 +125,12 @@ impl<D: DataMut> ZnxZero for VecZnx<D> {
}
impl VecZnx<Vec<u8>> {
pub fn alloc_bytes(n: usize, cols: usize, size: usize) -> usize {
pub fn bytes_of(n: usize, cols: usize, size: usize) -> usize {
n * cols * size * size_of::<i64>()
}
pub fn alloc(n: usize, cols: usize, size: usize) -> Self {
let data: Vec<u8> = alloc_aligned::<u8>(Self::alloc_bytes(n, cols, size));
let data: Vec<u8> = alloc_aligned::<u8>(Self::bytes_of(n, cols, size));
Self {
data,
n,
@@ -142,7 +142,7 @@ impl VecZnx<Vec<u8>> {
pub fn from_bytes<Scalar: Sized>(n: usize, cols: usize, size: usize, bytes: impl Into<Vec<u8>>) -> Self {
let data: Vec<u8> = bytes.into();
assert!(data.len() == Self::alloc_bytes(n, cols, size));
assert!(data.len() == Self::bytes_of(n, cols, size));
Self {
data,
n,

View File

@@ -96,7 +96,7 @@ where
B: VecZnxBigAllocBytesImpl<B>,
{
pub fn alloc(n: usize, cols: usize, size: usize) -> Self {
let data = alloc_aligned::<u8>(B::vec_znx_big_alloc_bytes_impl(n, cols, size));
let data = alloc_aligned::<u8>(B::vec_znx_big_bytes_of_impl(n, cols, size));
Self {
data: data.into(),
n,
@@ -109,7 +109,7 @@ where
pub fn from_bytes(n: usize, cols: usize, size: usize, bytes: impl Into<Vec<u8>>) -> Self {
let data: Vec<u8> = bytes.into();
assert!(data.len() == B::vec_znx_big_alloc_bytes_impl(n, cols, size));
assert!(data.len() == B::vec_znx_big_bytes_of_impl(n, cols, size));
Self {
data: data.into(),
n,

View File

@@ -116,7 +116,7 @@ where
B: VecZnxDftAllocBytesImpl<B>,
{
pub fn alloc(n: usize, cols: usize, size: usize) -> Self {
let data: Vec<u8> = alloc_aligned::<u8>(B::vec_znx_dft_alloc_bytes_impl(n, cols, size));
let data: Vec<u8> = alloc_aligned::<u8>(B::vec_znx_dft_bytes_of_impl(n, cols, size));
Self {
data: data.into(),
n,
@@ -129,7 +129,7 @@ where
pub fn from_bytes(n: usize, cols: usize, size: usize, bytes: impl Into<Vec<u8>>) -> Self {
let data: Vec<u8> = bytes.into();
assert!(data.len() == B::vec_znx_dft_alloc_bytes_impl(n, cols, size));
assert!(data.len() == B::vec_znx_dft_bytes_of_impl(n, cols, size));
Self {
data: data.into(),
n,

View File

@@ -88,9 +88,7 @@ where
B: VmpPMatAllocBytesImpl<B>,
{
pub fn alloc(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> Self {
let data: Vec<u8> = alloc_aligned(B::vmp_pmat_alloc_bytes_impl(
n, rows, cols_in, cols_out, size,
));
let data: Vec<u8> = alloc_aligned(B::vmp_pmat_bytes_of_impl(n, rows, cols_in, cols_out, size));
Self {
data: data.into(),
n,
@@ -104,7 +102,7 @@ where
pub fn from_bytes(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize, bytes: impl Into<Vec<u8>>) -> Self {
let data: Vec<u8> = bytes.into();
assert!(data.len() == B::vmp_pmat_alloc_bytes_impl(n, rows, cols_in, cols_out, size));
assert!(data.len() == B::vmp_pmat_bytes_of_impl(n, rows, cols_in, cols_out, size));
Self {
data: data.into(),
n,

View File

@@ -113,12 +113,12 @@ impl<D: DataMut> ZnxZero for Zn<D> {
}
impl Zn<Vec<u8>> {
pub fn alloc_bytes(n: usize, cols: usize, size: usize) -> usize {
pub fn bytes_of(n: usize, cols: usize, size: usize) -> usize {
n * cols * size * size_of::<i64>()
}
pub fn alloc(n: usize, cols: usize, size: usize) -> Self {
let data: Vec<u8> = alloc_aligned::<u8>(Self::alloc_bytes(n, cols, size));
let data: Vec<u8> = alloc_aligned::<u8>(Self::bytes_of(n, cols, size));
Self {
data,
n,
@@ -130,7 +130,7 @@ impl Zn<Vec<u8>> {
pub fn from_bytes<Scalar: Sized>(n: usize, cols: usize, size: usize, bytes: impl Into<Vec<u8>>) -> Self {
let data: Vec<u8> = bytes.into();
assert!(data.len() == Self::alloc_bytes(n, cols, size));
assert!(data.len() == Self::bytes_of(n, cols, size));
Self {
data,
n,

View File

@@ -23,7 +23,7 @@ pub unsafe trait SvpPPolAllocImpl<B: Backend> {
/// * See [crate::api::SvpPPolAllocBytes] for corresponding public API.
/// # Safety [crate::doc::backend_safety] for safety contract.
pub unsafe trait SvpPPolAllocBytesImpl<B: Backend> {
fn svp_ppol_alloc_bytes_impl(n: usize, cols: usize) -> usize;
fn svp_ppol_bytes_of_impl(n: usize, cols: usize) -> usize;
}
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe)

View File

@@ -35,7 +35,7 @@ pub unsafe trait VecZnxBigFromBytesImpl<B: Backend> {
/// * See [crate::api::VecZnxBigAllocBytes] for corresponding public API.
/// # Safety [crate::doc::backend_safety] for safety contract.
pub unsafe trait VecZnxBigAllocBytesImpl<B: Backend> {
fn vec_znx_big_alloc_bytes_impl(n: usize, cols: usize, size: usize) -> usize;
fn vec_znx_big_bytes_of_impl(n: usize, cols: usize, size: usize) -> usize;
}
#[allow(clippy::too_many_arguments)]

View File

@@ -42,7 +42,7 @@ pub unsafe trait VecZnxDftApplyImpl<B: Backend> {
/// * See [crate::api::VecZnxDftAllocBytes] for corresponding public API.
/// # Safety [crate::doc::backend_safety] for safety contract.
pub unsafe trait VecZnxDftAllocBytesImpl<B: Backend> {
fn vec_znx_dft_alloc_bytes_impl(n: usize, cols: usize, size: usize) -> usize;
fn vec_znx_dft_bytes_of_impl(n: usize, cols: usize, size: usize) -> usize;
}
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe)

View File

@@ -15,7 +15,7 @@ pub unsafe trait VmpPMatAllocImpl<B: Backend> {
/// * See [crate::api::VmpPMatAllocBytes] for corresponding public API.
/// # Safety [crate::doc::backend_safety] for safety contract.
pub unsafe trait VmpPMatAllocBytesImpl<B: Backend> {
fn vmp_pmat_alloc_bytes_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize;
fn vmp_pmat_bytes_of_impl(n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> usize;
}
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe)

View File

@@ -140,7 +140,7 @@ where
assert!(a.cols() <= cols);
}
let (data, tmp_bytes) = tmp_bytes.split_at_mut(BE::vec_znx_dft_alloc_bytes_impl(n, cols, size));
let (data, tmp_bytes) = tmp_bytes.split_at_mut(BE::vec_znx_dft_bytes_of_impl(n, cols, size));
let mut a_dft: VecZnxDft<&mut [u8], BE> = VecZnxDft::from_data(cast_mut(data), n, cols, size);