mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 21:26:41 +01:00
keyswitch tests
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
|
||||
use crate::layouts::{
|
||||
AutomorphismKeyToRef, Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{
|
||||
GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut,
|
||||
GLWESwitchingKeyPreparedToRef,
|
||||
},
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut,
|
||||
GGLWEPreparedToRef, GGLWEToRef, GLWEInfos, LWEInfos, Rank, TorusPrecision,
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct AutomorphismKeyPrepared<D: Data, B: Backend> {
|
||||
pub(crate) key: GLWESwitchingKeyPrepared<D, B>,
|
||||
pub(crate) key: GGLWEPrepared<D, B>,
|
||||
pub(crate) p: i64,
|
||||
}
|
||||
|
||||
@@ -78,7 +75,7 @@ impl<D: Data, B: Backend> GGLWEInfos for AutomorphismKeyPrepared<D, B> {
|
||||
|
||||
pub trait AutomorphismKeyPreparedAlloc<B: Backend>
|
||||
where
|
||||
Self: GLWESwitchingKeyPreparedAlloc<B>,
|
||||
Self: GGLWEPreparedAlloc<B>,
|
||||
{
|
||||
fn alloc_automorphism_key_prepared(
|
||||
&self,
|
||||
@@ -89,7 +86,7 @@ where
|
||||
dsize: Dsize,
|
||||
) -> AutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
AutomorphismKeyPrepared::<Vec<u8>, B> {
|
||||
key: self.alloc_glwe_switching_key_prepared(base2k, k, rank, rank, dnum, dsize),
|
||||
key: self.alloc_gglwe_prepared(base2k, k, rank, rank, dnum, dsize),
|
||||
p: 0,
|
||||
}
|
||||
}
|
||||
@@ -120,7 +117,7 @@ where
|
||||
dnum: Dnum,
|
||||
dsize: Dsize,
|
||||
) -> usize {
|
||||
self.bytes_of_glwe_switching_key_prepared(base2k, k, rank, rank, dnum, dsize)
|
||||
self.bytes_of_gglwe_prepared(base2k, k, rank, rank, dnum, dsize)
|
||||
}
|
||||
|
||||
fn bytes_of_automorphism_key_prepared_from_infos<A>(&self, infos: &A) -> usize
|
||||
@@ -130,7 +127,7 @@ where
|
||||
assert_eq!(
|
||||
infos.rank_in(),
|
||||
infos.rank_out(),
|
||||
"rank_in != rank_out is not supported for GGLWEAutomorphismKeyPrepared"
|
||||
"rank_in != rank_out is not supported for AutomorphismKeyPrepared"
|
||||
);
|
||||
self.bytes_of_automorphism_key_prepared(
|
||||
infos.base2k(),
|
||||
@@ -142,7 +139,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> AutomorphismKeyPreparedAlloc<B> for Module<B> where Module<B>: GLWESwitchingKeyPreparedAlloc<B> {}
|
||||
impl<B: Backend> AutomorphismKeyPreparedAlloc<B> for Module<B> where Module<B>: GGLWEPreparedAlloc<B> {}
|
||||
|
||||
impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||
@@ -178,26 +175,26 @@ impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
|
||||
pub trait PrepareAutomorphismKey<B: Backend>
|
||||
where
|
||||
Self: GLWESwitchingKeyPrepare<B>,
|
||||
Self: GGLWEPrepare<B>,
|
||||
{
|
||||
fn prepare_automorphism_key_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_glwe_switching_key_tmp_bytes(infos)
|
||||
self.prepare_gglwe_tmp_bytes(infos)
|
||||
}
|
||||
|
||||
fn prepare_automorphism_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: AutomorphismKeyPreparedToMut<B> + SetAutomorphismGaloisElement,
|
||||
O: AutomorphismKeyToRef + GetAutomorphismGaloisElement,
|
||||
R: GGLWEPreparedToMut<B> + SetAutomorphismGaloisElement,
|
||||
O: GGLWEToRef + GetAutomorphismGaloisElement,
|
||||
{
|
||||
self.prepare_glwe_switching(&mut res.to_mut().key, &other.to_ref().key, scratch);
|
||||
self.prepare_gglwe(res, other, scratch);
|
||||
res.set_p(other.p());
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> PrepareAutomorphismKey<B> for Module<B> where Module<B>: GLWESwitchingKeyPrepare<B> {}
|
||||
impl<B: Backend> PrepareAutomorphismKey<B> for Module<B> where Module<B>: GGLWEPrepare<B> {}
|
||||
|
||||
impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
pub fn prepare_tmp_bytes<M>(&self, module: &M) -> usize
|
||||
@@ -211,35 +208,21 @@ impl<B: Backend> AutomorphismKeyPrepared<Vec<u8>, B> {
|
||||
impl<D: DataMut, B: Backend> AutomorphismKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: AutomorphismKeyToRef + GetAutomorphismGaloisElement,
|
||||
O: GGLWEToRef + GetAutomorphismGaloisElement,
|
||||
M: PrepareAutomorphismKey<B>,
|
||||
{
|
||||
module.prepare_automorphism_key(self, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AutomorphismKeyPreparedToMut<B: Backend> {
|
||||
fn to_mut(&mut self) -> AutomorphismKeyPrepared<&mut [u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> AutomorphismKeyPreparedToMut<B> for AutomorphismKeyPrepared<D, B> {
|
||||
fn to_mut(&mut self) -> AutomorphismKeyPrepared<&mut [u8], B> {
|
||||
AutomorphismKeyPrepared {
|
||||
p: self.p,
|
||||
key: self.key.to_mut(),
|
||||
}
|
||||
impl<D: DataMut, B: Backend> GGLWEPreparedToMut<B> for AutomorphismKeyPrepared<D, B> {
|
||||
fn to_mut(&mut self) -> GGLWEPrepared<&mut [u8], B> {
|
||||
self.key.to_mut()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AutomorphismKeyPreparedToRef<B: Backend> {
|
||||
fn to_ref(&self) -> AutomorphismKeyPrepared<&[u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> AutomorphismKeyPreparedToRef<B> for AutomorphismKeyPrepared<D, B> {
|
||||
fn to_ref(&self) -> AutomorphismKeyPrepared<&[u8], B> {
|
||||
AutomorphismKeyPrepared {
|
||||
p: self.p,
|
||||
key: self.key.to_ref(),
|
||||
}
|
||||
impl<D: DataRef, BE: Backend> GGLWEPreparedToRef<BE> for AutomorphismKeyPrepared<D, BE> {
|
||||
fn to_ref(&self) -> GGLWEPrepared<&[u8], BE> {
|
||||
self.key.to_ref()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWESwitchingKeySetMetaData, GLWESwitchingKeyToRef,
|
||||
GLWESwtichingKeyGetMetaData, LWEInfos, Rank, TorusPrecision,
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEToRef, GLWEInfos, GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut,
|
||||
LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut, GGLWEPreparedToRef},
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct GLWESwitchingKeyPrepared<D: Data, B: Backend> {
|
||||
pub(crate) key: GGLWEPrepared<D, B>,
|
||||
pub(crate) sk_in_n: usize, // Degree of sk_in
|
||||
pub(crate) sk_out_n: usize, // Degree of sk_out
|
||||
pub(crate) input_degree: Degree, // Degree of sk_in
|
||||
pub(crate) output_degree: Degree, // Degree of sk_out
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWESwitchingKeySetMetaData for GLWESwitchingKeyPrepared<D, B> {
|
||||
fn set_sk_in_n(&mut self, sk_in_n: usize) {
|
||||
self.sk_in_n = sk_in_n
|
||||
impl<D: DataRef, BE: Backend> GLWESwitchingKeyDegrees for GLWESwitchingKeyPrepared<D, BE> {
|
||||
fn output_degree(&self) -> &Degree {
|
||||
&self.output_degree
|
||||
}
|
||||
|
||||
fn set_sk_out_n(&mut self, sk_out_n: usize) {
|
||||
self.sk_out_n = sk_out_n
|
||||
fn input_degree(&self) -> &Degree {
|
||||
&self.input_degree
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> GLWESwtichingKeyGetMetaData for GLWESwitchingKeyPrepared<D, B> {
|
||||
fn sk_in_n(&self) -> usize {
|
||||
self.sk_in_n
|
||||
impl<D: DataMut, BE: Backend> GLWESwitchingKeyDegreesMut for GLWESwitchingKeyPrepared<D, BE> {
|
||||
fn output_degree(&mut self) -> &mut Degree {
|
||||
&mut self.output_degree
|
||||
}
|
||||
|
||||
fn sk_out_n(&self) -> usize {
|
||||
self.sk_out_n
|
||||
fn input_degree(&mut self) -> &mut Degree {
|
||||
&mut self.input_degree
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +90,8 @@ where
|
||||
) -> GLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
GLWESwitchingKeyPrepared::<Vec<u8>, B> {
|
||||
key: self.alloc_gglwe_prepared(base2k, k, rank_in, rank_out, dnum, dsize),
|
||||
sk_in_n: 0,
|
||||
sk_out_n: 0,
|
||||
input_degree: Degree(0),
|
||||
output_degree: Degree(0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,12 +199,12 @@ where
|
||||
|
||||
fn prepare_glwe_switching<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GLWESwitchingKeyPreparedToMut<B> + GLWESwitchingKeySetMetaData,
|
||||
O: GLWESwitchingKeyToRef + GLWESwtichingKeyGetMetaData,
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_gglwe(&mut res.to_mut().key, &other.to_ref().key, scratch);
|
||||
res.set_sk_in_n(other.sk_in_n());
|
||||
res.set_sk_out_n(other.sk_out_n());
|
||||
self.prepare_gglwe(res, other, scratch);
|
||||
*res.input_degree() = *other.input_degree();
|
||||
*res.output_degree() = *other.output_degree();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ impl<B: Backend> GLWESwitchingKeyPrepare<B> for Module<B> where Self: GGLWEPrepa
|
||||
impl<D: DataMut, B: Backend> GLWESwitchingKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: GLWESwitchingKeyToRef + GLWESwtichingKeyGetMetaData,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
M: GLWESwitchingKeyPrepare<B>,
|
||||
{
|
||||
module.prepare_glwe_switching(self, other, scratch);
|
||||
@@ -229,30 +229,20 @@ impl<B: Backend> GLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWESwitchingKeyPreparedToMut<B: Backend> {
|
||||
fn to_mut(&mut self) -> GLWESwitchingKeyPrepared<&mut [u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWESwitchingKeyPreparedToMut<B> for GLWESwitchingKeyPrepared<D, B> {
|
||||
fn to_mut(&mut self) -> GLWESwitchingKeyPrepared<&mut [u8], B> {
|
||||
GLWESwitchingKeyPrepared {
|
||||
sk_in_n: self.sk_in_n,
|
||||
sk_out_n: self.sk_out_n,
|
||||
key: self.key.to_mut(),
|
||||
}
|
||||
impl<D: DataRef, BE: Backend> GGLWEPreparedToRef<BE> for GLWESwitchingKeyPrepared<D, BE>
|
||||
where
|
||||
GGLWEPrepared<D, BE>: GGLWEPreparedToRef<BE>,
|
||||
{
|
||||
fn to_ref(&self) -> GGLWEPrepared<&[u8], BE> {
|
||||
self.key.to_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWESwitchingKeyPreparedToRef<B: Backend> {
|
||||
fn to_ref(&self) -> GLWESwitchingKeyPrepared<&[u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> GLWESwitchingKeyPreparedToRef<B> for GLWESwitchingKeyPrepared<D, B> {
|
||||
fn to_ref(&self) -> GLWESwitchingKeyPrepared<&[u8], B> {
|
||||
GLWESwitchingKeyPrepared {
|
||||
sk_in_n: self.sk_in_n,
|
||||
sk_out_n: self.sk_out_n,
|
||||
key: self.key.to_ref(),
|
||||
}
|
||||
impl<D: DataRef, BE: Backend> GGLWEPreparedToMut<BE> for GLWESwitchingKeyPrepared<D, BE>
|
||||
where
|
||||
GGLWEPrepared<D, BE>: GGLWEPreparedToMut<BE>,
|
||||
{
|
||||
fn to_mut(&mut self) -> GGLWEPrepared<&mut [u8], BE> {
|
||||
self.key.to_mut()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision,
|
||||
prepared::{
|
||||
GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut,
|
||||
GLWESwitchingKeyPreparedToRef,
|
||||
},
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepare, GGLWEPrepared, GGLWEPreparedAlloc, GGLWEPreparedToMut,
|
||||
GGLWEPreparedToRef, GLWEInfos, LWEInfos, Rank, TensorKey, TensorKeyToRef, TorusPrecision,
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub struct TensorKeyPrepared<D: Data, B: Backend> {
|
||||
pub(crate) keys: Vec<GLWESwitchingKeyPrepared<D, B>>,
|
||||
pub(crate) keys: Vec<GGLWEPrepared<D, B>>,
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> LWEInfos for TensorKeyPrepared<D, B> {
|
||||
@@ -57,7 +54,7 @@ impl<D: Data, B: Backend> GGLWEInfos for TensorKeyPrepared<D, B> {
|
||||
|
||||
pub trait TensorKeyPreparedAlloc<B: Backend>
|
||||
where
|
||||
Self: GLWESwitchingKeyPreparedAlloc<B>,
|
||||
Self: GGLWEPreparedAlloc<B>,
|
||||
{
|
||||
fn alloc_tensor_key_prepared(
|
||||
&self,
|
||||
@@ -70,7 +67,7 @@ where
|
||||
let pairs: u32 = (((rank.as_u32() + 1) * rank.as_u32()) >> 1).max(1);
|
||||
TensorKeyPrepared {
|
||||
keys: (0..pairs)
|
||||
.map(|_| self.alloc_glwe_switching_key_prepared(base2k, k, Rank(1), rank, dnum, dsize))
|
||||
.map(|_| self.alloc_gglwe_prepared(base2k, k, Rank(1), rank, dnum, dsize))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
@@ -82,7 +79,7 @@ where
|
||||
assert_eq!(
|
||||
infos.rank_in(),
|
||||
infos.rank_out(),
|
||||
"rank_in != rank_out is not supported for GGLWETensorKeyPrepared"
|
||||
"rank_in != rank_out is not supported for TensorKeyPrepared"
|
||||
);
|
||||
self.alloc_tensor_key_prepared(
|
||||
infos.base2k(),
|
||||
@@ -95,7 +92,7 @@ where
|
||||
|
||||
fn bytes_of_tensor_key_prepared(&self, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize {
|
||||
let pairs: usize = (((rank.0 + 1) * rank.0) >> 1).max(1) as usize;
|
||||
pairs * self.bytes_of_glwe_switching_key_prepared(base2k, k, Rank(1), rank, dnum, dsize)
|
||||
pairs * self.bytes_of_gglwe_prepared(base2k, k, Rank(1), rank, dnum, dsize)
|
||||
}
|
||||
|
||||
fn bytes_of_tensor_key_prepared_from_infos<A>(&self, infos: &A) -> usize
|
||||
@@ -112,7 +109,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> TensorKeyPreparedAlloc<B> for Module<B> where Module<B>: GLWESwitchingKeyPreparedAlloc<B> {}
|
||||
impl<B: Backend> TensorKeyPreparedAlloc<B> for Module<B> where Module<B>: GGLWEPreparedAlloc<B> {}
|
||||
|
||||
impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> {
|
||||
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||
@@ -147,8 +144,8 @@ impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> {
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> TensorKeyPrepared<D, B> {
|
||||
// Returns a mutable reference to GLWESwitchingKey_{s}(s[i] * s[j])
|
||||
pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GLWESwitchingKeyPrepared<D, B> {
|
||||
// Returns a mutable reference to GGLWE_{s}(s[i] * s[j])
|
||||
pub fn at_mut(&mut self, mut i: usize, mut j: usize) -> &mut GGLWEPrepared<D, B> {
|
||||
if i > j {
|
||||
std::mem::swap(&mut i, &mut j);
|
||||
};
|
||||
@@ -158,8 +155,8 @@ impl<D: DataMut, B: Backend> TensorKeyPrepared<D, B> {
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> TensorKeyPrepared<D, B> {
|
||||
// Returns a reference to GLWESwitchingKey_{s}(s[i] * s[j])
|
||||
pub fn at(&self, mut i: usize, mut j: usize) -> &GLWESwitchingKeyPrepared<D, B> {
|
||||
// Returns a reference to GGLWE_{s}(s[i] * s[j])
|
||||
pub fn at(&self, mut i: usize, mut j: usize) -> &GGLWEPrepared<D, B> {
|
||||
if i > j {
|
||||
std::mem::swap(&mut i, &mut j);
|
||||
};
|
||||
@@ -170,13 +167,13 @@ impl<D: DataRef, B: Backend> TensorKeyPrepared<D, B> {
|
||||
|
||||
pub trait TensorKeyPrepare<B: Backend>
|
||||
where
|
||||
Self: GLWESwitchingKeyPrepare<B>,
|
||||
Self: GGLWEPrepare<B>,
|
||||
{
|
||||
fn prepare_tensor_key_tmp_bytes<A>(&self, infos: &A) -> usize
|
||||
where
|
||||
A: GGLWEInfos,
|
||||
{
|
||||
self.prepare_glwe_switching_key_tmp_bytes(infos)
|
||||
self.prepare_gglwe_tmp_bytes(infos)
|
||||
}
|
||||
|
||||
fn prepare_tensor_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
@@ -190,12 +187,12 @@ where
|
||||
assert_eq!(res.keys.len(), other.keys.len());
|
||||
|
||||
for (a, b) in res.keys.iter_mut().zip(other.keys.iter()) {
|
||||
self.prepare_glwe_switching(a, b, scratch);
|
||||
self.prepare_gglwe(a, b, scratch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: Backend> TensorKeyPrepare<B> for Module<B> where Self: GLWESwitchingKeyPrepare<B> {}
|
||||
impl<B: Backend> TensorKeyPrepare<B> for Module<B> where Self: GGLWEPrepare<B> {}
|
||||
|
||||
impl<B: Backend> TensorKeyPrepared<Vec<u8>, B> {
|
||||
pub fn prepare_tmp_bytes<A, M>(&self, module: &M, infos: &A) -> usize
|
||||
@@ -223,7 +220,7 @@ pub trait TensorKeyPreparedToMut<B: Backend> {
|
||||
|
||||
impl<D: DataMut, B: Backend> TensorKeyPreparedToMut<B> for TensorKeyPrepared<D, B>
|
||||
where
|
||||
GLWESwitchingKeyPrepared<D, B>: GLWESwitchingKeyPreparedToMut<B>,
|
||||
GGLWEPrepared<D, B>: GGLWEPreparedToMut<B>,
|
||||
{
|
||||
fn to_mut(&mut self) -> TensorKeyPrepared<&mut [u8], B> {
|
||||
TensorKeyPrepared {
|
||||
@@ -238,7 +235,7 @@ pub trait TensorKeyPreparedToRef<B: Backend> {
|
||||
|
||||
impl<D: DataRef, B: Backend> TensorKeyPreparedToRef<B> for TensorKeyPrepared<D, B>
|
||||
where
|
||||
GLWESwitchingKeyPrepared<D, B>: GLWESwitchingKeyPreparedToRef<B>,
|
||||
GGLWEPrepared<D, B>: GGLWEPreparedToRef<B>,
|
||||
{
|
||||
fn to_ref(&self) -> TensorKeyPrepared<&[u8], B> {
|
||||
TensorKeyPrepared {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, GLWEToLWESwitchingKeyToRef, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{
|
||||
GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut,
|
||||
GLWESwitchingKeyPreparedToRef,
|
||||
},
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos,
|
||||
GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
@@ -152,10 +150,10 @@ where
|
||||
|
||||
fn prepare_glwe_to_lwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: GLWEToLWESwitchingKeyPreparedToMut<B>,
|
||||
O: GLWEToLWESwitchingKeyToRef,
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_glwe_switching(&mut res.to_mut().0, &other.to_ref().0, scratch);
|
||||
self.prepare_glwe_switching(res, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,35 +172,37 @@ impl<B: Backend> GLWEToLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
impl<D: DataMut, B: Backend> GLWEToLWESwitchingKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: GLWEToLWESwitchingKeyToRef,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
M: GLWEToLWESwitchingKeyPrepare<B>,
|
||||
{
|
||||
module.prepare_glwe_to_lwe_switching_key(self, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEToLWESwitchingKeyPreparedToRef<B: Backend> {
|
||||
fn to_ref(&self) -> GLWEToLWESwitchingKeyPrepared<&[u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> GLWEToLWESwitchingKeyPreparedToRef<B> for GLWEToLWESwitchingKeyPrepared<D, B>
|
||||
impl<D: DataRef, B: Backend> GGLWEPreparedToRef<B> for GLWEToLWESwitchingKeyPrepared<D, B>
|
||||
where
|
||||
GLWESwitchingKeyPrepared<D, B>: GLWESwitchingKeyPreparedToRef<B>,
|
||||
GLWESwitchingKeyPrepared<D, B>: GGLWEPreparedToRef<B>,
|
||||
{
|
||||
fn to_ref(&self) -> GLWEToLWESwitchingKeyPrepared<&[u8], B> {
|
||||
GLWEToLWESwitchingKeyPrepared(self.0.to_ref())
|
||||
fn to_ref(&self) -> GGLWEPrepared<&[u8], B> {
|
||||
self.0.to_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GLWEToLWESwitchingKeyPreparedToMut<B: Backend> {
|
||||
fn to_mut(&mut self) -> GLWEToLWESwitchingKeyPrepared<&mut [u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWEToLWESwitchingKeyPreparedToMut<B> for GLWEToLWESwitchingKeyPrepared<D, B>
|
||||
impl<D: DataMut, B: Backend> GGLWEPreparedToMut<B> for GLWEToLWESwitchingKeyPrepared<D, B>
|
||||
where
|
||||
GLWESwitchingKeyPrepared<D, B>: GLWESwitchingKeyPreparedToMut<B>,
|
||||
GLWESwitchingKeyPrepared<D, B>: GGLWEPreparedToRef<B>,
|
||||
{
|
||||
fn to_mut(&mut self) -> GLWEToLWESwitchingKeyPrepared<&mut [u8], B> {
|
||||
GLWEToLWESwitchingKeyPrepared(self.0.to_mut())
|
||||
fn to_mut(&mut self) -> GGLWEPrepared<&mut [u8], B> {
|
||||
self.0.to_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWESwitchingKeyDegreesMut for GLWEToLWESwitchingKeyPrepared<D, B> {
|
||||
fn input_degree(&mut self) -> &mut Degree {
|
||||
&mut self.0.input_degree
|
||||
}
|
||||
|
||||
fn output_degree(&mut self) -> &mut Degree {
|
||||
&mut self.0.output_degree
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWESwitchingKeyToRef, Rank, TorusPrecision,
|
||||
prepared::{
|
||||
GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut,
|
||||
GLWESwitchingKeyPreparedToRef,
|
||||
},
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos,
|
||||
GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
@@ -160,10 +158,10 @@ where
|
||||
}
|
||||
fn prepare_lwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: LWESwitchingKeyPreparedToMut<B>,
|
||||
O: LWESwitchingKeyToRef,
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_glwe_switching(&mut res.to_mut().0, &other.to_ref().0, scratch);
|
||||
self.prepare_glwe_switching(res, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,35 +180,37 @@ impl<B: Backend> LWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
impl<D: DataMut, B: Backend> LWESwitchingKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: LWESwitchingKeyToRef,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
M: LWESwitchingKeyPrepare<B>,
|
||||
{
|
||||
module.prepare_lwe_switching_key(self, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait LWESwitchingKeyPreparedToRef<B: Backend> {
|
||||
fn to_ref(&self) -> LWESwitchingKeyPrepared<&[u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> LWESwitchingKeyPreparedToRef<B> for LWESwitchingKeyPrepared<D, B>
|
||||
impl<D: DataRef, B: Backend> GGLWEPreparedToRef<B> for LWESwitchingKeyPrepared<D, B>
|
||||
where
|
||||
GLWESwitchingKeyPrepared<D, B>: GLWESwitchingKeyPreparedToRef<B>,
|
||||
GGLWEPrepared<D, B>: GGLWEPreparedToRef<B>,
|
||||
{
|
||||
fn to_ref(&self) -> LWESwitchingKeyPrepared<&[u8], B> {
|
||||
LWESwitchingKeyPrepared(self.0.to_ref())
|
||||
fn to_ref(&self) -> GGLWEPrepared<&[u8], B> {
|
||||
self.0.to_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait LWESwitchingKeyPreparedToMut<B: Backend> {
|
||||
fn to_mut(&mut self) -> LWESwitchingKeyPrepared<&mut [u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> LWESwitchingKeyPreparedToMut<B> for LWESwitchingKeyPrepared<D, B>
|
||||
impl<D: DataMut, B: Backend> GGLWEPreparedToMut<B> for LWESwitchingKeyPrepared<D, B>
|
||||
where
|
||||
GLWESwitchingKeyPrepared<D, B>: GLWESwitchingKeyPreparedToMut<B>,
|
||||
GGLWEPrepared<D, B>: GGLWEPreparedToMut<B>,
|
||||
{
|
||||
fn to_mut(&mut self) -> LWESwitchingKeyPrepared<&mut [u8], B> {
|
||||
LWESwitchingKeyPrepared(self.0.to_mut())
|
||||
fn to_mut(&mut self) -> GGLWEPrepared<&mut [u8], B> {
|
||||
self.0.to_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWESwitchingKeyDegreesMut for LWESwitchingKeyPrepared<D, B> {
|
||||
fn input_degree(&mut self) -> &mut Degree {
|
||||
&mut self.0.input_degree
|
||||
}
|
||||
|
||||
fn output_degree(&mut self) -> &mut Degree {
|
||||
&mut self.0.output_degree
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
|
||||
use crate::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GLWEInfos, LWEInfos, LWEToGLWESwitchingKeyToRef, Rank, TorusPrecision,
|
||||
prepared::{
|
||||
GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc, GLWESwitchingKeyPreparedToMut,
|
||||
GLWESwitchingKeyPreparedToRef,
|
||||
},
|
||||
Base2K, Degree, Dnum, Dsize, GGLWEInfos, GGLWEPrepared, GGLWEPreparedToMut, GGLWEPreparedToRef, GGLWEToRef, GLWEInfos,
|
||||
GLWESwitchingKeyDegrees, GLWESwitchingKeyDegreesMut, LWEInfos, Rank, TorusPrecision,
|
||||
prepared::{GLWESwitchingKeyPrepare, GLWESwitchingKeyPrepared, GLWESwitchingKeyPreparedAlloc},
|
||||
};
|
||||
|
||||
/// A special [GLWESwitchingKey] required to for the conversion from [LWE] to [GLWE].
|
||||
@@ -159,10 +157,10 @@ where
|
||||
|
||||
fn prepare_lwe_to_glwe_switching_key<R, O>(&self, res: &mut R, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
R: LWEToGLWESwitchingKeyPreparedToMut<B>,
|
||||
O: LWEToGLWESwitchingKeyToRef,
|
||||
R: GGLWEPreparedToMut<B> + GLWESwitchingKeyDegreesMut,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
{
|
||||
self.prepare_glwe_switching(&mut res.to_mut().0, &other.to_ref().0, scratch);
|
||||
self.prepare_glwe_switching(res, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,35 +179,37 @@ impl<B: Backend> LWEToGLWESwitchingKeyPrepared<Vec<u8>, B> {
|
||||
impl<D: DataMut, B: Backend> LWEToGLWESwitchingKeyPrepared<D, B> {
|
||||
pub fn prepare<O, M>(&mut self, module: &M, other: &O, scratch: &mut Scratch<B>)
|
||||
where
|
||||
O: LWEToGLWESwitchingKeyToRef,
|
||||
O: GGLWEToRef + GLWESwitchingKeyDegrees,
|
||||
M: LWEToGLWESwitchingKeyPrepare<B>,
|
||||
{
|
||||
module.prepare_lwe_to_glwe_switching_key(self, other, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait LWEToGLWESwitchingKeyPreparedToRef<B: Backend> {
|
||||
fn to_ref(&self) -> LWEToGLWESwitchingKeyPrepared<&[u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> LWEToGLWESwitchingKeyPreparedToRef<B> for LWEToGLWESwitchingKeyPrepared<D, B>
|
||||
impl<D: DataRef, B: Backend> GGLWEPreparedToRef<B> for LWEToGLWESwitchingKeyPrepared<D, B>
|
||||
where
|
||||
GLWESwitchingKeyPrepared<D, B>: GLWESwitchingKeyPreparedToRef<B>,
|
||||
GLWESwitchingKeyPrepared<D, B>: GGLWEPreparedToRef<B>,
|
||||
{
|
||||
fn to_ref(&self) -> LWEToGLWESwitchingKeyPrepared<&[u8], B> {
|
||||
LWEToGLWESwitchingKeyPrepared(self.0.to_ref())
|
||||
fn to_ref(&self) -> GGLWEPrepared<&[u8], B> {
|
||||
self.0.to_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait LWEToGLWESwitchingKeyPreparedToMut<B: Backend> {
|
||||
fn to_mut(&mut self) -> LWEToGLWESwitchingKeyPrepared<&mut [u8], B>;
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> LWEToGLWESwitchingKeyPreparedToMut<B> for LWEToGLWESwitchingKeyPrepared<D, B>
|
||||
impl<D: DataMut, B: Backend> GGLWEPreparedToMut<B> for LWEToGLWESwitchingKeyPrepared<D, B>
|
||||
where
|
||||
GLWESwitchingKeyPrepared<D, B>: GLWESwitchingKeyPreparedToMut<B>,
|
||||
GLWESwitchingKeyPrepared<D, B>: GGLWEPreparedToMut<B>,
|
||||
{
|
||||
fn to_mut(&mut self) -> LWEToGLWESwitchingKeyPrepared<&mut [u8], B> {
|
||||
LWEToGLWESwitchingKeyPrepared(self.0.to_mut())
|
||||
fn to_mut(&mut self) -> GGLWEPrepared<&mut [u8], B> {
|
||||
self.0.to_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataMut, B: Backend> GLWESwitchingKeyDegreesMut for LWEToGLWESwitchingKeyPrepared<D, B> {
|
||||
fn input_degree(&mut self) -> &mut Degree {
|
||||
&mut self.0.input_degree
|
||||
}
|
||||
|
||||
fn output_degree(&mut self) -> &mut Degree {
|
||||
&mut self.0.output_degree
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user