Ref. + AVX code & generic tests + benches (#85)

This commit is contained in:
Jean-Philippe Bossuat
2025-09-15 16:16:11 +02:00
committed by GitHub
parent 99b9e3e10e
commit 56dbd29c59
286 changed files with 27797 additions and 7270 deletions

View File

@@ -24,8 +24,8 @@ impl<D: DataRef> fmt::Debug for GGLWEAutomorphismKeyCompressed<D> {
}
impl<D: DataMut> FillUniform for GGLWEAutomorphismKeyCompressed<D> {
fn fill_uniform(&mut self, source: &mut Source) {
self.key.fill_uniform(source);
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.key.fill_uniform(log_bound, source);
}
}

View File

@@ -28,8 +28,8 @@ impl<D: DataRef> fmt::Debug for GGLWECiphertextCompressed<D> {
}
impl<D: DataMut> FillUniform for GGLWECiphertextCompressed<D> {
fn fill_uniform(&mut self, source: &mut Source) {
self.data.fill_uniform(source);
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.data.fill_uniform(log_bound, source);
}
}

View File

@@ -25,8 +25,8 @@ impl<D: DataRef> fmt::Debug for GGLWESwitchingKeyCompressed<D> {
}
impl<D: DataMut> FillUniform for GGLWESwitchingKeyCompressed<D> {
fn fill_uniform(&mut self, source: &mut Source) {
self.key.fill_uniform(source);
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.key.fill_uniform(log_bound, source);
}
}

View File

@@ -23,10 +23,10 @@ impl<D: DataRef> fmt::Debug for GGLWETensorKeyCompressed<D> {
}
impl<D: DataMut> FillUniform for GGLWETensorKeyCompressed<D> {
fn fill_uniform(&mut self, source: &mut Source) {
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.keys
.iter_mut()
.for_each(|key: &mut GGLWESwitchingKeyCompressed<D>| key.fill_uniform(source))
.for_each(|key: &mut GGLWESwitchingKeyCompressed<D>| key.fill_uniform(log_bound, source))
}
}

View File

@@ -49,8 +49,8 @@ impl<D: DataMut> Reset for GGSWCiphertextCompressed<D> {
}
impl<D: DataMut> FillUniform for GGSWCiphertextCompressed<D> {
fn fill_uniform(&mut self, source: &mut Source) {
self.data.fill_uniform(source);
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.data.fill_uniform(log_bound, source);
}
}

View File

@@ -48,8 +48,8 @@ impl<D: DataMut> Reset for GLWECiphertextCompressed<D> {
}
impl<D: DataMut> FillUniform for GLWECiphertextCompressed<D> {
fn fill_uniform(&mut self, source: &mut Source) {
self.data.fill_uniform(source);
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.data.fill_uniform(log_bound, source);
}
}
@@ -160,7 +160,8 @@ impl<D: DataMut> GLWECiphertext<D> {
{
#[cfg(debug_assertions)]
{
assert_eq!(self.rank(), other.rank())
assert_eq!(self.rank(), other.rank());
debug_assert_eq!(self.size(), other.size());
}
let k: usize = other.k;
@@ -168,7 +169,7 @@ impl<D: DataMut> GLWECiphertext<D> {
let cols: usize = other.rank() + 1;
module.vec_znx_copy(&mut self.data, 0, &other.data, 0);
(1..cols).for_each(|i| {
module.vec_znx_fill_uniform(basek, &mut self.data, i, k, source);
module.vec_znx_fill_uniform(basek, &mut self.data, i, source);
});
self.basek = basek;

View File

@@ -2,9 +2,9 @@ use std::fmt;
use poulpy_hal::{
api::{
DFT, IDFTConsume, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal,
VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace,
VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace,
SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal,
VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftApply, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize,
VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace,
},
layouts::{Backend, Data, DataMut, DataRef, FillUniform, MatZnx, Module, ReaderFrom, Reset, WriterTo},
source::Source,
@@ -22,8 +22,8 @@ impl<D: DataRef> fmt::Debug for GLWEToLWESwitchingKeyCompressed<D> {
}
impl<D: DataMut> FillUniform for GLWEToLWESwitchingKeyCompressed<D> {
fn fill_uniform(&mut self, source: &mut Source) {
self.0.fill_uniform(source);
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.0.fill_uniform(log_bound, source);
}
}
@@ -96,9 +96,9 @@ impl GLWEToLWESwitchingKeyCompressed<Vec<u8>> {
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
+ DFT<B>
+ SvpApplyInplace<B>
+ IDFTConsume<B>
+ VecZnxDftApply<B>
+ SvpApplyDftToDftInplace<B>
+ VecZnxIdftApplyConsume<B>
+ VecZnxNormalizeTmpBytes
+ VecZnxFillUniform
+ VecZnxSubABInplace

View File

@@ -50,8 +50,8 @@ where
}
impl<D: DataMut> FillUniform for LWECiphertextCompressed<D> {
fn fill_uniform(&mut self, source: &mut Source) {
self.data.fill_uniform(source);
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.data.fill_uniform(log_bound, source);
}
}
@@ -124,15 +124,9 @@ where
Module<B>: ZnFillUniform,
{
fn decompress(&mut self, module: &Module<B>, other: &LWECiphertextCompressed<DR>) {
debug_assert_eq!(self.size(), other.size());
let mut source: Source = Source::new(other.seed);
module.zn_fill_uniform(
self.n(),
other.basek(),
&mut self.data,
0,
other.k(),
&mut source,
);
module.zn_fill_uniform(self.n(), other.basek(), &mut self.data, 0, &mut source);
(0..self.size()).for_each(|i| {
self.data.at_mut(0, i)[0] = other.data.at(0, i)[0];
});

View File

@@ -1,8 +1,8 @@
use poulpy_hal::{
api::{
DFT, IDFTConsume, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal,
VecZnxBigNormalize, VecZnxCopy, VecZnxDftAllocBytes, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace,
VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace,
SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal,
VecZnxBigNormalize, VecZnxCopy, VecZnxDftAllocBytes, VecZnxDftApply, VecZnxFillUniform, VecZnxIdftApplyConsume,
VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace,
},
layouts::{Backend, Data, DataMut, DataRef, FillUniform, MatZnx, Module, ReaderFrom, Reset, WriterTo},
source::Source,
@@ -24,8 +24,8 @@ impl<D: DataRef> fmt::Debug for LWESwitchingKeyCompressed<D> {
}
impl<D: DataMut> FillUniform for LWESwitchingKeyCompressed<D> {
fn fill_uniform(&mut self, source: &mut Source) {
self.0.fill_uniform(source);
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.0.fill_uniform(log_bound, source);
}
}
@@ -98,9 +98,9 @@ impl LWESwitchingKeyCompressed<Vec<u8>> {
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
+ DFT<B>
+ SvpApplyInplace<B>
+ IDFTConsume<B>
+ VecZnxDftApply<B>
+ SvpApplyDftToDftInplace<B>
+ VecZnxIdftApplyConsume<B>
+ VecZnxNormalizeTmpBytes
+ VecZnxFillUniform
+ VecZnxSubABInplace

View File

@@ -1,8 +1,8 @@
use poulpy_hal::{
api::{
DFT, IDFTConsume, SvpApplyInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal,
VecZnxBigNormalize, VecZnxCopy, VecZnxDftAllocBytes, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace,
VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace,
SvpApplyDftToDftInplace, SvpPPolAlloc, SvpPPolAllocBytes, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal,
VecZnxBigNormalize, VecZnxCopy, VecZnxDftAllocBytes, VecZnxDftApply, VecZnxFillUniform, VecZnxIdftApplyConsume,
VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace,
},
layouts::{Backend, Data, DataMut, DataRef, FillUniform, MatZnx, Module, ReaderFrom, Reset, WriterTo},
source::Source,
@@ -24,8 +24,8 @@ impl<D: DataRef> fmt::Debug for LWEToGLWESwitchingKeyCompressed<D> {
}
impl<D: DataMut> FillUniform for LWEToGLWESwitchingKeyCompressed<D> {
fn fill_uniform(&mut self, source: &mut Source) {
self.0.fill_uniform(source);
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
self.0.fill_uniform(log_bound, source);
}
}
@@ -98,9 +98,9 @@ impl LWEToGLWESwitchingKeyCompressed<Vec<u8>> {
where
Module<B>: VecZnxDftAllocBytes
+ VecZnxBigNormalize<B>
+ DFT<B>
+ SvpApplyInplace<B>
+ IDFTConsume<B>
+ VecZnxDftApply<B>
+ SvpApplyDftToDftInplace<B>
+ VecZnxIdftApplyConsume<B>
+ VecZnxNormalizeTmpBytes
+ VecZnxFillUniform
+ VecZnxSubABInplace