mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
rename raw dft ops
This commit is contained in:
@@ -14,26 +14,33 @@ pub trait VecZnxDftAllocBytes {
|
||||
fn vec_znx_dft_alloc_bytes(&self, cols: usize, size: usize) -> usize;
|
||||
}
|
||||
|
||||
pub trait VecZnxDftToVecZnxBigTmpBytes {
|
||||
fn vec_znx_dft_to_vec_znx_big_tmp_bytes(&self) -> usize;
|
||||
pub trait DFT<B: Backend> {
|
||||
fn dft<R, A>(&self, step: usize, offset: usize, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
||||
where
|
||||
R: VecZnxDftToMut<B>,
|
||||
A: VecZnxToRef;
|
||||
}
|
||||
|
||||
pub trait VecZnxDftToVecZnxBig<B: Backend> {
|
||||
fn vec_znx_dft_to_vec_znx_big<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>)
|
||||
pub trait VecZnxIDFTTmpBytes {
|
||||
fn vec_znx_idft_tmp_bytes(&self) -> usize;
|
||||
}
|
||||
|
||||
pub trait IDFT<B: Backend> {
|
||||
fn idft<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: VecZnxBigToMut<B>,
|
||||
A: VecZnxDftToRef<B>;
|
||||
}
|
||||
|
||||
pub trait VecZnxDftToVecZnxBigTmpA<B: Backend> {
|
||||
fn vec_znx_dft_to_vec_znx_big_tmp_a<R, A>(&self, res: &mut R, res_col: usize, a: &mut A, a_col: usize)
|
||||
pub trait IDFTTmpA<B: Backend> {
|
||||
fn idft_tmp_a<R, A>(&self, res: &mut R, res_col: usize, a: &mut A, a_col: usize)
|
||||
where
|
||||
R: VecZnxBigToMut<B>,
|
||||
A: VecZnxDftToMut<B>;
|
||||
}
|
||||
|
||||
pub trait VecZnxDftToVecZnxBigConsume<B: Backend> {
|
||||
fn vec_znx_dft_to_vec_znx_big_consume<D: Data>(&self, a: VecZnxDft<D, B>) -> VecZnxBig<D, B>
|
||||
pub trait IDFTConsume<B: Backend> {
|
||||
fn vec_znx_idft_consume<D: Data>(&self, a: VecZnxDft<D, B>) -> VecZnxBig<D, B>
|
||||
where
|
||||
VecZnxDft<D, B>: VecZnxDftToMut<B>;
|
||||
}
|
||||
@@ -82,13 +89,6 @@ pub trait VecZnxDftCopy<B: Backend> {
|
||||
A: VecZnxDftToRef<B>;
|
||||
}
|
||||
|
||||
pub trait VecZnxDftFromVecZnx<B: Backend> {
|
||||
fn vec_znx_dft_from_vec_znx<R, A>(&self, step: usize, offset: usize, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
||||
where
|
||||
R: VecZnxDftToMut<B>,
|
||||
A: VecZnxToRef;
|
||||
}
|
||||
|
||||
pub trait VecZnxDftZero<B: Backend> {
|
||||
fn vec_znx_dft_zero<R>(&self, res: &mut R)
|
||||
where
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
use crate::{
|
||||
api::{
|
||||
VecZnxDftAdd, VecZnxDftAddInplace, VecZnxDftAlloc, VecZnxDftAllocBytes, VecZnxDftCopy, VecZnxDftFromBytes,
|
||||
VecZnxDftFromVecZnx, VecZnxDftSub, VecZnxDftSubABInplace, VecZnxDftSubBAInplace, VecZnxDftToVecZnxBig,
|
||||
VecZnxDftToVecZnxBigConsume, VecZnxDftToVecZnxBigTmpA, VecZnxDftToVecZnxBigTmpBytes, VecZnxDftZero,
|
||||
DFT, IDFT, IDFTConsume, IDFTTmpA, VecZnxDftAdd, VecZnxDftAddInplace, VecZnxDftAlloc, VecZnxDftAllocBytes, VecZnxDftCopy,
|
||||
VecZnxDftFromBytes, VecZnxDftSub, VecZnxDftSubABInplace, VecZnxDftSubBAInplace, VecZnxDftZero, VecZnxIDFTTmpBytes,
|
||||
},
|
||||
layouts::{
|
||||
Backend, Data, Module, Scratch, VecZnxBig, VecZnxBigToMut, VecZnxDft, VecZnxDftOwned, VecZnxDftToMut, VecZnxDftToRef,
|
||||
VecZnxToRef,
|
||||
},
|
||||
oep::{
|
||||
VecZnxDftAddImpl, VecZnxDftAddInplaceImpl, VecZnxDftAllocBytesImpl, VecZnxDftAllocImpl, VecZnxDftCopyImpl,
|
||||
VecZnxDftFromBytesImpl, VecZnxDftFromVecZnxImpl, VecZnxDftSubABInplaceImpl, VecZnxDftSubBAInplaceImpl, VecZnxDftSubImpl,
|
||||
VecZnxDftToVecZnxBigConsumeImpl, VecZnxDftToVecZnxBigImpl, VecZnxDftToVecZnxBigTmpAImpl,
|
||||
VecZnxDftToVecZnxBigTmpBytesImpl, VecZnxDftZeroImpl,
|
||||
DFTImpl, IDFTConsumeImpl, IDFTImpl, IDFTTmpAImpl, VecZnxDftAddImpl, VecZnxDftAddInplaceImpl, VecZnxDftAllocBytesImpl,
|
||||
VecZnxDftAllocImpl, VecZnxDftCopyImpl, VecZnxDftFromBytesImpl, VecZnxDftSubABInplaceImpl, VecZnxDftSubBAInplaceImpl,
|
||||
VecZnxDftSubImpl, VecZnxDftZeroImpl, VecZnxIDFTTmpBytesImpl,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -43,63 +41,63 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> VecZnxDftToVecZnxBigTmpBytes for Module<B>
|
||||
impl<B> VecZnxIDFTTmpBytes for Module<B>
|
||||
where
|
||||
B: Backend + VecZnxDftToVecZnxBigTmpBytesImpl<B>,
|
||||
B: Backend + VecZnxIDFTTmpBytesImpl<B>,
|
||||
{
|
||||
fn vec_znx_dft_to_vec_znx_big_tmp_bytes(&self) -> usize {
|
||||
B::vec_znx_dft_to_vec_znx_big_tmp_bytes_impl(self)
|
||||
fn vec_znx_idft_tmp_bytes(&self) -> usize {
|
||||
B::vec_znx_idft_tmp_bytes_impl(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> VecZnxDftToVecZnxBig<B> for Module<B>
|
||||
impl<B> IDFT<B> for Module<B>
|
||||
where
|
||||
B: Backend + VecZnxDftToVecZnxBigImpl<B>,
|
||||
B: Backend + IDFTImpl<B>,
|
||||
{
|
||||
fn vec_znx_dft_to_vec_znx_big<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>)
|
||||
fn idft<R, A>(&self, res: &mut R, res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: VecZnxBigToMut<B>,
|
||||
A: VecZnxDftToRef<B>,
|
||||
{
|
||||
B::vec_znx_dft_to_vec_znx_big_impl(self, res, res_col, a, a_col, scratch);
|
||||
B::idft_impl(self, res, res_col, a, a_col, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> VecZnxDftToVecZnxBigTmpA<B> for Module<B>
|
||||
impl<B> IDFTTmpA<B> for Module<B>
|
||||
where
|
||||
B: Backend + VecZnxDftToVecZnxBigTmpAImpl<B>,
|
||||
B: Backend + IDFTTmpAImpl<B>,
|
||||
{
|
||||
fn vec_znx_dft_to_vec_znx_big_tmp_a<R, A>(&self, res: &mut R, res_col: usize, a: &mut A, a_col: usize)
|
||||
fn idft_tmp_a<R, A>(&self, res: &mut R, res_col: usize, a: &mut A, a_col: usize)
|
||||
where
|
||||
R: VecZnxBigToMut<B>,
|
||||
A: VecZnxDftToMut<B>,
|
||||
{
|
||||
B::vec_znx_dft_to_vec_znx_big_tmp_a_impl(self, res, res_col, a, a_col);
|
||||
B::idft_tmp_a_impl(self, res, res_col, a, a_col);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> VecZnxDftToVecZnxBigConsume<B> for Module<B>
|
||||
impl<B> IDFTConsume<B> for Module<B>
|
||||
where
|
||||
B: Backend + VecZnxDftToVecZnxBigConsumeImpl<B>,
|
||||
B: Backend + IDFTConsumeImpl<B>,
|
||||
{
|
||||
fn vec_znx_dft_to_vec_znx_big_consume<D: Data>(&self, a: VecZnxDft<D, B>) -> VecZnxBig<D, B>
|
||||
fn vec_znx_idft_consume<D: Data>(&self, a: VecZnxDft<D, B>) -> VecZnxBig<D, B>
|
||||
where
|
||||
VecZnxDft<D, B>: VecZnxDftToMut<B>,
|
||||
{
|
||||
B::vec_znx_dft_to_vec_znx_big_consume_impl(self, a)
|
||||
B::idft_consume_impl(self, a)
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> VecZnxDftFromVecZnx<B> for Module<B>
|
||||
impl<B> DFT<B> for Module<B>
|
||||
where
|
||||
B: Backend + VecZnxDftFromVecZnxImpl<B>,
|
||||
B: Backend + DFTImpl<B>,
|
||||
{
|
||||
fn vec_znx_dft_from_vec_znx<R, A>(&self, step: usize, offset: usize, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
||||
fn dft<R, A>(&self, step: usize, offset: usize, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
||||
where
|
||||
R: VecZnxDftToMut<B>,
|
||||
A: VecZnxToRef,
|
||||
{
|
||||
B::vec_znx_dft_from_vec_znx_impl(self, step, offset, res, res_col, a, a_col);
|
||||
B::dft_impl(self, step, offset, res, res_col, a, a_col);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,17 @@ pub unsafe trait VecZnxDftFromBytesImpl<B: Backend> {
|
||||
fn vec_znx_dft_from_bytes_impl(n: usize, cols: usize, size: usize, bytes: Vec<u8>) -> VecZnxDftOwned<B>;
|
||||
}
|
||||
|
||||
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe)
|
||||
/// * See TODO for reference code.
|
||||
/// * See TODO for corresponding public API.
|
||||
/// # Safety [crate::doc::backend_safety] for safety contract.
|
||||
pub unsafe trait DFTImpl<B: Backend> {
|
||||
fn dft_impl<R, A>(module: &Module<B>, step: usize, offset: usize, res: &mut R, res_col: usize, a: &A, a_col: usize)
|
||||
where
|
||||
R: VecZnxDftToMut<B>,
|
||||
A: VecZnxToRef;
|
||||
}
|
||||
|
||||
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe)
|
||||
/// * See TODO for reference code.
|
||||
/// * See TODO for corresponding public API.
|
||||
@@ -31,23 +42,17 @@ pub unsafe trait VecZnxDftAllocBytesImpl<B: Backend> {
|
||||
/// * See TODO for reference code.
|
||||
/// * See TODO for corresponding public API.
|
||||
/// # Safety [crate::doc::backend_safety] for safety contract.
|
||||
pub unsafe trait VecZnxDftToVecZnxBigTmpBytesImpl<B: Backend> {
|
||||
fn vec_znx_dft_to_vec_znx_big_tmp_bytes_impl(module: &Module<B>) -> usize;
|
||||
pub unsafe trait VecZnxIDFTTmpBytesImpl<B: Backend> {
|
||||
fn vec_znx_idft_tmp_bytes_impl(module: &Module<B>) -> usize;
|
||||
}
|
||||
|
||||
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe)
|
||||
/// * See TODO for reference code.
|
||||
/// * See TODO for corresponding public API.
|
||||
/// # Safety [crate::doc::backend_safety] for safety contract.
|
||||
pub unsafe trait VecZnxDftToVecZnxBigImpl<B: Backend> {
|
||||
fn vec_znx_dft_to_vec_znx_big_impl<R, A>(
|
||||
module: &Module<B>,
|
||||
res: &mut R,
|
||||
res_col: usize,
|
||||
a: &A,
|
||||
a_col: usize,
|
||||
scratch: &mut Scratch<B>,
|
||||
) where
|
||||
pub unsafe trait IDFTImpl<B: Backend> {
|
||||
fn idft_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &A, a_col: usize, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: VecZnxBigToMut<B>,
|
||||
A: VecZnxDftToRef<B>;
|
||||
}
|
||||
@@ -56,8 +61,8 @@ pub unsafe trait VecZnxDftToVecZnxBigImpl<B: Backend> {
|
||||
/// * See TODO for reference code.
|
||||
/// * See for corresponding public API.
|
||||
/// # Safety [crate::doc::backend_safety] for safety contract.
|
||||
pub unsafe trait VecZnxDftToVecZnxBigTmpAImpl<B: Backend> {
|
||||
fn vec_znx_dft_to_vec_znx_big_tmp_a_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &mut A, a_col: usize)
|
||||
pub unsafe trait IDFTTmpAImpl<B: Backend> {
|
||||
fn idft_tmp_a_impl<R, A>(module: &Module<B>, res: &mut R, res_col: usize, a: &mut A, a_col: usize)
|
||||
where
|
||||
R: VecZnxBigToMut<B>,
|
||||
A: VecZnxDftToMut<B>;
|
||||
@@ -67,8 +72,8 @@ pub unsafe trait VecZnxDftToVecZnxBigTmpAImpl<B: Backend> {
|
||||
/// * See TODO for reference code.
|
||||
/// * See TODO for corresponding public API.
|
||||
/// # Safety [crate::doc::backend_safety] for safety contract.
|
||||
pub unsafe trait VecZnxDftToVecZnxBigConsumeImpl<B: Backend> {
|
||||
fn vec_znx_dft_to_vec_znx_big_consume_impl<D: Data>(module: &Module<B>, a: VecZnxDft<D, B>) -> VecZnxBig<D, B>
|
||||
pub unsafe trait IDFTConsumeImpl<B: Backend> {
|
||||
fn idft_consume_impl<D: Data>(module: &Module<B>, a: VecZnxDft<D, B>) -> VecZnxBig<D, B>
|
||||
where
|
||||
VecZnxDft<D, B>: VecZnxDftToMut<B>;
|
||||
}
|
||||
@@ -148,24 +153,6 @@ pub unsafe trait VecZnxDftCopyImpl<B: Backend> {
|
||||
A: VecZnxDftToRef<B>;
|
||||
}
|
||||
|
||||
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe)
|
||||
/// * See TODO for reference code.
|
||||
/// * See TODO for corresponding public API.
|
||||
/// # Safety [crate::doc::backend_safety] for safety contract.
|
||||
pub unsafe trait VecZnxDftFromVecZnxImpl<B: Backend> {
|
||||
fn vec_znx_dft_from_vec_znx_impl<R, A>(
|
||||
module: &Module<B>,
|
||||
step: usize,
|
||||
offset: usize,
|
||||
res: &mut R,
|
||||
res_col: usize,
|
||||
a: &A,
|
||||
a_col: usize,
|
||||
) where
|
||||
R: VecZnxDftToMut<B>,
|
||||
A: VecZnxToRef;
|
||||
}
|
||||
|
||||
/// # THIS TRAIT IS AN OPEN EXTENSION POINT (unsafe)
|
||||
/// * See TODO for reference code.
|
||||
/// * See TODO for corresponding public API.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use crate::{
|
||||
api::{
|
||||
ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxBigAlloc, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes,
|
||||
VecZnxDftAlloc, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigTmpA, VmpApply, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare,
|
||||
DFT, IDFTTmpA, ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxBigAlloc, VecZnxBigNormalize,
|
||||
VecZnxBigNormalizeTmpBytes, VecZnxDftAlloc, VmpApply, VmpApplyTmpBytes, VmpPMatAlloc, VmpPrepare,
|
||||
},
|
||||
layouts::{MatZnx, Module, ScratchOwned, VecZnx, VecZnxBig, VecZnxDft, VmpPMat, ZnxInfos, ZnxViewMut},
|
||||
oep::{
|
||||
ModuleNewImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, VecZnxBigAllocImpl, VecZnxBigNormalizeImpl,
|
||||
VecZnxBigNormalizeTmpBytesImpl, VecZnxDftAllocImpl, VecZnxDftFromVecZnxImpl, VecZnxDftToVecZnxBigTmpAImpl, VmpApplyImpl,
|
||||
VmpApplyTmpBytesImpl, VmpPMatAllocImpl, VmpPMatPrepareImpl,
|
||||
DFTImpl, IDFTTmpAImpl, ModuleNewImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, VecZnxBigAllocImpl,
|
||||
VecZnxBigNormalizeImpl, VecZnxBigNormalizeTmpBytesImpl, VecZnxDftAllocImpl, VmpApplyImpl, VmpApplyTmpBytesImpl,
|
||||
VmpPMatAllocImpl, VmpPMatPrepareImpl,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -23,9 +23,9 @@ where
|
||||
+ VecZnxDftAllocImpl<B>
|
||||
+ VecZnxBigAllocImpl<B>
|
||||
+ VmpPMatPrepareImpl<B>
|
||||
+ VecZnxDftFromVecZnxImpl<B>
|
||||
+ DFTImpl<B>
|
||||
+ VmpApplyImpl<B>
|
||||
+ VecZnxDftToVecZnxBigTmpAImpl<B>
|
||||
+ IDFTTmpAImpl<B>
|
||||
+ ScratchOwnedAllocImpl<B>
|
||||
+ ScratchOwnedBorrowImpl<B>
|
||||
+ VecZnxBigNormalizeImpl<B>,
|
||||
@@ -86,7 +86,7 @@ where
|
||||
|
||||
let mut a_dft: VecZnxDft<Vec<u8>, B> = module.vec_znx_dft_alloc(a_cols, a_size);
|
||||
(0..a_cols).for_each(|i| {
|
||||
module.vec_znx_dft_from_vec_znx(1, 0, &mut a_dft, i, &a, i);
|
||||
module.dft(1, 0, &mut a_dft, i, &a, i);
|
||||
});
|
||||
|
||||
module.vmp_apply(&mut c_dft, &a_dft, &vmp, scratch.borrow());
|
||||
@@ -95,7 +95,7 @@ where
|
||||
|
||||
let mut res_have: VecZnx<Vec<u8>> = VecZnx::alloc(n, res_cols, res_size);
|
||||
(0..mat_cols_out).for_each(|i| {
|
||||
module.vec_znx_dft_to_vec_znx_big_tmp_a(&mut c_big, i, &mut c_dft, i);
|
||||
module.idft_tmp_a(&mut c_big, i, &mut c_dft, i);
|
||||
module.vec_znx_big_normalize(basek, &mut res_have, i, &c_big, i, scratch.borrow());
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user