mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 21:26:41 +01:00
wip
This commit is contained in:
committed by
Jean-Philippe Bossuat
parent
f72363cc4b
commit
2b2b994f7d
@@ -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;
|
||||
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -110,7 +110,7 @@ impl<D: DataRef> ZnxView for VecZnx<D> {
|
||||
}
|
||||
|
||||
impl VecZnx<Vec<u8>> {
|
||||
pub fn rsh_scratch_space(n: usize) -> usize {
|
||||
pub fn rsh_tmp_bytes(n: usize) -> usize {
|
||||
n * std::mem::size_of::<i64>()
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -98,7 +98,7 @@ impl<D: DataRef> ZnxView for Zn<D> {
|
||||
}
|
||||
|
||||
impl Zn<Vec<u8>> {
|
||||
pub fn rsh_scratch_space(n: usize) -> usize {
|
||||
pub fn rsh_tmp_bytes(n: usize) -> usize {
|
||||
n * std::mem::size_of::<i64>()
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user