mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Support for bivariate convolution & normalization with offset (#126)
* Add bivariate-convolution * Add pair-wise convolution + tests + benches * Add take_cnv_pvec_[left/right] to Scratch & updated CHANGELOG.md * cross-base2k normalization with positive offset * clippy & fix CI doctest avx compile error * more streamlined bounds derivation for normalization * Working cross-base2k normalization with pos/neg offset * Update normalization API & tests * Add glwe tensoring test * Add relinearization + preliminary test * Fix GGLWEToGGSW key infos * Add (X,Y) convolution by const (1, Y) poly * Faster normalization test + add bench for cnv_by_const * Update changelog
This commit is contained in:
committed by
GitHub
parent
76424d0ab5
commit
4e90e08a71
@@ -3,7 +3,7 @@ use poulpy_hal::{
|
||||
source::Source,
|
||||
};
|
||||
|
||||
use crate::layouts::{Base2K, Degree, GLWEInfos, LWEInfos, Rank, SetGLWEInfos, TorusPrecision};
|
||||
use crate::layouts::{Base2K, Degree, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, LWEInfos, Rank, SetGLWEInfos, TorusPrecision};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
@@ -68,13 +68,7 @@ impl<D: DataRef> fmt::Debug for GLWETensor<D> {
|
||||
|
||||
impl<D: DataRef> fmt::Display for GLWETensor<D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"GLWETensor: base2k={} k={}: {}",
|
||||
self.base2k().0,
|
||||
self.k().0,
|
||||
self.data
|
||||
)
|
||||
write!(f, "GLWETensor: base2k={} k={}: {}", self.base2k().0, self.k().0, self.data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,9 +87,10 @@ impl GLWETensor<Vec<u8>> {
|
||||
}
|
||||
|
||||
pub fn alloc(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self {
|
||||
let pairs: usize = (((rank + 1) * rank).as_usize() >> 1).max(1);
|
||||
let cols: usize = rank.as_usize() + 1;
|
||||
let pairs: usize = (((cols + 1) * cols) >> 1).max(1);
|
||||
GLWETensor {
|
||||
data: VecZnx::alloc(n.into(), pairs + 1, k.0.div_ceil(base2k.0) as usize),
|
||||
data: VecZnx::alloc(n.into(), pairs, k.0.div_ceil(base2k.0) as usize),
|
||||
base2k,
|
||||
k,
|
||||
rank,
|
||||
@@ -110,36 +105,27 @@ impl GLWETensor<Vec<u8>> {
|
||||
}
|
||||
|
||||
pub fn bytes_of(n: Degree, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize {
|
||||
let pairs: usize = (((rank + 1) * rank).as_usize() >> 1).max(1);
|
||||
VecZnx::bytes_of(n.into(), pairs + 1, k.0.div_ceil(base2k.0) as usize)
|
||||
let cols: usize = rank.as_usize() + 1;
|
||||
let pairs: usize = (((cols + 1) * cols) >> 1).max(1);
|
||||
VecZnx::bytes_of(n.into(), pairs, k.0.div_ceil(base2k.0) as usize)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWETensorToRef {
|
||||
fn to_ref(&self) -> GLWETensor<&[u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataRef> GLWETensorToRef for GLWETensor<D> {
|
||||
fn to_ref(&self) -> GLWETensor<&[u8]> {
|
||||
GLWETensor {
|
||||
impl<D: DataRef> GLWEToRef for GLWETensor<D> {
|
||||
fn to_ref(&self) -> GLWE<&[u8]> {
|
||||
GLWE {
|
||||
k: self.k,
|
||||
base2k: self.base2k,
|
||||
data: self.data.to_ref(),
|
||||
rank: self.rank,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWETensorToMut {
|
||||
fn to_mut(&mut self) -> GLWETensor<&mut [u8]>;
|
||||
}
|
||||
|
||||
impl<D: DataMut> GLWETensorToMut for GLWETensor<D> {
|
||||
fn to_mut(&mut self) -> GLWETensor<&mut [u8]> {
|
||||
GLWETensor {
|
||||
impl<D: DataMut> GLWEToMut for GLWETensor<D> {
|
||||
fn to_mut(&mut self) -> GLWE<&mut [u8]> {
|
||||
GLWE {
|
||||
k: self.k,
|
||||
base2k: self.base2k,
|
||||
rank: self.rank,
|
||||
data: self.data.to_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user