From 008b800c015e52797273c5f85d26676190db4c4b Mon Sep 17 00:00:00 2001 From: Pro7ech Date: Wed, 15 Oct 2025 10:48:14 +0200 Subject: [PATCH] wip --- poulpy-core/src/automorphism/gglwe_atk.rs | 10 +- poulpy-core/src/automorphism/ggsw_ct.rs | 12 +- poulpy-core/src/automorphism/glwe_ct.rs | 24 +- poulpy-core/src/conversion/glwe_to_lwe.rs | 13 +- poulpy-core/src/conversion/lwe_to_glwe.rs | 11 +- poulpy-core/src/decryption/glwe_ct.rs | 6 +- .../src/encryption/compressed/gglwe_atk.rs | 3 +- .../src/encryption/compressed/gglwe_ct.rs | 3 +- .../src/encryption/compressed/gglwe_ksk.rs | 7 +- .../src/encryption/compressed/gglwe_tsk.rs | 7 +- .../src/encryption/compressed/ggsw_ct.rs | 3 +- poulpy-core/src/encryption/gglwe_atk.rs | 19 +- poulpy-core/src/encryption/gglwe_ct.rs | 10 +- poulpy-core/src/encryption/gglwe_ksk.rs | 14 +- poulpy-core/src/encryption/gglwe_tsk.rs | 18 +- poulpy-core/src/encryption/ggsw_ct.rs | 4 +- poulpy-core/src/encryption/glwe_ct.rs | 12 +- poulpy-core/src/encryption/glwe_to_lwe_ksk.rs | 17 +- poulpy-core/src/encryption/lwe_ksk.rs | 18 +- poulpy-core/src/encryption/lwe_to_glwe_ksk.rs | 15 +- poulpy-core/src/external_product/gglwe_atk.rs | 9 +- poulpy-core/src/external_product/gglwe_ksk.rs | 9 +- poulpy-core/src/external_product/ggsw_ct.rs | 215 +++++++++--------- poulpy-core/src/external_product/glwe_ct.rs | 113 +++++---- poulpy-core/src/glwe_packing.rs | 32 +-- poulpy-core/src/glwe_trace.rs | 11 +- poulpy-core/src/keyswitching/gglwe_ct.rs | 12 +- poulpy-core/src/keyswitching/ggsw_ct.rs | 15 +- poulpy-core/src/keyswitching/glwe_ct.rs | 14 +- poulpy-core/src/keyswitching/lwe_ct.rs | 17 +- .../src/layouts/compressed/gglwe_atk.rs | 22 +- .../src/layouts/compressed/gglwe_ct.rs | 24 +- .../src/layouts/compressed/gglwe_ksk.rs | 24 +- .../src/layouts/compressed/gglwe_tsk.rs | 22 +- poulpy-core/src/layouts/compressed/ggsw_ct.rs | 22 +- poulpy-core/src/layouts/compressed/glwe_ct.rs | 20 +- .../src/layouts/compressed/glwe_to_lwe_ksk.rs | 20 +- poulpy-core/src/layouts/compressed/lwe_ct.rs | 22 +- poulpy-core/src/layouts/compressed/lwe_ksk.rs | 22 +- .../src/layouts/compressed/lwe_to_glwe_ksk.rs | 20 +- poulpy-core/src/layouts/gglwe_atk.rs | 30 +-- poulpy-core/src/layouts/gglwe_ct.rs | 26 +-- poulpy-core/src/layouts/gglwe_ksk.rs | 20 +- poulpy-core/src/layouts/gglwe_tsk.rs | 23 +- poulpy-core/src/layouts/ggsw_ct.rs | 23 +- poulpy-core/src/layouts/glwe_ct.rs | 16 +- poulpy-core/src/layouts/glwe_pk.rs | 18 +- poulpy-core/src/layouts/glwe_pt.rs | 18 +- poulpy-core/src/layouts/glwe_sk.rs | 18 +- poulpy-core/src/layouts/glwe_to_lwe_ksk.rs | 18 +- poulpy-core/src/layouts/lwe_ct.rs | 18 +- poulpy-core/src/layouts/lwe_ksk.rs | 16 +- poulpy-core/src/layouts/lwe_pt.rs | 8 +- poulpy-core/src/layouts/lwe_sk.rs | 4 +- poulpy-core/src/layouts/lwe_to_glwe_ksk.rs | 16 +- poulpy-core/src/layouts/prepared/gglwe_atk.rs | 24 +- poulpy-core/src/layouts/prepared/gglwe_ct.rs | 41 ++-- poulpy-core/src/layouts/prepared/gglwe_ksk.rs | 47 ++-- poulpy-core/src/layouts/prepared/gglwe_tsk.rs | 39 ++-- poulpy-core/src/layouts/prepared/ggsw_ct.rs | 43 ++-- poulpy-core/src/layouts/prepared/glwe_pk.rs | 29 +-- poulpy-core/src/layouts/prepared/glwe_sk.rs | 31 ++- .../src/layouts/prepared/glwe_to_lwe_ksk.rs | 31 +-- poulpy-core/src/layouts/prepared/lwe_ksk.rs | 29 ++- .../src/layouts/prepared/lwe_to_glwe_ksk.rs | 23 +- poulpy-core/src/lib.rs | 2 +- poulpy-core/src/noise/gglwe_ct.rs | 6 +- poulpy-core/src/noise/ggsw_ct.rs | 14 +- poulpy-core/src/noise/glwe_ct.rs | 14 +- poulpy-core/src/scratch.rs | 143 ++++++++---- poulpy-hal/src/api/module.rs | 4 + poulpy-hal/src/api/scratch.rs | 60 ++--- .../src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs | 12 +- .../src/tfhe/bdd_arithmetic/eval.rs | 6 +- 74 files changed, 890 insertions(+), 871 deletions(-) diff --git a/poulpy-core/src/automorphism/gglwe_atk.rs b/poulpy-core/src/automorphism/gglwe_atk.rs index fc49c52..e822b63 100644 --- a/poulpy-core/src/automorphism/gglwe_atk.rs +++ b/poulpy-core/src/automorphism/gglwe_atk.rs @@ -1,8 +1,8 @@ use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, - VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, - VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, + ScratchAvailable, VecZnxAutomorphism, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, VecZnxBigNormalize, + VecZnxBigNormalizeTmpBytes, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, + VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxZero}, }; @@ -61,7 +61,7 @@ impl AutomorphismKey { + VecZnxAutomorphismInplace + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -149,7 +149,7 @@ impl AutomorphismKey { + VecZnxAutomorphismInplace + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/automorphism/ggsw_ct.rs b/poulpy-core/src/automorphism/ggsw_ct.rs index 41acde9..e99b3d5 100644 --- a/poulpy-core/src/automorphism/ggsw_ct.rs +++ b/poulpy-core/src/automorphism/ggsw_ct.rs @@ -1,9 +1,9 @@ use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, - VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftAddInplace, VecZnxDftApply, VecZnxDftBytesOf, - VecZnxDftCopy, VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, - VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, + ScratchAvailable, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, VecZnxBigBytesOf, VecZnxBigNormalize, + VecZnxBigNormalizeTmpBytes, VecZnxDftAddInplace, VecZnxDftApply, VecZnxDftBytesOf, VecZnxDftCopy, VecZnxIdftApplyConsume, + VecZnxIdftApplyTmpA, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, + VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -83,7 +83,7 @@ impl GGSW { + VecZnxDftAddInplace + VecZnxIdftApplyTmpA + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnxBig + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -151,7 +151,7 @@ impl GGSW { + VecZnxDftAddInplace + VecZnxIdftApplyTmpA + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnxBig + TakeVecZnx, + Scratch: ScratchAvailable, { // Keyswitch the j-th row of the col 0 (0..self.dnum().into()).for_each(|row_i| { diff --git a/poulpy-core/src/automorphism/glwe_ct.rs b/poulpy-core/src/automorphism/glwe_ct.rs index 8cdaa91..5d30917 100644 --- a/poulpy-core/src/automorphism/glwe_ct.rs +++ b/poulpy-core/src/automorphism/glwe_ct.rs @@ -1,9 +1,9 @@ use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, - VecZnxBigAutomorphismInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallInplace, - VecZnxBigSubSmallNegateInplace, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, - VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, + ScratchAvailable, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, VecZnxBigAutomorphismInplace, VecZnxBigNormalize, + VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallInplace, VecZnxBigSubSmallNegateInplace, VecZnxDftApply, VecZnxDftBytesOf, + VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, + VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnxBig}, }; @@ -56,7 +56,7 @@ impl GLWE { + VecZnxAutomorphismInplace + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { self.keyswitch(module, lhs, &rhs.key, scratch); (0..(self.rank() + 1).into()).for_each(|i| { @@ -82,7 +82,7 @@ impl GLWE { + VecZnxAutomorphismInplace + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { self.keyswitch_inplace(module, &rhs.key, scratch); (0..(self.rank() + 1).into()).for_each(|i| { @@ -109,7 +109,7 @@ impl GLWE { + VecZnxBigAutomorphismInplace + VecZnxNormalizeTmpBytes + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -150,7 +150,7 @@ impl GLWE { + VecZnxBigAutomorphismInplace + VecZnxNormalizeTmpBytes + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -193,7 +193,7 @@ impl GLWE { + VecZnxBigSubSmallInplace + VecZnxNormalizeTmpBytes + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -235,7 +235,7 @@ impl GLWE { + VecZnxBigSubSmallInplace + VecZnxNormalizeTmpBytes + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -278,7 +278,7 @@ impl GLWE { + VecZnxBigSubSmallNegateInplace + VecZnxNormalizeTmpBytes + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -320,7 +320,7 @@ impl GLWE { + VecZnxBigSubSmallNegateInplace + VecZnxNormalizeTmpBytes + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/conversion/glwe_to_lwe.rs b/poulpy-core/src/conversion/glwe_to_lwe.rs index ef18123..c023a43 100644 --- a/poulpy-core/src/conversion/glwe_to_lwe.rs +++ b/poulpy-core/src/conversion/glwe_to_lwe.rs @@ -1,16 +1,13 @@ use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, - VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, - VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, + VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftApply, VecZnxDftBytesOf, + VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, + VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxView, ZnxViewMut, ZnxZero}, }; -use crate::{ - TakeGLWE, - layouts::{GGLWEInfos, GLWE, GLWEInfos, GLWELayout, LWE, LWEInfos, Rank, prepared::GLWEToLWESwitchingKeyPrepared}, -}; +use crate::layouts::{GGLWEInfos, GLWE, GLWEInfos, GLWELayout, LWE, LWEInfos, Rank, prepared::GLWEToLWESwitchingKeyPrepared}; impl LWE> { pub fn from_glwe_scratch_space( @@ -80,7 +77,7 @@ impl LWE { + VecZnxBigNormalize + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeGLWE + TakeVecZnx, + Scratch:, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/conversion/lwe_to_glwe.rs b/poulpy-core/src/conversion/lwe_to_glwe.rs index de40d8f..e3ba833 100644 --- a/poulpy-core/src/conversion/lwe_to_glwe.rs +++ b/poulpy-core/src/conversion/lwe_to_glwe.rs @@ -1,16 +1,13 @@ use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, - VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, + ScratchAvailable, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftApply, + VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnx, ZnxView, ZnxViewMut, ZnxZero}, }; -use crate::{ - TakeGLWE, - layouts::{GGLWEInfos, GLWE, GLWEInfos, GLWELayout, LWE, LWEInfos, prepared::LWEToGLWESwitchingKeyPrepared}, -}; +use crate::layouts::{GGLWEInfos, GLWE, GLWEInfos, GLWELayout, LWE, LWEInfos, prepared::LWEToGLWESwitchingKeyPrepared}; impl GLWE> { pub fn from_lwe_scratch_space( @@ -62,7 +59,7 @@ impl GLWE { + VecZnxBigNormalize + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeGLWE + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/decryption/glwe_ct.rs b/poulpy-core/src/decryption/glwe_ct.rs index 89c6591..fdc040a 100644 --- a/poulpy-core/src/decryption/glwe_ct.rs +++ b/poulpy-core/src/decryption/glwe_ct.rs @@ -1,7 +1,7 @@ use poulpy_hal::{ api::{ - SvpApplyDftToDftInplace, TakeVecZnxBig, TakeVecZnxDft, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigNormalize, - VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalizeTmpBytes, + SvpApplyDftToDftInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxDftApply, + VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalizeTmpBytes, }, layouts::{Backend, DataMut, DataRef, DataViewMut, Module, Scratch}, }; @@ -33,7 +33,7 @@ impl GLWE { + VecZnxBigAddInplace + VecZnxBigAddSmallInplace + VecZnxBigNormalize, - Scratch: TakeVecZnxDft + TakeVecZnxBig, + Scratch:, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/encryption/compressed/gglwe_atk.rs b/poulpy-core/src/encryption/compressed/gglwe_atk.rs index 9091e74..17cd17f 100644 --- a/poulpy-core/src/encryption/compressed/gglwe_atk.rs +++ b/poulpy-core/src/encryption/compressed/gglwe_atk.rs @@ -5,7 +5,6 @@ use poulpy_hal::{ }; use crate::{ - TakeGLWESecret, encryption::compressed::gglwe_ksk::GGLWEKeyCompressedEncryptSk, layouts::{ GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, @@ -41,7 +40,7 @@ pub trait GGLWEAutomorphismKeyCompressedEncryptSk { impl GGLWEAutomorphismKeyCompressedEncryptSk for Module where Module: GGLWEKeyCompressedEncryptSk + VecZnxNormalizeTmpBytes + VecZnxDftBytesOf + SvpPPolBytesOf + VecZnxAutomorphism, - Scratch: TakeGLWESecret + ScratchAvailable, + Scratch: ScratchAvailable, { fn gglwe_automorphism_key_compressed_encrypt_sk( &self, diff --git a/poulpy-core/src/encryption/compressed/gglwe_ct.rs b/poulpy-core/src/encryption/compressed/gglwe_ct.rs index bd0f3b3..7757e95 100644 --- a/poulpy-core/src/encryption/compressed/gglwe_ct.rs +++ b/poulpy-core/src/encryption/compressed/gglwe_ct.rs @@ -8,7 +8,6 @@ use poulpy_hal::{ }; use crate::{ - TakeGLWEPlaintext, encryption::{SIGMA, glwe_ct::GLWEEncryptSkInternal}, layouts::{ GGLWE, GGLWEInfos, LWEInfos, @@ -67,7 +66,7 @@ where + VecZnxDftBytesOf + VecZnxAddScalarInplace + ZnNormalizeInplace, - Scratch: TakeGLWEPlaintext + ScratchAvailable, + Scratch: ScratchAvailable, { fn gglwe_compressed_encrypt_sk( &self, diff --git a/poulpy-core/src/encryption/compressed/gglwe_ksk.rs b/poulpy-core/src/encryption/compressed/gglwe_ksk.rs index 800a37e..2c0266a 100644 --- a/poulpy-core/src/encryption/compressed/gglwe_ksk.rs +++ b/poulpy-core/src/encryption/compressed/gglwe_ksk.rs @@ -1,13 +1,10 @@ use poulpy_hal::{ - api::{ - ScratchAvailable, SvpPPolBytesOf, SvpPrepare, TakeScalarZnx, VecZnxDftBytesOf, VecZnxNormalizeTmpBytes, VecZnxSwitchRing, - }, + api::{ScratchAvailable, SvpPPolBytesOf, SvpPrepare, VecZnxDftBytesOf, VecZnxNormalizeTmpBytes, VecZnxSwitchRing}, layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch}, source::Source, }; use crate::{ - TakeGLWESecretPrepared, encryption::compressed::gglwe_ct::GGLWECompressedEncryptSk, layouts::{ Degree, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, @@ -68,7 +65,7 @@ where + VecZnxDftBytesOf + VecZnxSwitchRing + SvpPrepare, - Scratch: ScratchAvailable + TakeScalarZnx + TakeGLWESecretPrepared, + Scratch: ScratchAvailable, { fn gglwe_key_compressed_encrypt_sk( &self, diff --git a/poulpy-core/src/encryption/compressed/gglwe_tsk.rs b/poulpy-core/src/encryption/compressed/gglwe_tsk.rs index 0c88f67..6115fdd 100644 --- a/poulpy-core/src/encryption/compressed/gglwe_tsk.rs +++ b/poulpy-core/src/encryption/compressed/gglwe_tsk.rs @@ -1,14 +1,13 @@ use poulpy_hal::{ api::{ - SvpApplyDftToDft, SvpPPolBytesOf, SvpPrepare, TakeVecZnxBig, TakeVecZnxDft, VecZnxBigBytesOf, VecZnxBigNormalize, - VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyTmpA, VecZnxNormalizeTmpBytes, + SvpApplyDftToDft, SvpPPolBytesOf, SvpPrepare, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, + VecZnxIdftApplyTmpA, VecZnxNormalizeTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, source::Source, }; use crate::{ - TakeGLWESecret, TakeGLWESecretPrepared, encryption::compressed::gglwe_ksk::GGLWEKeyCompressedEncryptSk, layouts::{ GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, LWEInfos, Rank, TensorKey, @@ -47,7 +46,7 @@ where + VecZnxIdftApplyTmpA + VecZnxBigNormalize + SvpPrepare, - Scratch: TakeGLWESecretPrepared + TakeVecZnxDft + TakeVecZnxBig + TakeGLWESecret, + Scratch:, { fn gglwe_tensor_key_encrypt_sk( &self, diff --git a/poulpy-core/src/encryption/compressed/ggsw_ct.rs b/poulpy-core/src/encryption/compressed/ggsw_ct.rs index 31efd53..8a8949b 100644 --- a/poulpy-core/src/encryption/compressed/ggsw_ct.rs +++ b/poulpy-core/src/encryption/compressed/ggsw_ct.rs @@ -5,7 +5,6 @@ use poulpy_hal::{ }; use crate::{ - TakeGLWEPlaintext, encryption::{SIGMA, glwe_ct::GLWEEncryptSkInternal}, layouts::{ GGSW, GGSWInfos, GLWEInfos, LWEInfos, @@ -42,7 +41,7 @@ pub trait GGSWCompressedEncryptSk { impl GGSWCompressedEncryptSk for Module where Module: GLWEEncryptSkInternal + VecZnxAddScalarInplace + VecZnxNormalizeInplace, - Scratch: TakeGLWEPlaintext, + Scratch:, { fn ggsw_compressed_encrypt_sk( &self, diff --git a/poulpy-core/src/encryption/gglwe_atk.rs b/poulpy-core/src/encryption/gglwe_atk.rs index 2fa90d4..8e0ecb7 100644 --- a/poulpy-core/src/encryption/gglwe_atk.rs +++ b/poulpy-core/src/encryption/gglwe_atk.rs @@ -1,19 +1,16 @@ use poulpy_hal::{ api::{ - ScratchAvailable, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, - VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigNormalize, VecZnxDftApply, - VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, - VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing, + ScratchAvailable, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, + VecZnxAddScalarInplace, VecZnxAutomorphism, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform, + VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, + VecZnxSwitchRing, }, layouts::{Backend, DataMut, Module, Scratch}, source::Source, }; -use crate::{ - TakeGLWESecret, TakeGLWESecretPrepared, - layouts::{ - AutomorphismKey, AutomorphismKeyToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GLWESwitchingKey, LWEInfos, - }, +use crate::layouts::{ + AutomorphismKey, AutomorphismKeyToMut, GGLWEInfos, GLWEInfos, GLWESecret, GLWESecretToRef, GLWESwitchingKey, LWEInfos, }; impl AutomorphismKey> { @@ -27,7 +24,7 @@ impl AutomorphismKey> { infos.rank_out(), "rank_in != rank_out is not supported for GGLWEAutomorphismKey" ); - GLWESwitchingKey::encrypt_sk_scratch_space(module, infos) + GLWESecret::bytes_of(&infos.glwe_layout()) + GLWESwitchingKey::encrypt_sk_scratch_space(module, infos) + GLWESecret::bytes_of_from_infos(module, &infos.glwe_layout()) } pub fn encrypt_pk_scratch_space(module: &Module, _infos: &A) -> usize @@ -97,7 +94,7 @@ where + VecZnxSwitchRing + SvpPPolBytesOf + VecZnxAutomorphism, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, + Scratch: ScratchAvailable, { fn gglwe_automorphism_key_encrypt_sk( &self, diff --git a/poulpy-core/src/encryption/gglwe_ct.rs b/poulpy-core/src/encryption/gglwe_ct.rs index a4bff60..d99ca5f 100644 --- a/poulpy-core/src/encryption/gglwe_ct.rs +++ b/poulpy-core/src/encryption/gglwe_ct.rs @@ -1,14 +1,10 @@ use poulpy_hal::{ - api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxAddScalarInplace, VecZnxDftBytesOf, VecZnxNormalizeInplace, - VecZnxNormalizeTmpBytes, - }, + api::{ScratchAvailable, VecZnxAddScalarInplace, VecZnxDftBytesOf, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes}, layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, ScalarZnxToRef, Scratch, ZnxZero}, source::Source, }; use crate::{ - TakeGLWEPlaintext, encryption::glwe_ct::GLWEEncryptSk, layouts::{ GGLWE, GGLWEInfos, GGLWEToMut, GLWE, GLWEPlaintext, LWEInfos, @@ -23,7 +19,7 @@ impl GGLWE> { Module: VecZnxNormalizeTmpBytes + VecZnxDftBytesOf + VecZnxNormalizeTmpBytes, { GLWE::encrypt_sk_scratch_space(module, &infos.glwe_layout()) - + (GLWEPlaintext::bytes_of(&infos.glwe_layout()) | module.vec_znx_normalize_tmp_bytes()) + + (GLWEPlaintext::bytes_of_from_infos(module, &infos.glwe_layout()) | module.vec_znx_normalize_tmp_bytes()) } pub fn encrypt_pk_scratch_space(_module: &Module, _infos: &A) -> usize @@ -52,7 +48,7 @@ pub trait GGLWEEncryptSk { impl GGLWEEncryptSk for Module where Module: GLWEEncryptSk + VecZnxNormalizeTmpBytes + VecZnxDftBytesOf + VecZnxAddScalarInplace + VecZnxNormalizeInplace, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { fn gglwe_encrypt_sk( &self, diff --git a/poulpy-core/src/encryption/gglwe_ksk.rs b/poulpy-core/src/encryption/gglwe_ksk.rs index 64d9e9e..1210aa7 100644 --- a/poulpy-core/src/encryption/gglwe_ksk.rs +++ b/poulpy-core/src/encryption/gglwe_ksk.rs @@ -1,17 +1,15 @@ use poulpy_hal::{ api::{ - ScratchAvailable, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, - VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, - VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, - VecZnxSubInplace, VecZnxSwitchRing, + ScratchAvailable, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, + VecZnxAddScalarInplace, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, + VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing, }, layouts::{Backend, DataMut, DataRef, Module, ScalarZnx, Scratch}, source::Source, }; -use crate::{ - TakeGLWESecretPrepared, - layouts::{Degree, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, prepared::GLWESecretPrepared}, +use crate::layouts::{ + Degree, GGLWE, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, prepared::GLWESecretPrepared, }; impl GLWESwitchingKey> { @@ -61,7 +59,7 @@ impl GLWESwitchingKey { + SvpPrepare + VecZnxSwitchRing + SvpPPolBytesOf, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/encryption/gglwe_tsk.rs b/poulpy-core/src/encryption/gglwe_tsk.rs index c2762a0..125cdf5 100644 --- a/poulpy-core/src/encryption/gglwe_tsk.rs +++ b/poulpy-core/src/encryption/gglwe_tsk.rs @@ -1,19 +1,16 @@ use poulpy_hal::{ api::{ - ScratchAvailable, SvpApplyDftToDft, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, TakeScalarZnx, TakeVecZnx, - TakeVecZnxBig, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxBigBytesOf, - VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, - VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing, + SvpApplyDftToDft, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, + VecZnxAddScalarInplace, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform, + VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, + VecZnxSubInplace, VecZnxSwitchRing, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, source::Source, }; -use crate::{ - TakeGLWESecret, TakeGLWESecretPrepared, - layouts::{ - Degree, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, Rank, TensorKey, prepared::GLWESecretPrepared, - }, +use crate::layouts::{ + Degree, GGLWEInfos, GLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, Rank, TensorKey, prepared::GLWESecretPrepared, }; impl TensorKey> { @@ -59,8 +56,7 @@ impl TensorKey { + SvpPrepare + VecZnxSwitchRing + SvpPPolBytesOf, - Scratch: - TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared + TakeVecZnxBig, + Scratch:, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/encryption/ggsw_ct.rs b/poulpy-core/src/encryption/ggsw_ct.rs index 6def5d3..23443a0 100644 --- a/poulpy-core/src/encryption/ggsw_ct.rs +++ b/poulpy-core/src/encryption/ggsw_ct.rs @@ -5,7 +5,7 @@ use poulpy_hal::{ }; use crate::{ - SIGMA, TakeGLWEPlaintext, + SIGMA, encryption::glwe_ct::GLWEEncryptSkInternal, layouts::{ GGSW, GGSWInfos, GGSWToMut, GLWE, GLWEInfos, LWEInfos, @@ -45,7 +45,7 @@ pub trait GGSWEncryptSk { impl GGSWEncryptSk for Module where Module: GLWEEncryptSkInternal + VecZnxAddScalarInplace + VecZnxNormalizeInplace, - Scratch: TakeGLWEPlaintext, + Scratch:, { fn ggsw_encrypt_sk( &self, diff --git a/poulpy-core/src/encryption/glwe_ct.rs b/poulpy-core/src/encryption/glwe_ct.rs index afd0881..c5ed129 100644 --- a/poulpy-core/src/encryption/glwe_ct.rs +++ b/poulpy-core/src/encryption/glwe_ct.rs @@ -1,9 +1,9 @@ use poulpy_hal::{ api::{ - ScratchAvailable, SvpApplyDftToDft, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, TakeScalarZnx, TakeSvpPPol, - TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxBigAddNormal, VecZnxBigAddSmallInplace, - VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, - VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, + ScratchAvailable, SvpApplyDftToDft, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, VecZnxAddInplace, + VecZnxAddNormal, VecZnxBigAddNormal, VecZnxBigAddSmallInplace, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, + VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, + VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, }, layouts::{Backend, DataMut, Module, ScalarZnx, Scratch, VecZnx, VecZnxBig, VecZnxToMut, ZnxInfos, ZnxZero}, source::Source, @@ -331,7 +331,7 @@ where + VecZnxBigAddNormal + VecZnxBigAddSmallInplace + VecZnxBigNormalize, - Scratch: TakeSvpPPol + TakeScalarZnx + TakeVecZnxDft, + Scratch:, { fn glwe_encrypt_pk_internal( &self, @@ -453,7 +453,7 @@ where + VecZnxAddNormal + VecZnxNormalize + VecZnxSub, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { fn glwe_encrypt_sk_internal( &self, diff --git a/poulpy-core/src/encryption/glwe_to_lwe_ksk.rs b/poulpy-core/src/encryption/glwe_to_lwe_ksk.rs index 585bb12..6658480 100644 --- a/poulpy-core/src/encryption/glwe_to_lwe_ksk.rs +++ b/poulpy-core/src/encryption/glwe_to_lwe_ksk.rs @@ -1,19 +1,16 @@ use poulpy_hal::{ api::{ - ScratchAvailable, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, - VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigNormalize, VecZnxDftApply, - VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, - VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing, + ScratchAvailable, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, + VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, + VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, + VecZnxSubInplace, VecZnxSwitchRing, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxView, ZnxViewMut, ZnxZero}, source::Source, }; -use crate::{ - TakeGLWESecret, TakeGLWESecretPrepared, - layouts::{ - GGLWEInfos, GLWESecret, GLWESwitchingKey, GLWEToLWESwitchingKey, LWEInfos, LWESecret, Rank, prepared::GLWESecretPrepared, - }, +use crate::layouts::{ + GGLWEInfos, GLWESecret, GLWESwitchingKey, GLWEToLWESwitchingKey, LWEInfos, LWESecret, Rank, prepared::GLWESecretPrepared, }; impl GLWEToLWESwitchingKey> { @@ -58,7 +55,7 @@ impl GLWEToLWESwitchingKey { + SvpPrepare + VecZnxSwitchRing + SvpPPolBytesOf, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/encryption/lwe_ksk.rs b/poulpy-core/src/encryption/lwe_ksk.rs index 28eab5f..04b52aa 100644 --- a/poulpy-core/src/encryption/lwe_ksk.rs +++ b/poulpy-core/src/encryption/lwe_ksk.rs @@ -1,20 +1,16 @@ use poulpy_hal::{ api::{ - ScratchAvailable, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, - VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigNormalize, VecZnxDftApply, - VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, - VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing, + SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, + VecZnxAutomorphismInplace, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxFillUniform, + VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, + VecZnxSwitchRing, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxView, ZnxViewMut}, source::Source, }; -use crate::{ - TakeGLWESecret, TakeGLWESecretPrepared, - layouts::{ - Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWESwitchingKey, Rank, - prepared::GLWESecretPrepared, - }, +use crate::layouts::{ + Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWESwitchingKey, Rank, prepared::GLWESecretPrepared, }; impl LWESwitchingKey> { @@ -75,7 +71,7 @@ impl LWESwitchingKey { + SvpPrepare + VecZnxSwitchRing + SvpPPolBytesOf, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, + Scratch:, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/encryption/lwe_to_glwe_ksk.rs b/poulpy-core/src/encryption/lwe_to_glwe_ksk.rs index 0f8ea56..b50a2db 100644 --- a/poulpy-core/src/encryption/lwe_to_glwe_ksk.rs +++ b/poulpy-core/src/encryption/lwe_to_glwe_ksk.rs @@ -1,18 +1,15 @@ use poulpy_hal::{ api::{ - ScratchAvailable, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, TakeScalarZnx, TakeVecZnx, TakeVecZnxDft, - VecZnxAddInplace, VecZnxAddNormal, VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigNormalize, VecZnxDftApply, - VecZnxDftBytesOf, VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, - VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing, + ScratchAvailable, SvpApplyDftToDftInplace, SvpPPolBytesOf, SvpPrepare, VecZnxAddInplace, VecZnxAddNormal, + VecZnxAddScalarInplace, VecZnxAutomorphismInplace, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, + VecZnxFillUniform, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, + VecZnxSubInplace, VecZnxSwitchRing, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxView, ZnxViewMut}, source::Source, }; -use crate::{ - TakeGLWESecret, TakeGLWESecretPrepared, - layouts::{Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWEToGLWESwitchingKey, Rank}, -}; +use crate::layouts::{Degree, GGLWEInfos, GLWESecret, GLWESwitchingKey, LWEInfos, LWESecret, LWEToGLWESwitchingKey, Rank}; impl LWEToGLWESwitchingKey> { pub fn encrypt_sk_scratch_space(module: &Module, infos: &A) -> usize @@ -61,7 +58,7 @@ impl LWEToGLWESwitchingKey { + SvpPrepare + VecZnxSwitchRing + SvpPPolBytesOf, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeScalarZnx + TakeGLWESecretPrepared, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/external_product/gglwe_atk.rs b/poulpy-core/src/external_product/gglwe_atk.rs index 742af02..0eba897 100644 --- a/poulpy-core/src/external_product/gglwe_atk.rs +++ b/poulpy-core/src/external_product/gglwe_atk.rs @@ -1,8 +1,7 @@ use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, - VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, - VmpApplyDftToDftTmpBytes, + ScratchAvailable, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, + VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; @@ -56,7 +55,7 @@ impl AutomorphismKey { + VecZnxIdftApplyConsume + VecZnxBigNormalize + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { self.key.external_product(module, &lhs.key, rhs, scratch); } @@ -76,7 +75,7 @@ impl AutomorphismKey { + VecZnxIdftApplyConsume + VecZnxBigNormalize + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { self.key.external_product_inplace(module, rhs, scratch); } diff --git a/poulpy-core/src/external_product/gglwe_ksk.rs b/poulpy-core/src/external_product/gglwe_ksk.rs index 5877d40..c9b7299 100644 --- a/poulpy-core/src/external_product/gglwe_ksk.rs +++ b/poulpy-core/src/external_product/gglwe_ksk.rs @@ -1,8 +1,7 @@ use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, - VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, - VmpApplyDftToDftTmpBytes, + ScratchAvailable, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, + VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxZero}, }; @@ -61,7 +60,7 @@ impl GLWESwitchingKey { + VecZnxIdftApplyConsume + VecZnxBigNormalize + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -119,7 +118,7 @@ impl GLWESwitchingKey { + VecZnxIdftApplyConsume + VecZnxBigNormalize + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/external_product/ggsw_ct.rs b/poulpy-core/src/external_product/ggsw_ct.rs index 6535076..5257a49 100644 --- a/poulpy-core/src/external_product/ggsw_ct.rs +++ b/poulpy-core/src/external_product/ggsw_ct.rs @@ -1,47 +1,116 @@ use poulpy_hal::{ - api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, - VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, - VmpApplyDftToDftTmpBytes, - }, + api::ScratchAvailable, layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxZero}, }; -use crate::layouts::{GGSW, GGSWInfos, GLWE, GLWEInfos, prepared::GGSWPrepared}; +use crate::{ + GLWEExternalProduct, ScratchTakeCore, + layouts::{ + GGSW, GGSWInfos, GGSWToMut, GGSWToRef, GLWEInfos, LWEInfos, + prepared::{GGSWPrepared, GGSWPreparedToRef}, + }, +}; -impl GGSW> { - #[allow(clippy::too_many_arguments)] - pub fn external_product_scratch_space( - module: &Module, - out_infos: &OUT, - in_infos: &IN, - ggsw_infos: &GGSW, - ) -> usize +pub trait GGSWExternalProduct +where + Self: GLWEExternalProduct, +{ + fn ggsw_external_product_tmp_bytes(&self, res_infos: &R, a_infos: &A, b_infos: &B) -> usize where - OUT: GGSWInfos, - IN: GGSWInfos, - GGSW: GGSWInfos, - Module: VecZnxDftBytesOf + VmpApplyDftToDftTmpBytes + VecZnxNormalizeTmpBytes, + R: GGSWInfos, + A: GGSWInfos, + B: GGSWInfos, { - GLWE::external_product_scratch_space( - module, - &out_infos.glwe_layout(), - &in_infos.glwe_layout(), - ggsw_infos, - ) + self.glwe_external_product_scratch_space(res_infos, a_infos, b_infos) } - pub fn external_product_inplace_scratch_space( - module: &Module, - out_infos: &OUT, - ggsw_infos: &GGSW, + fn ggsw_external_product(&self, res: &mut R, a: &A, b: &B, scratch: &mut Scratch) + where + R: GGSWToMut, + A: GGSWToRef, + B: GGSWPreparedToRef, + Scratch: ScratchTakeCore, + { + let res: &mut GGSW<&mut [u8]> = &mut res.to_mut(); + let a: &GGSW<&[u8]> = &a.to_ref(); + let b: &GGSWPrepared<&[u8], BE> = &b.to_ref(); + + assert_eq!( + res.rank(), + a.rank(), + "res rank: {} != a rank: {}", + res.rank(), + a.rank() + ); + assert_eq!( + res.rank(), + b.rank(), + "res rank: {} != b rank: {}", + res.rank(), + b.rank() + ); + + assert!(scratch.available() >= self.ggsw_external_product_tmp_bytes(res, a, b)); + + let min_dnum: usize = res.dnum().min(a.dnum()).into(); + + for row in 0..min_dnum { + for col in 0..(res.rank() + 1).into() { + self.glwe_external_product(&mut res.at_mut(row, col), &a.at(row, col), b, scratch); + } + } + + for row in min_dnum..res.dnum().into() { + for col in 0..(res.rank() + 1).into() { + res.at_mut(row, col).data.zero(); + } + } + } + + fn ggsw_external_product_inplace(&self, res: &mut R, a: &A, scratch: &mut Scratch) + where + R: GGSWToMut, + A: GGSWPreparedToRef, + Scratch: ScratchTakeCore, + { + let res: &mut GGSW<&mut [u8]> = &mut res.to_mut(); + let a: &GGSWPrepared<&[u8], BE> = &a.to_ref(); + + assert_eq!(res.n(), self.n() as u32); + assert_eq!(a.n(), self.n() as u32); + assert_eq!( + res.rank(), + a.rank(), + "res rank: {} != a rank: {}", + res.rank(), + a.rank() + ); + + for row in 0..res.dnum().into() { + for col in 0..(res.rank() + 1).into() { + self.glwe_external_product_inplace(&mut res.at_mut(row, col), a, scratch); + } + } + } +} + +impl GGSWExternalProduct for Module where Self: GLWEExternalProduct {} + +impl GGSW> { + pub fn external_product_tmp_bytes( + &self, + module: &M, + res_infos: &R, + a_infos: &A, + b_infos: &B, ) -> usize where - OUT: GGSWInfos, - GGSW: GGSWInfos, - Module: VecZnxDftBytesOf + VmpApplyDftToDftTmpBytes + VecZnxNormalizeTmpBytes, + R: GGSWInfos, + A: GGSWInfos, + B: GGSWInfos, + M: GGSWExternalProduct, { - GLWE::external_product_inplace_scratch_space(module, &out_infos.glwe_layout(), ggsw_infos) + module.ggsw_external_product_tmp_bytes(res_infos, a_infos, b_infos) } } @@ -52,54 +121,7 @@ impl GGSW { lhs: &GGSW, rhs: &GGSWPrepared, scratch: &mut Scratch, - ) where - Module: VecZnxDftBytesOf - + VmpApplyDftToDftTmpBytes - + VecZnxNormalizeTmpBytes - + VecZnxDftApply - + VmpApplyDftToDft - + VmpApplyDftToDftAdd - + VecZnxIdftApplyConsume - + VecZnxBigNormalize - + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, - { - #[cfg(debug_assertions)] - { - use crate::layouts::LWEInfos; - - assert_eq!(lhs.n(), self.n()); - assert_eq!(rhs.n(), self.n()); - - assert_eq!( - self.rank(), - lhs.rank(), - "ggsw_out rank: {} != ggsw_in rank: {}", - self.rank(), - lhs.rank() - ); - assert_eq!( - self.rank(), - rhs.rank(), - "ggsw_in rank: {} != ggsw_apply rank: {}", - self.rank(), - rhs.rank() - ); - - assert!(scratch.available() >= GGSW::external_product_scratch_space(module, self, lhs, rhs)) - } - - let min_dnum: usize = self.dnum().min(lhs.dnum()).into(); - - (0..(self.rank() + 1).into()).for_each(|col_i| { - (0..min_dnum).for_each(|row_j| { - self.at_mut(row_j, col_i) - .external_product(module, &lhs.at(row_j, col_i), rhs, scratch); - }); - (min_dnum..self.dnum().into()).for_each(|row_i| { - self.at_mut(row_i, col_i).data.zero(); - }); - }); + ) { } pub fn external_product_inplace( @@ -107,37 +129,6 @@ impl GGSW { module: &Module, rhs: &GGSWPrepared, scratch: &mut Scratch, - ) where - Module: VecZnxDftBytesOf - + VmpApplyDftToDftTmpBytes - + VecZnxNormalizeTmpBytes - + VecZnxDftApply - + VmpApplyDftToDft - + VmpApplyDftToDftAdd - + VecZnxIdftApplyConsume - + VecZnxBigNormalize - + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, - { - #[cfg(debug_assertions)] - { - use crate::layouts::LWEInfos; - - assert_eq!(rhs.n(), self.n()); - assert_eq!( - self.rank(), - rhs.rank(), - "ggsw_out rank: {} != ggsw_apply: {}", - self.rank(), - rhs.rank() - ); - } - - (0..(self.rank() + 1).into()).for_each(|col_i| { - (0..self.dnum().into()).for_each(|row_j| { - self.at_mut(row_j, col_i) - .external_product_inplace(module, rhs, scratch); - }); - }); + ) { } } diff --git a/poulpy-core/src/external_product/glwe_ct.rs b/poulpy-core/src/external_product/glwe_ct.rs index 6ee5796..06de868 100644 --- a/poulpy-core/src/external_product/glwe_ct.rs +++ b/poulpy-core/src/external_product/glwe_ct.rs @@ -1,58 +1,59 @@ use poulpy_hal::{ api::{ - ScratchAvailable, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, + ModuleN, ScratchTakeBasic, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, }, - layouts::{Backend, DataMut, DataRef, DataViewMut, Module, Scratch, VecZnx, VecZnxBig}, + layouts::{Backend, DataMut, DataViewMut, Module, Scratch, VecZnx, VecZnxBig}, }; use crate::{ ScratchTakeCore, layouts::{ - GGSWInfos, GGSWToRef, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, GetDegree, LWEInfos, - prepared::{GGSWCiphertextPreparedToRef, GGSWPrepared}, + GGSWInfos, GLWE, GLWEInfos, GLWEToMut, GLWEToRef, LWEInfos, + prepared::{GGSWPrepared, GGSWPreparedToRef}, }, }; impl GLWE { - pub fn external_product_scratch_space( - module: Module, - out_infos: &OUT, - in_infos: &IN, - ggsw_infos: &GGSW, + pub fn external_product_scratch_space( + module: Module, + res_infos: &R, + a_infos: &A, + b_infos: &B, ) -> usize where - OUT: GLWEInfos, - IN: GLWEInfos, - GGSW: GGSWInfos, - Module: GLWEExternalProduct, + R: GLWEInfos, + A: GLWEInfos, + B: GGSWInfos, + Module: GLWEExternalProduct, { - module.glwe_external_product_scratch_space(out_infos, in_infos, ggsw_infos) + module.glwe_external_product_scratch_space(res_infos, a_infos, b_infos) } - pub fn external_product(&mut self, module: &Module, lhs: &L, rhs: &R, scratch: &mut Scratch) + pub fn external_product(&mut self, module: &Module, a: &A, b: &B, scratch: &mut Scratch) where - L: GLWEToRef, - R: GGSWToRef, - Module: GLWEExternalProduct, - Scratch: ScratchTakeCore, + A: GLWEToRef, + B: GGSWPreparedToRef, + Module: GLWEExternalProduct, + Scratch: ScratchTakeCore, { - module.glwe_external_product(self, lhs, rhs, scratch); + module.glwe_external_product(self, a, b, scratch); } - pub fn external_product_inplace(&mut self, module: &Module, rhs: &R, scratch: &mut Scratch) + pub fn external_product_inplace(&mut self, module: &Module, a: &A, scratch: &mut Scratch) where - R: GGSWToRef, - Module: GLWEExternalProduct, - Scratch: ScratchTakeCore, + A: GGSWPreparedToRef, + Module: GLWEExternalProduct, + Scratch: ScratchTakeCore, { - module.glwe_external_product_inplace(self, rhs, scratch); + module.glwe_external_product_inplace(self, a, scratch); } } pub trait GLWEExternalProduct where - Self: GetDegree + Self: Sized + + ModuleN + VecZnxDftBytesOf + VmpApplyDftToDftTmpBytes + VecZnxNormalizeTmpBytes @@ -61,52 +62,48 @@ where + VmpApplyDftToDftAdd + VecZnxIdftApplyConsume + VecZnxBigNormalize - + VecZnxNormalize - + VecZnxDftBytesOf - + VmpApplyDftToDftTmpBytes - + VecZnxNormalizeTmpBytes, + + VecZnxNormalize, { - #[allow(clippy::too_many_arguments)] - fn glwe_external_product_scratch_space(&self, out_infos: &OUT, in_infos: &IN, ggsw_infos: &GGSW) -> usize + fn glwe_external_product_scratch_space(&self, res_infos: &R, a_infos: &A, b_infos: &B) -> usize where - OUT: GLWEInfos, - IN: GLWEInfos, - GGSW: GGSWInfos, + R: GLWEInfos, + A: GLWEInfos, + B: GGSWInfos, { - let in_size: usize = in_infos + let in_size: usize = a_infos .k() - .div_ceil(ggsw_infos.base2k()) - .div_ceil(ggsw_infos.dsize().into()) as usize; - let out_size: usize = out_infos.size(); - let ggsw_size: usize = ggsw_infos.size(); - let res_dft: usize = self.bytes_of_vec_znx_dft((ggsw_infos.rank() + 1).into(), ggsw_size); - let a_dft: usize = self.bytes_of_vec_znx_dft((ggsw_infos.rank() + 1).into(), in_size); + .div_ceil(b_infos.base2k()) + .div_ceil(b_infos.dsize().into()) as usize; + let out_size: usize = res_infos.size(); + let ggsw_size: usize = b_infos.size(); + let res_dft: usize = self.bytes_of_vec_znx_dft((b_infos.rank() + 1).into(), ggsw_size); + let a_dft: usize = self.bytes_of_vec_znx_dft((b_infos.rank() + 1).into(), in_size); let vmp: usize = self.vmp_apply_dft_to_dft_tmp_bytes( out_size, in_size, - in_size, // rows - (ggsw_infos.rank() + 1).into(), // cols in - (ggsw_infos.rank() + 1).into(), // cols out + in_size, // rows + (b_infos.rank() + 1).into(), // cols in + (b_infos.rank() + 1).into(), // cols out ggsw_size, ); let normalize_big: usize = self.vec_znx_normalize_tmp_bytes(); - if in_infos.base2k() == ggsw_infos.base2k() { + if a_infos.base2k() == b_infos.base2k() { res_dft + a_dft + (vmp | normalize_big) } else { - let normalize_conv: usize = VecZnx::bytes_of(self.n().into(), (ggsw_infos.rank() + 1).into(), in_size); + let normalize_conv: usize = VecZnx::bytes_of(self.n(), (b_infos.rank() + 1).into(), in_size); res_dft + ((a_dft + normalize_conv + (self.vec_znx_normalize_tmp_bytes() | vmp)) | normalize_big) } } - fn glwe_external_product_inplace(&self, res: &mut R, ggsw: &D, scratch: &mut Scratch) + fn glwe_external_product_inplace(&self, res: &mut R, a: &D, scratch: &mut Scratch) where R: GLWEToMut, - D: GGSWCiphertextPreparedToRef, + D: GGSWPreparedToRef, Scratch: ScratchTakeCore, { let res: &mut GLWE<&mut [u8]> = &mut res.to_mut(); - let rhs: &GGSWPrepared<&[u8], BE> = &ggsw.to_ref(); + let rhs: &GGSWPrepared<&[u8], BE> = &a.to_ref(); let basek_in: usize = res.base2k().into(); let basek_ggsw: usize = rhs.base2k().into(); @@ -124,8 +121,8 @@ where let dsize: usize = rhs.dsize().into(); let a_size: usize = (res.size() * basek_in).div_ceil(basek_ggsw); - let (mut res_dft, scratch_1) = scratch.take_vec_znx_dft(res.n().into(), cols, rhs.size()); // Todo optimise - let (mut a_dft, scratch_2) = scratch_1.take_vec_znx_dft(res.n().into(), cols, a_size.div_ceil(dsize)); + let (mut res_dft, scratch_1) = scratch.take_vec_znx_dft(self, cols, rhs.size()); // Todo optimise + let (mut a_dft, scratch_2) = scratch_1.take_vec_znx_dft(self, cols, a_size.div_ceil(dsize)); a_dft.data_mut().fill(0); if basek_in == basek_ggsw { @@ -153,7 +150,7 @@ where } } } else { - let (mut a_conv, scratch_3) = scratch_2.take_vec_znx(self.n().into(), cols, a_size); + let (mut a_conv, scratch_3) = scratch_2.take_vec_znx(self, cols, a_size); for j in 0..cols { self.vec_znx_normalize( @@ -211,7 +208,7 @@ where where R: GLWEToMut, A: GLWEToRef, - D: GGSWCiphertextPreparedToRef, + D: GGSWPreparedToRef, Scratch: ScratchTakeCore, { let res: &mut GLWE<&mut [u8]> = &mut res.to_mut(); @@ -239,8 +236,8 @@ where let a_size: usize = (lhs.size() * basek_in).div_ceil(basek_ggsw); - let (mut res_dft, scratch_1) = scratch.take_vec_znx_dft(self.n().into(), cols, rhs.size()); // Todo optimise - let (mut a_dft, scratch_2) = scratch_1.take_vec_znx_dft(self.n().into(), cols, a_size.div_ceil(dsize)); + let (mut res_dft, scratch_1) = scratch.take_vec_znx_dft(self, cols, rhs.size()); // Todo optimise + let (mut a_dft, scratch_2) = scratch_1.take_vec_znx_dft(self, cols, a_size.div_ceil(dsize)); a_dft.data_mut().fill(0); if basek_in == basek_ggsw { @@ -268,7 +265,7 @@ where } } } else { - let (mut a_conv, scratch_3) = scratch_2.take_vec_znx(self.n().into(), cols, a_size); + let (mut a_conv, scratch_3) = scratch_2.take_vec_znx(self, cols, a_size); for j in 0..cols { self.vec_znx_normalize( @@ -324,7 +321,7 @@ where } impl GLWEExternalProduct for Module where - Self: GetDegree + Self: ModuleN + VecZnxDftBytesOf + VmpApplyDftToDftTmpBytes + VecZnxNormalizeTmpBytes diff --git a/poulpy-core/src/glwe_packing.rs b/poulpy-core/src/glwe_packing.rs index c5a2129..05a2965 100644 --- a/poulpy-core/src/glwe_packing.rs +++ b/poulpy-core/src/glwe_packing.rs @@ -2,17 +2,17 @@ use std::collections::HashMap; use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, - VecZnxBigAutomorphismInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallNegateInplace, VecZnxCopy, - VecZnxDftApply, VecZnxDftBytesOf, VecZnxDftCopy, VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, VecZnxNegateInplace, - VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace, VecZnxRshInplace, - VecZnxSub, VecZnxSubInplace, VecZnxSwitchRing, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, + ScratchAvailable, VecZnxAddInplace, VecZnxAutomorphismInplace, VecZnxBigAddSmallInplace, VecZnxBigAutomorphismInplace, + VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxBigSubSmallNegateInplace, VecZnxCopy, VecZnxDftApply, + VecZnxDftBytesOf, VecZnxDftCopy, VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, VecZnxNegateInplace, VecZnxNormalize, + VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxRotate, VecZnxRotateInplace, VecZnxRshInplace, VecZnxSub, + VecZnxSubInplace, VecZnxSwitchRing, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; use crate::{ - GLWEOperations, TakeGLWE, + GLWEOperations, layouts::{GGLWEInfos, GLWE, GLWEInfos, LWEInfos, prepared::AutomorphismKeyPrepared}, }; @@ -43,12 +43,12 @@ impl Accumulator { /// * `base2k`: base 2 logarithm of the GLWE ciphertext in memory digit representation. /// * `k`: base 2 precision of the GLWE ciphertext precision over the Torus. /// * `rank`: rank of the GLWE ciphertext. - pub fn alloc(infos: &A) -> Self + pub fn alloc(module: &Module, infos: &A) -> Self where A: GLWEInfos, { Self { - data: GLWE::alloc_from_infos(infos), + data: GLWE::alloc_from_infos(module, infos), value: false, control: false, } @@ -66,13 +66,13 @@ impl GLWEPacker { /// and N GLWE ciphertext can be packed. With `log_batch=2` all coefficients /// which are multiples of X^{N/4} are packed. Meaning that N/4 ciphertexts /// can be packed. - pub fn new(infos: &A, log_batch: usize) -> Self + pub fn new(module: Module, infos: &A, log_batch: usize) -> Self where A: GLWEInfos, { let mut accumulators: Vec = Vec::::new(); let log_n: usize = infos.n().log2(); - (0..log_n - log_batch).for_each(|_| accumulators.push(Accumulator::alloc(infos))); + (0..log_n - log_batch).for_each(|_| accumulators.push(Accumulator::alloc(module, infos))); Self { accumulators, log_batch, @@ -142,7 +142,7 @@ impl GLWEPacker { + VecZnxBigAutomorphismInplace + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { assert!( (self.counter as u32) < self.accumulators[0].data.n(), @@ -217,7 +217,7 @@ fn pack_core( + VecZnxBigAutomorphismInplace + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { let log_n: usize = module.log_n(); @@ -274,7 +274,7 @@ where KEY: GGLWEInfos, Module: VecZnxDftBytesOf + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VecZnxNormalizeTmpBytes, { - GLWE::bytes_of(out_infos) + GLWE::bytes_of_from_infos(module, out_infos) + (GLWE::rsh_scratch_space(module.n()) | GLWE::automorphism_inplace_scratch_space(module, out_infos, key_infos)) } @@ -310,7 +310,7 @@ fn combine( + VecZnxBigAutomorphismInplace + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx + TakeGLWE, + Scratch: ScratchAvailable, { let log_n: usize = acc.data.n().log2(); let a: &mut GLWE> = &mut acc.data; @@ -426,7 +426,7 @@ pub fn glwe_packing( + VecZnxBigSubSmallNegateInplace + VecZnxRotate + VecZnxNormalize, - Scratch: TakeVecZnx + TakeVecZnxDft + ScratchAvailable, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -493,7 +493,7 @@ fn pack_internal( + VecZnxBigSubSmallNegateInplace + VecZnxRotate + VecZnxNormalize, - Scratch: TakeVecZnx + TakeVecZnxDft + ScratchAvailable, + Scratch: ScratchAvailable, { // Goal is to evaluate: a = a + b*X^t + phi(a - b*X^t)) // We also use the identity: AUTO(a * X^t, g) = -X^t * AUTO(a, g) diff --git a/poulpy-core/src/glwe_trace.rs b/poulpy-core/src/glwe_trace.rs index 5158361..1d7a6e6 100644 --- a/poulpy-core/src/glwe_trace.rs +++ b/poulpy-core/src/glwe_trace.rs @@ -2,15 +2,14 @@ use std::collections::HashMap; use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigAutomorphismInplace, VecZnxBigNormalize, - VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, - VecZnxNormalizeTmpBytes, VecZnxRshInplace, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, + ScratchAvailable, VecZnxBigAddSmallInplace, VecZnxBigAutomorphismInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, + VecZnxCopy, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, + VecZnxRshInplace, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnx}, }; use crate::{ - TakeGLWE, layouts::{Base2K, GGLWEInfos, GLWE, GLWEInfos, GLWELayout, LWEInfos, prepared::AutomorphismKeyPrepared}, operations::GLWEOperations, }; @@ -87,7 +86,7 @@ impl GLWE { + VecZnxCopy + VecZnxNormalizeTmpBytes + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { self.copy(module, lhs); self.trace_inplace(module, start, end, auto_keys, scratch); @@ -114,7 +113,7 @@ impl GLWE { + VecZnxRshInplace + VecZnxNormalizeTmpBytes + VecZnxNormalize, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { let basek_ksk: Base2K = auto_keys .get(auto_keys.keys().next().unwrap()) diff --git a/poulpy-core/src/keyswitching/gglwe_ct.rs b/poulpy-core/src/keyswitching/gglwe_ct.rs index 9b6f947..b1fd8f4 100644 --- a/poulpy-core/src/keyswitching/gglwe_ct.rs +++ b/poulpy-core/src/keyswitching/gglwe_ct.rs @@ -1,7 +1,7 @@ use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, - VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, + ScratchAvailable, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftApply, + VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxZero}, @@ -57,7 +57,7 @@ impl AutomorphismKey { + VecZnxBigNormalize + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { self.key.keyswitch(module, &lhs.key, rhs, scratch); } @@ -79,7 +79,7 @@ impl AutomorphismKey { + VecZnxBigNormalize + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { self.key.keyswitch_inplace(module, &rhs.key, scratch); } @@ -130,7 +130,7 @@ impl GLWESwitchingKey { + VecZnxBigNormalize + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -201,7 +201,7 @@ impl GLWESwitchingKey { + VecZnxBigNormalize + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/keyswitching/ggsw_ct.rs b/poulpy-core/src/keyswitching/ggsw_ct.rs index 42aa925..4f89a41 100644 --- a/poulpy-core/src/keyswitching/ggsw_ct.rs +++ b/poulpy-core/src/keyswitching/ggsw_ct.rs @@ -1,9 +1,8 @@ use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigBytesOf, - VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftAddInplace, VecZnxDftApply, VecZnxDftBytesOf, - VecZnxDftCopy, VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, - VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, + ScratchAvailable, VecZnxBigAddSmallInplace, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxCopy, + VecZnxDftAddInplace, VecZnxDftApply, VecZnxDftBytesOf, VecZnxDftCopy, VecZnxIdftApplyConsume, VecZnxIdftApplyTmpA, + VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, VecZnx, VmpPMat, ZnxInfos}, }; @@ -130,7 +129,7 @@ impl GGSW { + VecZnxBigNormalize + VecZnxIdftApplyTmpA + VecZnxNormalize, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -172,7 +171,7 @@ impl GGSW { + VecZnxDftAddInplace + VecZnxIdftApplyTmpA + VecZnxNormalize, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig + TakeVecZnx, + Scratch: ScratchAvailable, { (0..lhs.dnum().into()).for_each(|row_i| { // Key-switch column 0, i.e. @@ -206,7 +205,7 @@ impl GGSW { + VecZnxDftAddInplace + VecZnxIdftApplyTmpA + VecZnxNormalize, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig + TakeVecZnx, + Scratch: ScratchAvailable, { (0..self.dnum().into()).for_each(|row_i| { // Key-switch column 0, i.e. @@ -235,7 +234,7 @@ impl GGSW { + VecZnxBigNormalize + VecZnxIdftApplyTmpA + VecZnxNormalize, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnxBig + TakeVecZnx, + Scratch: ScratchAvailable, { let basek_in: usize = self.base2k().into(); let basek_tsk: usize = tsk.base2k().into(); diff --git a/poulpy-core/src/keyswitching/glwe_ct.rs b/poulpy-core/src/keyswitching/glwe_ct.rs index 1f3e10c..ebd0243 100644 --- a/poulpy-core/src/keyswitching/glwe_ct.rs +++ b/poulpy-core/src/keyswitching/glwe_ct.rs @@ -1,7 +1,7 @@ use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, - VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, + ScratchAvailable, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxDftApply, + VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, DataViewMut, Module, Scratch, VecZnx, VecZnxBig, VecZnxDft, VmpPMat, ZnxInfos}, @@ -163,7 +163,7 @@ impl GLWE { + VecZnxBigNormalize + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -206,7 +206,7 @@ impl GLWE { + VecZnxBigNormalize + VecZnxNormalize + VecZnxNormalizeTmpBytes, - Scratch: ScratchAvailable + TakeVecZnxDft + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { @@ -254,7 +254,7 @@ impl GLWE { + VecZnxBigAddSmallInplace + VecZnxBigNormalize + VecZnxNormalize, - Scratch: TakeVecZnxDft + TakeVecZnx, + Scratch:, { if rhs.dsize() == 1 { return keyswitch_vmp_one_digit( @@ -300,7 +300,7 @@ where + VecZnxIdftApplyConsume + VecZnxBigAddSmallInplace + VecZnxNormalize, - Scratch: TakeVecZnxDft + TakeVecZnx, + Scratch:, { let cols: usize = a.cols(); @@ -347,7 +347,7 @@ where + VecZnxIdftApplyConsume + VecZnxBigAddSmallInplace + VecZnxNormalize, - Scratch: TakeVecZnxDft + TakeVecZnx, + Scratch:, { let cols: usize = a.cols(); let a_size: usize = (a.size() * basek_in).div_ceil(basek_ksk); diff --git a/poulpy-core/src/keyswitching/lwe_ct.rs b/poulpy-core/src/keyswitching/lwe_ct.rs index 9a0c3bc..938c732 100644 --- a/poulpy-core/src/keyswitching/lwe_ct.rs +++ b/poulpy-core/src/keyswitching/lwe_ct.rs @@ -1,16 +1,13 @@ use poulpy_hal::{ api::{ - ScratchAvailable, TakeVecZnx, TakeVecZnxDft, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, - VecZnxCopy, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, - VmpApplyDftToDft, VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, + ScratchAvailable, VecZnxBigAddSmallInplace, VecZnxBigNormalize, VecZnxBigNormalizeTmpBytes, VecZnxCopy, VecZnxDftApply, + VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalize, VecZnxNormalizeTmpBytes, VmpApplyDftToDft, + VmpApplyDftToDftAdd, VmpApplyDftToDftTmpBytes, }, layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxView, ZnxViewMut, ZnxZero}, }; -use crate::{ - TakeGLWE, - layouts::{GGLWEInfos, GLWE, GLWELayout, LWE, LWEInfos, Rank, TorusPrecision, prepared::LWESwitchingKeyPrepared}, -}; +use crate::layouts::{GGLWEInfos, GLWE, GLWELayout, LWE, LWEInfos, Rank, TorusPrecision, prepared::LWESwitchingKeyPrepared}; impl LWE> { pub fn keyswitch_scratch_space( @@ -51,8 +48,8 @@ impl LWE> { rank: Rank(1), }; - let glwe_in: usize = GLWE::bytes_of(&glwe_in_infos); - let glwe_out: usize = GLWE::bytes_of(&glwe_out_infos); + let glwe_in: usize = GLWE::bytes_of_from_infos(module, &glwe_in_infos); + let glwe_out: usize = GLWE::bytes_of_from_infos(module, &glwe_out_infos); let ks: usize = GLWE::keyswitch_scratch_space(module, &glwe_out_infos, &glwe_in_infos, key_infos); glwe_in + glwe_out + ks @@ -81,7 +78,7 @@ impl LWE { + VecZnxNormalize + VecZnxNormalizeTmpBytes + VecZnxCopy, - Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, + Scratch: ScratchAvailable, { #[cfg(debug_assertions)] { diff --git a/poulpy-core/src/layouts/compressed/gglwe_atk.rs b/poulpy-core/src/layouts/compressed/gglwe_atk.rs index 04a51c0..5b675a5 100644 --- a/poulpy-core/src/layouts/compressed/gglwe_atk.rs +++ b/poulpy-core/src/layouts/compressed/gglwe_atk.rs @@ -138,31 +138,31 @@ where } impl AutomorphismKeyCompressed> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: AutomorphismKeyCompressedAlloc, + M: AutomorphismKeyCompressedAlloc, { module.alloc_automorphism_key_compressed_from_infos(infos) } - pub fn alloc(module: Module, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self where - Module: AutomorphismKeyCompressedAlloc, + M: AutomorphismKeyCompressedAlloc, { module.alloc_automorphism_key_compressed(base2k, k, rank, dnum, dsize) } - pub fn bytes_of_from_infos(module: Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: AutomorphismKeyCompressedAlloc, + M: AutomorphismKeyCompressedAlloc, { module.bytes_of_automorphism_key_compressed_from_infos(infos) } - pub fn bytes_of( - module: Module, + pub fn bytes_of( + module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, @@ -170,7 +170,7 @@ impl AutomorphismKeyCompressed> { dsize: Dsize, ) -> usize where - Module: AutomorphismKeyCompressedAlloc, + M: AutomorphismKeyCompressedAlloc, { module.bytes_of_automorphism_key_compressed(base2k, k, rank, dnum, dsize) } @@ -210,10 +210,10 @@ impl AutomorphismKey where Self: SetAutomorphismGaloisElement, { - pub fn decompress(&mut self, module: &Module, other: &O) + pub fn decompress(&mut self, module: &M, other: &O) where O: AutomorphismKeyCompressedToRef + GetAutomorphismGaloisElement, - Module: AutomorphismKeyDecompress, + M: AutomorphismKeyDecompress, { module.decompress_automorphism_key(self, other); } diff --git a/poulpy-core/src/layouts/compressed/gglwe_ct.rs b/poulpy-core/src/layouts/compressed/gglwe_ct.rs index 51bb1fb..4accd8f 100644 --- a/poulpy-core/src/layouts/compressed/gglwe_ct.rs +++ b/poulpy-core/src/layouts/compressed/gglwe_ct.rs @@ -186,16 +186,16 @@ where impl GGLWECompressedAlloc for Module where Self: GetDegree {} impl GGLWECompressed> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: GGLWECompressedAlloc, + M: GGLWECompressedAlloc, { module.alloc_gglwe_compressed_from_infos(infos) } - pub fn alloc( - module: &Module, + pub fn alloc( + module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, @@ -204,21 +204,21 @@ impl GGLWECompressed> { dsize: Dsize, ) -> Self where - Module: GGLWECompressedAlloc, + M: GGLWECompressedAlloc, { module.alloc_gglwe_compressed(base2k, k, rank_in, rank_out, dnum, dsize) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: GGLWECompressedAlloc, + M: GGLWECompressedAlloc, { module.bytes_of_gglwe_compressed_from_infos(infos) } - pub fn byte_of( - module: &Module, + pub fn byte_of( + module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, @@ -226,7 +226,7 @@ impl GGLWECompressed> { dsize: Dsize, ) -> usize where - Module: GGLWECompressedAlloc, + M: GGLWECompressedAlloc, { module.bytes_of_gglwe_compressed(base2k, k, rank_in, dnum, dsize) } @@ -315,10 +315,10 @@ where impl GGLWEDecompress for Module where Self: VecZnxFillUniform + VecZnxCopy {} impl GGLWE { - pub fn decompress(&mut self, module: &Module, other: &O) + pub fn decompress(&mut self, module: &M, other: &O) where O: GGLWECompressedToRef, - Module: GGLWEDecompress, + M: GGLWEDecompress, { module.decompress_gglwe(self, other); } diff --git a/poulpy-core/src/layouts/compressed/gglwe_ksk.rs b/poulpy-core/src/layouts/compressed/gglwe_ksk.rs index 450c5bc..53f57e2 100644 --- a/poulpy-core/src/layouts/compressed/gglwe_ksk.rs +++ b/poulpy-core/src/layouts/compressed/gglwe_ksk.rs @@ -135,16 +135,16 @@ where } impl GLWESwitchingKeyCompressed> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: GLWESwitchingKeyCompressedAlloc, + M: GLWESwitchingKeyCompressedAlloc, { module.alloc_glwe_switching_key_compressed_from_infos(infos) } - pub fn alloc( - module: &Module, + pub fn alloc( + module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, @@ -153,21 +153,21 @@ impl GLWESwitchingKeyCompressed> { dsize: Dsize, ) -> Self where - Module: GLWESwitchingKeyCompressedAlloc, + M: GLWESwitchingKeyCompressedAlloc, { module.alloc_glwe_switching_key_compressed(base2k, k, rank_in, rank_out, dnum, dsize) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: GLWESwitchingKeyCompressedAlloc, + M: GLWESwitchingKeyCompressedAlloc, { module.bytes_of_glwe_switching_key_compressed_from_infos(infos) } - pub fn bytes_of( - module: &Module, + pub fn bytes_of( + module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, @@ -175,7 +175,7 @@ impl GLWESwitchingKeyCompressed> { dsize: Dsize, ) -> usize where - Module: GLWESwitchingKeyCompressedAlloc, + M: GLWESwitchingKeyCompressedAlloc, { module.bytes_of_glwe_switching_key_compressed(base2k, k, rank_in, dnum, dsize) } @@ -216,10 +216,10 @@ where impl GLWESwitchingKeyDecompress for Module where Self: GGLWEDecompress {} impl GLWESwitchingKey { - pub fn decompress(&mut self, module: Module, other: &O) + pub fn decompress(&mut self, module: &M, other: &O) where O: GLWESwitchingKeyCompressedToRef, - Module: GGLWEDecompress, + M: GLWESwitchingKeyDecompress, { module.decompress_glwe_switching_key(self, other); } diff --git a/poulpy-core/src/layouts/compressed/gglwe_tsk.rs b/poulpy-core/src/layouts/compressed/gglwe_tsk.rs index 730336c..173d065 100644 --- a/poulpy-core/src/layouts/compressed/gglwe_tsk.rs +++ b/poulpy-core/src/layouts/compressed/gglwe_tsk.rs @@ -140,31 +140,31 @@ where } impl TensorKeyCompressed> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: TensorKeyCompressedAlloc, + M: TensorKeyCompressedAlloc, { module.alloc_tensor_key_compressed_from_infos(infos) } - pub fn alloc(module: Module, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self where - Module: TensorKeyCompressedAlloc, + M: TensorKeyCompressedAlloc, { module.alloc_tensor_key_compressed(base2k, k, rank, dnum, dsize) } - pub fn bytes_of_from_infos(module: Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: TensorKeyCompressedAlloc, + M: TensorKeyCompressedAlloc, { module.bytes_of_tensor_key_compressed_from_infos(infos) } - pub fn bytes_of( - module: Module, + pub fn bytes_of( + module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, @@ -172,7 +172,7 @@ impl TensorKeyCompressed> { dsize: Dsize, ) -> usize where - Module: TensorKeyCompressedAlloc, + M: TensorKeyCompressedAlloc, { module.bytes_of_tensor_key_compressed(base2k, k, rank, dnum, dsize) } @@ -243,10 +243,10 @@ where impl TensorKeyDecompress for Module where Self: GLWESwitchingKeyDecompress {} impl TensorKey { - pub fn decompress(&mut self, module: &Module, other: &O) + pub fn decompress(&mut self, module: &M, other: &O) where O: TensorKeyCompressedToRef, - Module: GLWESwitchingKeyDecompress, + M: TensorKeyDecompress, { module.decompress_tensor_key(self, other); } diff --git a/poulpy-core/src/layouts/compressed/ggsw_ct.rs b/poulpy-core/src/layouts/compressed/ggsw_ct.rs index d417385..aba734f 100644 --- a/poulpy-core/src/layouts/compressed/ggsw_ct.rs +++ b/poulpy-core/src/layouts/compressed/ggsw_ct.rs @@ -170,31 +170,31 @@ where } impl GGSWCompressed> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGSWInfos, - Module: GGSWCompressedAlloc, + M: GGSWCompressedAlloc, { module.alloc_ggsw_compressed_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self where - Module: GGSWCompressedAlloc, + M: GGSWCompressedAlloc, { module.alloc_ggsw_compressed(base2k, k, rank, dnum, dsize) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGSWInfos, - Module: GGSWCompressedAlloc, + M: GGSWCompressedAlloc, { module.bytes_of_ggsw_compressed_key_from_infos(infos) } - pub fn bytes_of( - module: &Module, + pub fn bytes_of( + module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, @@ -202,7 +202,7 @@ impl GGSWCompressed> { dsize: Dsize, ) -> usize where - Module: GGSWCompressedAlloc, + M: GGSWCompressedAlloc, { module.bytes_of_ggsw_compressed(base2k, k, rank, dnum, dsize) } @@ -290,10 +290,10 @@ where impl GGSWDecompress for Module where Self: GGSWDecompress {} impl GGSW { - pub fn decompress(&mut self, module: &Module, other: &O) + pub fn decompress(&mut self, module: &M, other: &O) where O: GGSWCompressedToRef, - Module: GGSWDecompress, + M: GGSWDecompress, { module.decompress_ggsw(self, other); } diff --git a/poulpy-core/src/layouts/compressed/glwe_ct.rs b/poulpy-core/src/layouts/compressed/glwe_ct.rs index 1ee976a..8a5193f 100644 --- a/poulpy-core/src/layouts/compressed/glwe_ct.rs +++ b/poulpy-core/src/layouts/compressed/glwe_ct.rs @@ -106,32 +106,32 @@ where impl GLWECompressedAlloc for Module where Self: GetDegree {} impl GLWECompressed> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GLWEInfos, - Module: GLWECompressedAlloc, + M: GLWECompressedAlloc, { module.alloc_glwe_compressed_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self where - Module: GLWECompressedAlloc, + M: GLWECompressedAlloc, { module.alloc_glwe_compressed(base2k, k, rank) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GLWEInfos, - Module: GLWECompressedAlloc, + M: GLWECompressedAlloc, { module.bytes_of_glwe_compressed_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision) -> usize where - Module: GLWECompressedAlloc, + M: GLWECompressedAlloc, { module.bytes_of_glwe_compressed(base2k, k) } @@ -196,10 +196,10 @@ where impl GLWEDecompress for Module where Self: GetDegree + VecZnxFillUniform + VecZnxCopy {} impl GLWE { - pub fn decompress(&mut self, module: &Module, other: &O) + pub fn decompress(&mut self, module: &M, other: &O) where O: GLWECompressedToRef + GLWEInfos, - Module: GLWEDecompress, + M: GLWEDecompress, { module.decompress_glwe(self, other); } diff --git a/poulpy-core/src/layouts/compressed/glwe_to_lwe_ksk.rs b/poulpy-core/src/layouts/compressed/glwe_to_lwe_ksk.rs index 9f038a3..afdb493 100644 --- a/poulpy-core/src/layouts/compressed/glwe_to_lwe_ksk.rs +++ b/poulpy-core/src/layouts/compressed/glwe_to_lwe_ksk.rs @@ -150,32 +150,32 @@ where impl GLWEToLWESwitchingKeyCompressedAlloc for Module where Self: GLWESwitchingKeyCompressedAlloc {} impl GLWEToLWESwitchingKeyCompressed> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: GLWEToLWESwitchingKeyCompressedAlloc, + M: GLWEToLWESwitchingKeyCompressedAlloc, { module.alloc_glwe_to_lwe_switching_key_compressed_from_infos(infos) } - pub fn alloc(module: Module, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self where - Module: GLWEToLWESwitchingKeyCompressedAlloc, + M: GLWEToLWESwitchingKeyCompressedAlloc, { module.alloc_glwe_to_lwe_switching_key_compressed(base2k, k, rank_in, dnum) } - pub fn bytes_of_from_infos(module: Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: GLWEToLWESwitchingKeyCompressedAlloc, + M: GLWEToLWESwitchingKeyCompressedAlloc, { module.bytes_of_glwe_to_lwe_switching_key_compressed_from_infos(infos) } - pub fn bytes_of(module: Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum, rank_in: Rank) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum, rank_in: Rank) -> usize where - Module: GLWEToLWESwitchingKeyCompressedAlloc, + M: GLWEToLWESwitchingKeyCompressedAlloc, { module.bytes_of_glwe_to_lwe_switching_key_compressed(base2k, k, rank_in, dnum) } @@ -197,10 +197,10 @@ where impl GLWEToLWESwitchingKeyDecompress for Module where Self: GLWESwitchingKeyDecompress {} impl GLWEToLWESwitchingKey { - pub fn decompress(&mut self, module: &Module, other: &O) + pub fn decompress(&mut self, module: &M, other: &O) where O: GLWEToLWESwitchingKeyCompressedToRef, - Module: GLWEToLWESwitchingKeyDecompress, + M: GLWEToLWESwitchingKeyDecompress, { module.decompress_glwe_to_lwe_switching_key(self, other); } diff --git a/poulpy-core/src/layouts/compressed/lwe_ct.rs b/poulpy-core/src/layouts/compressed/lwe_ct.rs index 2696784..c1d613e 100644 --- a/poulpy-core/src/layouts/compressed/lwe_ct.rs +++ b/poulpy-core/src/layouts/compressed/lwe_ct.rs @@ -91,33 +91,35 @@ pub trait LWECompressedAlloc { } } +impl LWECompressedAlloc for Module{} + impl LWECompressed> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: LWEInfos, - Module: LWECompressedAlloc, + M: LWECompressedAlloc, { module.alloc_lwe_compressed_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision) -> Self where - Module: LWECompressedAlloc, + M: LWECompressedAlloc, { module.alloc_lwe_compressed(base2k, k) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: LWEInfos, - Module: LWECompressedAlloc, + M: LWECompressedAlloc, { module.bytes_of_lwe_compressed_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision) -> usize where - Module: LWECompressedAlloc, + M: LWECompressedAlloc, { module.bytes_of_lwe_compressed(base2k, k) } @@ -174,10 +176,10 @@ where impl LWEDecompress for Module where Self: ZnFillUniform {} impl LWE { - pub fn decompress(&mut self, module: &Module, other: &O) + pub fn decompress(&mut self, module: &M, other: &O) where O: LWECompressedToRef, - Module: LWEDecompress, + M: LWEDecompress, { module.decompress_lwe(self, other); } diff --git a/poulpy-core/src/layouts/compressed/lwe_ksk.rs b/poulpy-core/src/layouts/compressed/lwe_ksk.rs index ba987ab..1f5a50a 100644 --- a/poulpy-core/src/layouts/compressed/lwe_ksk.rs +++ b/poulpy-core/src/layouts/compressed/lwe_ksk.rs @@ -147,33 +147,35 @@ where } } +impl LWESwitchingKeyCompressedAlloc for Module where Self: GLWESwitchingKeyCompressedAlloc{} + impl LWESwitchingKeyCompressed> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: LWESwitchingKeyCompressedAlloc, + M: LWESwitchingKeyCompressedAlloc, { module.alloc_lwe_switching_key_compressed_from_infos(infos) } - pub fn alloc(module: Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self where - Module: LWESwitchingKeyCompressedAlloc, + M: LWESwitchingKeyCompressedAlloc, { module.alloc_lwe_switching_key_compressed(base2k, k, dnum) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: LWESwitchingKeyCompressedAlloc, + M: LWESwitchingKeyCompressedAlloc, { module.bytes_of_lwe_switching_key_compressed_from_infos(infos) } - pub fn bytes_of(module: Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize where - Module: LWESwitchingKeyCompressedAlloc, + M: LWESwitchingKeyCompressedAlloc, { module.bytes_of_lwe_switching_key_compressed(base2k, k, dnum) } @@ -195,10 +197,10 @@ where impl LWESwitchingKeyDecompress for Module where Self: GLWESwitchingKeyDecompress {} impl LWESwitchingKey { - pub fn decompress(&mut self, module: &Module, other: &O) + pub fn decompress(&mut self, module: &M, other: &O) where O: LWESwitchingKeyCompressedToRef, - Module: LWESwitchingKeyDecompress, + M: LWESwitchingKeyDecompress, { module.decompress_lwe_switching_key(self, other); } diff --git a/poulpy-core/src/layouts/compressed/lwe_to_glwe_ksk.rs b/poulpy-core/src/layouts/compressed/lwe_to_glwe_ksk.rs index ce4e889..5545518 100644 --- a/poulpy-core/src/layouts/compressed/lwe_to_glwe_ksk.rs +++ b/poulpy-core/src/layouts/compressed/lwe_to_glwe_ksk.rs @@ -140,32 +140,32 @@ where } impl LWEToGLWESwitchingKeyCompressed> { - pub fn alloc(module: &Module, infos: &A) -> Self + pub fn alloc(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: LWEToGLWESwitchingKeyCompressedAlloc, + M: LWEToGLWESwitchingKeyCompressedAlloc, { module.alloc_lwe_to_glwe_switching_key_compressed_from_infos(infos) } - pub fn alloc_with(module: &Module, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self + pub fn alloc_with(module: &M, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self where - Module: LWEToGLWESwitchingKeyCompressedAlloc, + M: LWEToGLWESwitchingKeyCompressedAlloc, { module.alloc_lwe_to_glwe_switching_key_compressed(base2k, k, rank_out, dnum) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: LWEToGLWESwitchingKeyCompressedAlloc, + M: LWEToGLWESwitchingKeyCompressedAlloc, { module.bytes_of_lwe_to_glwe_switching_key_compressed_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize where - Module: LWEToGLWESwitchingKeyCompressedAlloc, + M: LWEToGLWESwitchingKeyCompressedAlloc, { module.bytes_of_lwe_to_glwe_switching_key_compressed(base2k, k, dnum) } @@ -187,10 +187,10 @@ where impl LWEToGLWESwitchingKeyDecompress for Module where Self: GLWESwitchingKeyDecompress {} impl LWEToGLWESwitchingKey { - pub fn decompress(&mut self, module: &Module, other: &O) + pub fn decompress(&mut self, module: &M, other: &O) where O: LWEToGLWESwitchingKeyCompressedToRef, - Module: LWEToGLWESwitchingKeyDecompress, + M: LWEToGLWESwitchingKeyDecompress, { module.decompress_lwe_to_glwe_switching_key(self, other); } diff --git a/poulpy-core/src/layouts/gglwe_atk.rs b/poulpy-core/src/layouts/gglwe_atk.rs index c197828..2c99bd2 100644 --- a/poulpy-core/src/layouts/gglwe_atk.rs +++ b/poulpy-core/src/layouts/gglwe_atk.rs @@ -188,46 +188,32 @@ where } impl AutomorphismKey> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: AutomorphismKeyAlloc, + M: AutomorphismKeyAlloc, { module.alloc_automorphism_key_from_infos(infos) } - pub fn alloc_with( - module: &Module, - base2k: Base2K, - k: TorusPrecision, - rank: Rank, - dnum: Dnum, - dsize: Dsize, - ) -> Self + pub fn alloc_with(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self where - Module: AutomorphismKeyAlloc, + M: AutomorphismKeyAlloc, { module.alloc_automorphism_key(base2k, k, rank, dnum, dsize) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: AutomorphismKeyAlloc, + M: AutomorphismKeyAlloc, { module.bytes_of_automorphism_key_from_infos(infos) } - pub fn bytes_of( - module: &Module, - base2k: Base2K, - k: TorusPrecision, - rank: Rank, - dnum: Dnum, - dsize: Dsize, - ) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize where - Module: AutomorphismKeyAlloc, + M: AutomorphismKeyAlloc, { module.bytes_of_automorphism_key(base2k, k, rank, dnum, dsize) } diff --git a/poulpy-core/src/layouts/gglwe_ct.rs b/poulpy-core/src/layouts/gglwe_ct.rs index 97508c2..9c49c43 100644 --- a/poulpy-core/src/layouts/gglwe_ct.rs +++ b/poulpy-core/src/layouts/gglwe_ct.rs @@ -296,39 +296,31 @@ where impl GGLWEAlloc for Module where Self: GetDegree {} impl GGLWE> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: GGLWEAlloc, + M: GGLWEAlloc, { module.alloc_glwe_from_infos(infos) } - pub fn alloc( - module: Module, - base2k: Base2K, - k: TorusPrecision, - rank_in: Rank, - rank_out: Rank, - dnum: Dnum, - dsize: Dsize, - ) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, rank_out: Rank, dnum: Dnum, dsize: Dsize) -> Self where - Module: GGLWEAlloc, + M: GGLWEAlloc, { module.alloc_gglwe(base2k, k, rank_in, rank_out, dnum, dsize) } - pub fn bytes_of_from_infos(module: Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: GGLWEAlloc, + M: GGLWEAlloc, { module.bytes_of_gglwe_from_infos(infos) } - pub fn bytes_of( - module: Module, + pub fn bytes_of( + module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, @@ -337,7 +329,7 @@ impl GGLWE> { dsize: Dsize, ) -> usize where - Module: GGLWEAlloc, + M: GGLWEAlloc, { module.bytes_of_gglwe(base2k, k, rank_in, rank_out, dnum, dsize) } diff --git a/poulpy-core/src/layouts/gglwe_ksk.rs b/poulpy-core/src/layouts/gglwe_ksk.rs index 1384ccc..b261230 100644 --- a/poulpy-core/src/layouts/gglwe_ksk.rs +++ b/poulpy-core/src/layouts/gglwe_ksk.rs @@ -227,16 +227,16 @@ where impl GLWESwitchingKeyAlloc for Module where Self: GGLWEAlloc {} impl GLWESwitchingKey> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: GLWESwitchingKeyAlloc, + M: GLWESwitchingKeyAlloc, { module.alloc_glwe_switching_key_from_infos(infos) } - pub fn alloc( - module: &Module, + pub fn alloc( + module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, @@ -245,21 +245,21 @@ impl GLWESwitchingKey> { dsize: Dsize, ) -> Self where - Module: GLWESwitchingKeyAlloc, + M: GLWESwitchingKeyAlloc, { module.alloc_glwe_switching_key(base2k, k, rank_in, rank_out, dnum, dsize) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: GLWESwitchingKeyAlloc, + M: GLWESwitchingKeyAlloc, { module.bytes_of_glwe_switching_key_from_infos(infos) } - pub fn bytes_of( - module: &Module, + pub fn bytes_of( + module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, @@ -268,7 +268,7 @@ impl GLWESwitchingKey> { dsize: Dsize, ) -> usize where - Module: GLWESwitchingKeyAlloc, + M: GLWESwitchingKeyAlloc, { module.bytes_of_glwe_switching_key(base2k, k, rank_in, rank_out, dnum, dsize) } diff --git a/poulpy-core/src/layouts/gglwe_tsk.rs b/poulpy-core/src/layouts/gglwe_tsk.rs index 2483868..10523b1 100644 --- a/poulpy-core/src/layouts/gglwe_tsk.rs +++ b/poulpy-core/src/layouts/gglwe_tsk.rs @@ -188,39 +188,32 @@ where impl TensorKeyAlloc for Module where Self: GLWESwitchingKeyAlloc {} impl TensorKey> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: TensorKeyAlloc, + M: TensorKeyAlloc, { module.alloc_tensor_key_from_infos(infos) } - pub fn alloc(module: Module, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self where - Module: TensorKeyAlloc, + M: TensorKeyAlloc, { module.alloc_tensor_key(base2k, k, rank, dnum, dsize) } - pub fn bytes_of_from_infos(module: Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: TensorKeyAlloc, + M: TensorKeyAlloc, { module.bytes_of_tensor_key_from_infos(infos) } - pub fn bytes_of( - module: Module, - base2k: Base2K, - k: TorusPrecision, - rank: Rank, - dnum: Dnum, - dsize: Dsize, - ) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize where - Module: TensorKeyAlloc, + M: TensorKeyAlloc, { module.bytes_of_tensor_key(base2k, k, rank, dnum, dsize) } diff --git a/poulpy-core/src/layouts/ggsw_ct.rs b/poulpy-core/src/layouts/ggsw_ct.rs index b427ecd..a4fffd3 100644 --- a/poulpy-core/src/layouts/ggsw_ct.rs +++ b/poulpy-core/src/layouts/ggsw_ct.rs @@ -239,39 +239,32 @@ where } impl GGSW> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGSWInfos, - Module: GGSWAlloc, + M: GGSWAlloc, { module.alloc_ggsw_from_infos(infos) } - pub fn alloc(module: Module, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self where - Module: GGSWAlloc, + M: GGSWAlloc, { module.alloc_ggsw(base2k, k, rank, dnum, dsize) } - pub fn bytes_of_from_infos(module: Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGSWInfos, - Module: GGSWAlloc, + M: GGSWAlloc, { module.bytes_of_ggsw_from_infos(infos) } - pub fn bytes_of( - module: Module, - base2k: Base2K, - k: TorusPrecision, - rank: Rank, - dnum: Dnum, - dsize: Dsize, - ) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize where - Module: GGSWAlloc, + M: GGSWAlloc, { module.bytes_of_ggsw(base2k, k, rank, dnum, dsize) } diff --git a/poulpy-core/src/layouts/glwe_ct.rs b/poulpy-core/src/layouts/glwe_ct.rs index 5bdb2cb..328b1ff 100644 --- a/poulpy-core/src/layouts/glwe_ct.rs +++ b/poulpy-core/src/layouts/glwe_ct.rs @@ -188,32 +188,32 @@ where impl GLWEAlloc for Module where Self: GetDegree {} impl GLWE> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GLWEInfos, - Module: GLWEAlloc, + M: GLWEAlloc, { module.alloc_glwe_from_infos(infos) } - pub fn alloc(module: Module, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self where - Module: GLWEAlloc, + M: GLWEAlloc, { module.alloc_glwe(base2k, k, rank) } - pub fn bytes_of_from_infos(module: Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GLWEInfos, - Module: GLWEAlloc, + M: GLWEAlloc, { module.bytes_of_glwe_from_infos(infos) } - pub fn bytes_of(module: Module, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize where - Module: GLWEAlloc, + M: GLWEAlloc, { module.bytes_of_glwe(base2k, k, rank) } diff --git a/poulpy-core/src/layouts/glwe_pk.rs b/poulpy-core/src/layouts/glwe_pk.rs index a370656..0b0d058 100644 --- a/poulpy-core/src/layouts/glwe_pk.rs +++ b/poulpy-core/src/layouts/glwe_pk.rs @@ -122,33 +122,35 @@ where } } +impl GLWEPublicKeyAlloc for Module where Self: GetDegree {} + impl GLWEPublicKey> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GLWEInfos, - Module: GLWEPublicKeyAlloc, + M: GLWEPublicKeyAlloc, { module.alloc_glwe_public_key_from_infos(infos) } - pub fn alloc(module: Module, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self where - Module: GLWEPublicKeyAlloc, + M: GLWEPublicKeyAlloc, { module.alloc_glwe_public_key(base2k, k, rank) } - pub fn bytes_of_from_infos(module: Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GLWEInfos, - Module: GLWEPublicKeyAlloc, + M: GLWEPublicKeyAlloc, { module.bytes_of_glwe_public_key_from_infos(infos) } - pub fn bytes_of(module: Module, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize where - Module: GLWEPublicKeyAlloc, + M: GLWEPublicKeyAlloc, { module.bytes_of_glwe_public_key(base2k, k, rank) } diff --git a/poulpy-core/src/layouts/glwe_pt.rs b/poulpy-core/src/layouts/glwe_pt.rs index 5f4e2df..e7ae403 100644 --- a/poulpy-core/src/layouts/glwe_pt.rs +++ b/poulpy-core/src/layouts/glwe_pt.rs @@ -116,33 +116,35 @@ where } } +impl GLWEPlaintextAlloc for Module where Self: GetDegree {} + impl GLWEPlaintext> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GLWEInfos, - Module: GLWEPlaintextAlloc, + M: GLWEPlaintextAlloc, { module.alloc_glwe_plaintext_from_infos(infos) } - pub fn alloc(module: Module, base2k: Base2K, k: TorusPrecision) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision) -> Self where - Module: GLWEPlaintextAlloc, + M: GLWEPlaintextAlloc, { module.alloc_glwe_plaintext(base2k, k) } - pub fn bytes_of_from_infos(module: Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GLWEInfos, - Module: GLWEPlaintextAlloc, + M: GLWEPlaintextAlloc, { module.bytes_of_glwe_plaintext_from_infos(infos) } - pub fn bytes_of(module: Module, base2k: Base2K, k: TorusPrecision) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision) -> usize where - Module: GLWEPlaintextAlloc, + M: GLWEPlaintextAlloc, { module.bytes_of_glwe_plaintext(base2k, k) } diff --git a/poulpy-core/src/layouts/glwe_sk.rs b/poulpy-core/src/layouts/glwe_sk.rs index c5be370..65caa70 100644 --- a/poulpy-core/src/layouts/glwe_sk.rs +++ b/poulpy-core/src/layouts/glwe_sk.rs @@ -100,33 +100,35 @@ where } } +impl GLWESecretAlloc for Module where Self: GetDegree {} + impl GLWESecret> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GLWEInfos, - Module: GLWESecretAlloc, + M: GLWESecretAlloc, { module.alloc_glwe_secret_from_infos(infos) } - pub fn alloc(module: Module, rank: Rank) -> Self + pub fn alloc(module: &M, rank: Rank) -> Self where - Module: GLWESecretAlloc, + M: GLWESecretAlloc, { module.alloc_glwe_secret(rank) } - pub fn bytes_of_from_infos(module: Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GLWEInfos, - Module: GLWESecretAlloc, + M: GLWESecretAlloc, { module.bytes_of_glwe_secret_from_infos(infos) } - pub fn bytes_of(module: Module, rank: Rank) -> usize + pub fn bytes_of(module: &M, rank: Rank) -> usize where - Module: GLWESecretAlloc, + M: GLWESecretAlloc, { module.bytes_of_glwe_secret(rank) } diff --git a/poulpy-core/src/layouts/glwe_to_lwe_ksk.rs b/poulpy-core/src/layouts/glwe_to_lwe_ksk.rs index 4020721..76e0ebc 100644 --- a/poulpy-core/src/layouts/glwe_to_lwe_ksk.rs +++ b/poulpy-core/src/layouts/glwe_to_lwe_ksk.rs @@ -185,33 +185,35 @@ where } } +impl GLWEToLWESwitchingKeyAlloc for Module where Self: GLWESwitchingKeyAlloc {} + impl GLWEToLWESwitchingKey> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: GLWEToLWESwitchingKeyAlloc, + M: GLWEToLWESwitchingKeyAlloc, { module.alloc_glwe_to_lwe_switching_key_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self where - Module: GLWEToLWESwitchingKeyAlloc, + M: GLWEToLWESwitchingKeyAlloc, { module.alloc_glwe_to_lwe_switching_key(base2k, k, rank_in, dnum) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: GLWEToLWESwitchingKeyAlloc, + M: GLWEToLWESwitchingKeyAlloc, { module.bytes_of_glwe_to_lwe_switching_key_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> usize where - Module: GLWEToLWESwitchingKeyAlloc, + M: GLWEToLWESwitchingKeyAlloc, { module.bytes_of_glwe_to_lwe_switching_key(base2k, k, rank_in, dnum) } diff --git a/poulpy-core/src/layouts/lwe_ct.rs b/poulpy-core/src/layouts/lwe_ct.rs index 26ee40b..e5b218d 100644 --- a/poulpy-core/src/layouts/lwe_ct.rs +++ b/poulpy-core/src/layouts/lwe_ct.rs @@ -153,33 +153,35 @@ pub trait LWEAlloc { } } +impl LWEAlloc for Module {} + impl LWE> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: LWEInfos, - Module: LWEAlloc, + M: LWEAlloc, { module.alloc_lwe_from_infos(infos) } - pub fn alloc(module: &Module, n: Degree, base2k: Base2K, k: TorusPrecision) -> Self + pub fn alloc(module: &M, n: Degree, base2k: Base2K, k: TorusPrecision) -> Self where - Module: LWEAlloc, + M: LWEAlloc, { module.alloc_lwe(n, base2k, k) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: LWEInfos, - Module: LWEAlloc, + M: LWEAlloc, { module.bytes_of_lwe_from_infos(infos) } - pub fn bytes_of(module: &Module, n: Degree, base2k: Base2K, k: TorusPrecision) -> usize + pub fn bytes_of(module: &M, n: Degree, base2k: Base2K, k: TorusPrecision) -> usize where - Module: LWEAlloc, + M: LWEAlloc, { module.bytes_of_lwe(n, base2k, k) } diff --git a/poulpy-core/src/layouts/lwe_ksk.rs b/poulpy-core/src/layouts/lwe_ksk.rs index 77a027a..e449da6 100644 --- a/poulpy-core/src/layouts/lwe_ksk.rs +++ b/poulpy-core/src/layouts/lwe_ksk.rs @@ -161,32 +161,32 @@ where impl LWESwitchingKeyAlloc for Module where Self: GLWESwitchingKeyAlloc {} impl LWESwitchingKey> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: LWESwitchingKeyAlloc, + M: LWESwitchingKeyAlloc, { module.alloc_lwe_switching_key_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self where - Module: LWESwitchingKeyAlloc, + M: LWESwitchingKeyAlloc, { module.alloc_lwe_switching_key(base2k, k, dnum) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: LWESwitchingKeyAlloc, + M: LWESwitchingKeyAlloc, { module.bytes_of_glwe_switching_key_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize where - Module: LWESwitchingKeyAlloc, + M: LWESwitchingKeyAlloc, { module.bytes_of_lwe_switching_key(base2k, k, dnum) } diff --git a/poulpy-core/src/layouts/lwe_pt.rs b/poulpy-core/src/layouts/lwe_pt.rs index fb23b18..01ae19b 100644 --- a/poulpy-core/src/layouts/lwe_pt.rs +++ b/poulpy-core/src/layouts/lwe_pt.rs @@ -72,14 +72,18 @@ pub trait LWEPlaintextAlloc { impl LWEPlaintextAlloc for Module {} impl LWEPlaintext> { - pub fn alloc_from_infos(module: Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: LWEInfos, + M: LWEPlaintextAlloc, { module.alloc_lwe_plaintext_from_infos(infos) } - pub fn alloc(module: Module, base2k: Base2K, k: TorusPrecision) -> Self { + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision) -> Self + where + M: LWEPlaintextAlloc, + { module.alloc_lwe_plaintext(base2k, k) } } diff --git a/poulpy-core/src/layouts/lwe_sk.rs b/poulpy-core/src/layouts/lwe_sk.rs index 4190a4b..b5f019f 100644 --- a/poulpy-core/src/layouts/lwe_sk.rs +++ b/poulpy-core/src/layouts/lwe_sk.rs @@ -25,9 +25,9 @@ pub trait LWESecretAlloc { impl LWESecretAlloc for Module {} impl LWESecret> { - pub fn alloc(module: &Module, n: Degree) -> Self + pub fn alloc(module: &M, n: Degree) -> Self where - Module: LWESecretAlloc, + M: LWESecretAlloc, { module.alloc_lwe_secret(n) } diff --git a/poulpy-core/src/layouts/lwe_to_glwe_ksk.rs b/poulpy-core/src/layouts/lwe_to_glwe_ksk.rs index e9905ae..1427447 100644 --- a/poulpy-core/src/layouts/lwe_to_glwe_ksk.rs +++ b/poulpy-core/src/layouts/lwe_to_glwe_ksk.rs @@ -188,32 +188,32 @@ where impl LWEToGLWESwitchingKeyAlloc for Module where Self: GLWESwitchingKeyAlloc {} impl LWEToGLWESwitchingKey> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: LWEToGLWESwitchingKeyAlloc, + M: LWEToGLWESwitchingKeyAlloc, { module.alloc_lwe_to_glwe_switching_key_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self where - Module: LWEToGLWESwitchingKeyAlloc, + M: LWEToGLWESwitchingKeyAlloc, { module.alloc_lwe_to_glwe_switching_key(base2k, k, rank_out, dnum) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: LWEToGLWESwitchingKeyAlloc, + M: LWEToGLWESwitchingKeyAlloc, { module.bytes_of_lwe_to_glwe_switching_key_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum, rank_out: Rank) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum, rank_out: Rank) -> usize where - Module: LWEToGLWESwitchingKeyAlloc, + M: LWEToGLWESwitchingKeyAlloc, { module.bytes_of_lwe_to_glwe_switching_key(base2k, k, rank_out, dnum) } diff --git a/poulpy-core/src/layouts/prepared/gglwe_atk.rs b/poulpy-core/src/layouts/prepared/gglwe_atk.rs index e9f907c..d09b2e6 100644 --- a/poulpy-core/src/layouts/prepared/gglwe_atk.rs +++ b/poulpy-core/src/layouts/prepared/gglwe_atk.rs @@ -145,32 +145,32 @@ where impl AutomorphismKeyPreparedAlloc for Module where Module: GLWESwitchingKeyPreparedAlloc {} impl AutomorphismKeyPrepared, B> { - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, - Module: AutomorphismKeyPreparedAlloc, + M: AutomorphismKeyPreparedAlloc, { module.alloc_automorphism_key_prepared_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> Self where - Module: AutomorphismKeyPreparedAlloc, + M: AutomorphismKeyPreparedAlloc, { module.alloc_automorphism_key_prepared(base2k, k, rank, dnum, dsize) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, - Module: AutomorphismKeyPreparedAlloc, + M: AutomorphismKeyPreparedAlloc, { module.bytes_of_automorphism_key_prepared_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize where - Module: AutomorphismKeyPreparedAlloc, + M: AutomorphismKeyPreparedAlloc, { module.bytes_of_automorphism_key_prepared(base2k, k, rank, dnum, dsize) } @@ -200,19 +200,19 @@ where impl PrepareAutomorphismKey for Module where Module: GLWESwitchingKeyPrepare {} impl AutomorphismKeyPrepared, B> { - pub fn prepare_tmp_bytes(&self, module: &Module) -> usize + pub fn prepare_tmp_bytes(&self, module: &M) -> usize where - Module: GLWESwitchingKeyPrepare, + M: PrepareAutomorphismKey, { module.prepare_automorphism_key_tmp_bytes(self) } } impl AutomorphismKeyPrepared { - pub fn prepare(&mut self, module: &Module, other: &O, scratch: &mut Scratch) + pub fn prepare(&mut self, module: &M, other: &O, scratch: &mut Scratch) where O: AutomorphismKeyToRef + GetAutomorphismGaloisElement, - Module: PrepareAutomorphismKey, + M: PrepareAutomorphismKey, { module.prepare_automorphism_key(self, other, scratch); } diff --git a/poulpy-core/src/layouts/prepared/gglwe_ct.rs b/poulpy-core/src/layouts/prepared/gglwe_ct.rs index a428474..180393a 100644 --- a/poulpy-core/src/layouts/prepared/gglwe_ct.rs +++ b/poulpy-core/src/layouts/prepared/gglwe_ct.rs @@ -151,45 +151,50 @@ where impl GGLWEPreparedAlloc for Module where Module: GetDegree + VmpPMatAlloc + VmpPMatBytesOf {} -impl GGLWEPrepared, B> -where - Module: GGLWEPreparedAlloc, -{ - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self +impl GGLWEPrepared, B> { + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, + M: GGLWEPreparedAlloc, { module.alloc_gglwe_prepared_from_infos(infos) } - pub fn alloc( - module: &Module, + pub fn alloc( + module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, rank_out: Rank, dnum: Dnum, dsize: Dsize, - ) -> Self { + ) -> Self + where + M: GGLWEPreparedAlloc, + { module.alloc_gglwe_prepared(base2k, k, rank_in, rank_out, dnum, dsize) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, + M: GGLWEPreparedAlloc, { module.bytes_of_gglwe_prepared_from_infos(infos) } - pub fn bytes_of( - module: &Module, + pub fn bytes_of( + module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, rank_out: Rank, dnum: Dnum, dsize: Dsize, - ) -> usize { + ) -> usize + where + M: GGLWEPreparedAlloc, + { module.bytes_of_gglwe_prepared(base2k, k, rank_in, rank_out, dnum, dsize) } } @@ -230,22 +235,20 @@ where impl GGLWEPrepare for Module where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare {} -impl GGLWEPrepared -where - Module: GGLWEPrepare, -{ - pub fn prepare(&mut self, module: &Module, other: &O, scratch: &mut Scratch) +impl GGLWEPrepared { + pub fn prepare(&mut self, module: &M, other: &O, scratch: &mut Scratch) where O: GGLWEToRef, + M: GGLWEPrepare, { module.prepare_gglwe(self, other, scratch); } } impl GGLWEPrepared, B> { - pub fn prepare_tmp_bytes(&self, module: &Module) -> usize + pub fn prepare_tmp_bytes(&self, module: &M) -> usize where - Module: GGLWEPrepare, + M: GGLWEPrepare, { module.prepare_gglwe_tmp_bytes(self) } diff --git a/poulpy-core/src/layouts/prepared/gglwe_ksk.rs b/poulpy-core/src/layouts/prepared/gglwe_ksk.rs index 2bd20f3..d8ab0ca 100644 --- a/poulpy-core/src/layouts/prepared/gglwe_ksk.rs +++ b/poulpy-core/src/layouts/prepared/gglwe_ksk.rs @@ -136,47 +136,52 @@ where } } -impl GLWESwitchingKeyPreparedAlloc for Module where Module: GGLWEPreparedAlloc {} +impl GLWESwitchingKeyPreparedAlloc for Module where Self: GGLWEPreparedAlloc {} -impl GLWESwitchingKeyPrepared, B> -where - Module: GLWESwitchingKeyPreparedAlloc, -{ - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self +impl GLWESwitchingKeyPrepared, B> { + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, + M: GLWESwitchingKeyPreparedAlloc, { module.alloc_glwe_switching_key_prepared_from_infos(infos) } - pub fn alloc( - module: &Module, + pub fn alloc( + module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, rank_out: Rank, dnum: Dnum, dsize: Dsize, - ) -> Self { + ) -> Self + where + M: GLWESwitchingKeyPreparedAlloc, + { module.alloc_glwe_switching_key_prepared(base2k, k, rank_in, rank_out, dnum, dsize) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, + M: GLWESwitchingKeyPreparedAlloc, { module.bytes_of_glwe_switching_key_prepared_from_infos(infos) } - pub fn bytes_of( - module: &Module, + pub fn bytes_of( + module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, rank_out: Rank, dnum: Dnum, dsize: Dsize, - ) -> usize { + ) -> usize + where + M: GLWESwitchingKeyPreparedAlloc, + { module.bytes_of_glwe_switching_key_prepared(base2k, k, rank_in, rank_out, dnum, dsize) } } @@ -206,21 +211,21 @@ where impl GLWESwitchingKeyPrepare for Module where Self: GGLWEPrepare {} impl GLWESwitchingKeyPrepared { - pub fn prepare(&mut self, module: &Module, other: &O, scratch: &mut Scratch) + pub fn prepare(&mut self, module: &M, other: &O, scratch: &mut Scratch) where O: GLWESwitchingKeyToRef + GLWESwtichingKeyGetMetaData, - Module: GLWESwitchingKeyPrepare, + M: GLWESwitchingKeyPrepare, { module.prepare_glwe_switching(self, other, scratch); } } -impl GLWESwitchingKeyPrepared, B> -where - Module: GLWESwitchingKeyPrepare, -{ - pub fn prepare_tmp_bytes(&self, module: &Module) -> usize { - module.prepare_gglwe_tmp_bytes(self) +impl GLWESwitchingKeyPrepared, B> { + pub fn prepare_tmp_bytes(&self, module: &M) -> usize + where + M: GLWESwitchingKeyPrepare, + { + module.prepare_glwe_switching_key_tmp_bytes(self) } } diff --git a/poulpy-core/src/layouts/prepared/gglwe_tsk.rs b/poulpy-core/src/layouts/prepared/gglwe_tsk.rs index 27b1699..8357e40 100644 --- a/poulpy-core/src/layouts/prepared/gglwe_tsk.rs +++ b/poulpy-core/src/layouts/prepared/gglwe_tsk.rs @@ -114,29 +114,34 @@ where impl TensorKeyPreparedAlloc for Module where Module: GLWESwitchingKeyPreparedAlloc {} -impl TensorKeyPrepared, B> -where - Module: TensorKeyPreparedAlloc, -{ - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self +impl TensorKeyPrepared, B> { + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, + M: TensorKeyPreparedAlloc, { module.alloc_tensor_key_prepared_from_infos(infos) } - pub fn alloc_with(module: &Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self { + pub fn alloc_with(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self + where + M: TensorKeyPreparedAlloc, + { module.alloc_tensor_key_prepared(base2k, k, dnum, dsize, rank) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, + M: TensorKeyPreparedAlloc, { module.bytes_of_tensor_key_prepared_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize { + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank, dnum: Dnum, dsize: Dsize) -> usize + where + M: TensorKeyPreparedAlloc, + { module.bytes_of_tensor_key_prepared(base2k, k, rank, dnum, dsize) } } @@ -190,27 +195,23 @@ where } } -impl TensorKeyPrepare for Module where Module: GLWESwitchingKeyPrepare {} +impl TensorKeyPrepare for Module where Self: GLWESwitchingKeyPrepare {} -impl TensorKeyPrepared, B> -where - Module: TensorKeyPrepare, -{ - fn prepare_tmp_bytes(&self, module: &Module, infos: &A) -> usize +impl TensorKeyPrepared, B> { + fn prepare_tmp_bytes(&self, module: &M, infos: &A) -> usize where A: GGLWEInfos, + M: TensorKeyPrepare, { module.prepare_tensor_key_tmp_bytes(infos) } } -impl TensorKeyPrepared -where - Module: TensorKeyPrepare, -{ - fn prepare(&mut self, module: &Module, other: &O, scratch: &mut Scratch) +impl TensorKeyPrepared { + fn prepare(&mut self, module: &M, other: &O, scratch: &mut Scratch) where O: TensorKeyToRef, + M: TensorKeyPrepare, { module.prepare_tensor_key(self, other, scratch); } diff --git a/poulpy-core/src/layouts/prepared/ggsw_ct.rs b/poulpy-core/src/layouts/prepared/ggsw_ct.rs index fe7f218..f8f85c9 100644 --- a/poulpy-core/src/layouts/prepared/ggsw_ct.rs +++ b/poulpy-core/src/layouts/prepared/ggsw_ct.rs @@ -135,31 +135,36 @@ where } } -impl GGSWPreparedAlloc for Module where Module: GetDegree + VmpPMatAlloc + VmpPMatBytesOf {} +impl GGSWPreparedAlloc for Module where Self: GetDegree + VmpPMatAlloc + VmpPMatBytesOf {} -impl GGSWPrepared, B> -where - Module: GGSWPreparedAlloc, -{ - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self +impl GGSWPrepared, B> { + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGSWInfos, + M: GGSWPreparedAlloc, { module.alloc_ggsw_prepared_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self { + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self + where + M: GGSWPreparedAlloc, + { module.alloc_ggsw_prepared(base2k, k, dnum, dsize, rank) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGSWInfos, + M: GGSWPreparedAlloc, { module.bytes_of_ggsw_prepared_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> usize { + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> usize + where + M: GGSWPreparedAlloc, + { module.bytes_of_ggsw_prepared(base2k, k, dnum, dsize, rank) } } @@ -204,25 +209,21 @@ where impl GGSWPrepare for Module where Self: GetDegree + VmpPrepareTmpBytes + VmpPrepare {} -impl GGSWPrepared, B> -where - Module: GGSWPrepare, -{ - pub fn prepare_tmp_bytes(&self, module: Module, infos: &A) -> usize +impl GGSWPrepared, B> { + pub fn prepare_tmp_bytes(&self, module: &M, infos: &A) -> usize where A: GGSWInfos, + M: GGSWPrepare, { module.ggsw_prepare_tmp_bytes(infos) } } -impl GGSWPrepared -where - Module: GGSWPrepare, -{ - pub fn prepare(&mut self, module: &Module, other: &O, scratch: &mut Scratch) +impl GGSWPrepared { + pub fn prepare(&mut self, module: &M, other: &O, scratch: &mut Scratch) where O: GGSWToRef, + M: GGSWPrepare, { module.ggsw_prepare(self, other, scratch); } @@ -243,11 +244,11 @@ impl GGSWPreparedToMut for GGSWPrepared { } } -pub trait GGSWCiphertextPreparedToRef { +pub trait GGSWPreparedToRef { fn to_ref(&self) -> GGSWPrepared<&[u8], B>; } -impl GGSWCiphertextPreparedToRef for GGSWPrepared { +impl GGSWPreparedToRef for GGSWPrepared { fn to_ref(&self) -> GGSWPrepared<&[u8], B> { GGSWPrepared { base2k: self.base2k, diff --git a/poulpy-core/src/layouts/prepared/glwe_pk.rs b/poulpy-core/src/layouts/prepared/glwe_pk.rs index b6f2a0c..8aa0a59 100644 --- a/poulpy-core/src/layouts/prepared/glwe_pk.rs +++ b/poulpy-core/src/layouts/prepared/glwe_pk.rs @@ -84,29 +84,34 @@ where impl GLWEPublicKeyPreparedAlloc for Module where Self: VecZnxDftAlloc + VecZnxDftBytesOf {} -impl GLWEPublicKeyPrepared, B> -where - Module: GLWEPublicKeyPreparedAlloc, -{ - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self +impl GLWEPublicKeyPrepared, B> { + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GLWEInfos, + M: GLWEPublicKeyPreparedAlloc, { module.alloc_glwe_public_key_prepared_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self { + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self + where + M: GLWEPublicKeyPreparedAlloc, + { module.alloc_glwe_public_key_prepared(base2k, k, rank) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GLWEInfos, + M: GLWEPublicKeyPreparedAlloc, { module.bytes_of_glwe_public_key_prepared_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize { + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, rank: Rank) -> usize + where + M: GLWEPublicKeyPreparedAlloc, + { module.bytes_of_glwe_public_key_prepared(base2k, k, rank) } } @@ -141,13 +146,11 @@ where impl GLWEPublicKeyPrepare for Module where Self: GetDegree + VecZnxDftApply {} -impl GLWEPublicKeyPrepared -where - Module: GLWEPublicKeyPrepare, -{ - pub fn prepare(&mut self, module: &Module, other: &O) +impl GLWEPublicKeyPrepared { + pub fn prepare(&mut self, module: &M, other: &O) where O: GLWEPublicKeyToRef + GetDist, + M: GLWEPublicKeyPrepare, { module.prepare_glwe_public_key(self, other); } diff --git a/poulpy-core/src/layouts/prepared/glwe_sk.rs b/poulpy-core/src/layouts/prepared/glwe_sk.rs index 6028698..9e3f2ef 100644 --- a/poulpy-core/src/layouts/prepared/glwe_sk.rs +++ b/poulpy-core/src/layouts/prepared/glwe_sk.rs @@ -77,29 +77,34 @@ where impl GLWESecretPreparedAlloc for Module where Self: GetDegree + SvpPPolBytesOf + SvpPPolAlloc {} -impl GLWESecretPrepared, B> -where - Module: GLWESecretPreparedAlloc, -{ - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self +impl GLWESecretPrepared, B> { + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GLWEInfos, + M: GLWESecretPreparedAlloc, { module.alloc_glwe_secret_prepared_from_infos(infos) } - pub fn alloc(module: &Module, rank: Rank) -> Self { + pub fn alloc(module: &M, rank: Rank) -> Self + where + M: GLWESecretPreparedAlloc, + { module.alloc_glwe_secret_prepared(rank) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GLWEInfos, + M: GLWESecretPreparedAlloc, { module.bytes_of_glwe_secret_from_infos(infos) } - pub fn bytes_of(module: &Module, rank: Rank) -> usize { + pub fn bytes_of(module: &M, rank: Rank) -> usize + where + M: GLWESecretPreparedAlloc, + { module.bytes_of_glwe_secret(rank) } } @@ -138,6 +143,16 @@ where impl GLWESecretPrepare for Module where Self: SvpPrepare {} +impl GLWESecretPrepared { + pub fn prepare(&mut self, module: &M, other: &O) + where + M: GLWESecretPrepare, + O: GLWESecretToRef + GetDist, + { + module.prepare_glwe_secret(self, other); + } +} + pub trait GLWESecretPreparedToRef { fn to_ref(&self) -> GLWESecretPrepared<&[u8], B>; } diff --git a/poulpy-core/src/layouts/prepared/glwe_to_lwe_ksk.rs b/poulpy-core/src/layouts/prepared/glwe_to_lwe_ksk.rs index d4b8e85..63dec0b 100644 --- a/poulpy-core/src/layouts/prepared/glwe_to_lwe_ksk.rs +++ b/poulpy-core/src/layouts/prepared/glwe_to_lwe_ksk.rs @@ -105,31 +105,36 @@ where } } -impl GLWEToLWESwitchingKeyPreparedAlloc for Module where Module: GLWESwitchingKeyPreparedAlloc {} +impl GLWEToLWESwitchingKeyPreparedAlloc for Module where Self: GLWESwitchingKeyPreparedAlloc {} -impl GLWEToLWESwitchingKeyPrepared, B> -where - Module: GLWEToLWESwitchingKeyPreparedAlloc, -{ - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self +impl GLWEToLWESwitchingKeyPrepared, B> { + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, + M: GLWEToLWESwitchingKeyPreparedAlloc, { module.alloc_glwe_to_lwe_switching_key_prepared_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self { + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> Self + where + M: GLWEToLWESwitchingKeyPreparedAlloc, + { module.alloc_glwe_to_lwe_switching_key_prepared(base2k, k, rank_in, dnum) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, + M: GLWEToLWESwitchingKeyPreparedAlloc, { module.bytes_of_glwe_to_lwe_switching_key_prepared_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> usize { + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, rank_in: Rank, dnum: Dnum) -> usize + where + M: GLWEToLWESwitchingKeyPreparedAlloc, + { module.bytes_of_glwe_to_lwe_switching_key_prepared(base2k, k, rank_in, dnum) } } @@ -157,20 +162,20 @@ where impl GLWEToLWESwitchingKeyPrepare for Module where Self: GLWESwitchingKeyPrepare {} impl GLWEToLWESwitchingKeyPrepared, B> { - pub fn prepare_tmp_bytes(&self, module: &Module, infos: &A) + pub fn prepare_tmp_bytes(&self, module: &M, infos: &A) where A: GGLWEInfos, - Module: GLWEToLWESwitchingKeyPrepare, + M: GLWEToLWESwitchingKeyPrepare, { module.prepare_glwe_to_lwe_switching_key_tmp_bytes(infos); } } impl GLWEToLWESwitchingKeyPrepared { - fn prepare(&mut self, module: &Module, other: &O, scratch: &mut Scratch) + fn prepare(&mut self, module: &M, other: &O, scratch: &mut Scratch) where O: GLWEToLWESwitchingKeyToRef, - Module: GLWEToLWESwitchingKeyPrepare, + M: GLWEToLWESwitchingKeyPrepare, { module.prepare_glwe_to_lwe_switching_key(self, other, scratch); } diff --git a/poulpy-core/src/layouts/prepared/lwe_ksk.rs b/poulpy-core/src/layouts/prepared/lwe_ksk.rs index b5b3a35..49914f2 100644 --- a/poulpy-core/src/layouts/prepared/lwe_ksk.rs +++ b/poulpy-core/src/layouts/prepared/lwe_ksk.rs @@ -116,29 +116,34 @@ where impl LWESwitchingKeyPreparedAlloc for Module where Self: GLWESwitchingKeyPreparedAlloc {} -impl LWESwitchingKeyPrepared, B> -where - Module: LWESwitchingKeyPreparedAlloc, -{ - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self +impl LWESwitchingKeyPrepared, B> { + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, + M: LWESwitchingKeyPreparedAlloc, { module.alloc_lwe_switching_key_prepared_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self { + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> Self + where + M: LWESwitchingKeyPreparedAlloc, + { module.alloc_lwe_switching_key_prepared(base2k, k, dnum) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, + M: LWESwitchingKeyPreparedAlloc, { module.bytes_of_lwe_switching_key_prepared_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize { + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum) -> usize + where + M: LWESwitchingKeyPreparedAlloc, + { module.bytes_of_lwe_switching_key_prepared(base2k, k, dnum) } } @@ -165,20 +170,20 @@ where impl LWESwitchingKeyPrepare for Module where Self: GLWESwitchingKeyPrepare {} impl LWESwitchingKeyPrepared, B> { - pub fn prepare_tmp_bytes(&self, module: &Module, infos: &A) + pub fn prepare_tmp_bytes(&self, module: &M, infos: &A) where A: GGLWEInfos, - Module: LWESwitchingKeyPrepare, + M: LWESwitchingKeyPrepare, { module.prepare_lwe_switching_key_tmp_bytes(infos); } } impl LWESwitchingKeyPrepared { - fn prepare(&mut self, module: &Module, other: &O, scratch: &mut Scratch) + fn prepare(&mut self, module: &M, other: &O, scratch: &mut Scratch) where O: LWESwitchingKeyToRef, - Module: LWESwitchingKeyPrepare, + M: LWESwitchingKeyPrepare, { module.prepare_lwe_switching_key(self, other, scratch); } diff --git a/poulpy-core/src/layouts/prepared/lwe_to_glwe_ksk.rs b/poulpy-core/src/layouts/prepared/lwe_to_glwe_ksk.rs index 53867de..e7922dc 100644 --- a/poulpy-core/src/layouts/prepared/lwe_to_glwe_ksk.rs +++ b/poulpy-core/src/layouts/prepared/lwe_to_glwe_ksk.rs @@ -114,29 +114,28 @@ where impl LWEToGLWESwitchingKeyPreparedAlloc for Module where Self: GLWESwitchingKeyPreparedAlloc {} -impl LWEToGLWESwitchingKeyPrepared, B> -where - Module: LWEToGLWESwitchingKeyPreparedAlloc, -{ - pub fn alloc_from_infos(module: &Module, infos: &A) -> Self +impl LWEToGLWESwitchingKeyPrepared, B>{ + pub fn alloc_from_infos(module: &M, infos: &A) -> Self where A: GGLWEInfos, + M: LWEToGLWESwitchingKeyPreparedAlloc, { module.alloc_lwe_to_glwe_switching_key_prepared_from_infos(infos) } - pub fn alloc(module: &Module, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self { + pub fn alloc(module: &M, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> Self where M: LWEToGLWESwitchingKeyPreparedAlloc, { module.alloc_lwe_to_glwe_switching_key_prepared(base2k, k, rank_out, dnum) } - pub fn bytes_of_from_infos(module: &Module, infos: &A) -> usize + pub fn bytes_of_from_infos(module: &M, infos: &A) -> usize where A: GGLWEInfos, + M: LWEToGLWESwitchingKeyPreparedAlloc, { module.bytes_of_lwe_to_glwe_switching_key_prepared_from_infos(infos) } - pub fn bytes_of(module: &Module, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> usize { + pub fn bytes_of(module: &M, base2k: Base2K, k: TorusPrecision, rank_out: Rank, dnum: Dnum) -> usize where M: LWEToGLWESwitchingKeyPreparedAlloc,{ module.bytes_of_lwe_to_glwe_switching_key_prepared(base2k, k, rank_out, dnum) } } @@ -164,20 +163,20 @@ where impl LWEToGLWESwitchingKeyPrepare for Module where Self: GLWESwitchingKeyPrepare {} impl LWEToGLWESwitchingKeyPrepared, B> { - pub fn prepare_tmp_bytes(&self, module: &Module, infos: &A) + pub fn prepare_tmp_bytes(&self, module: &M, infos: &A) where A: GGLWEInfos, - Module: LWEToGLWESwitchingKeyPrepare, + M: LWEToGLWESwitchingKeyPrepare, { module.prepare_lwe_to_glwe_switching_key_tmp_bytes(infos); } } impl LWEToGLWESwitchingKeyPrepared { - fn prepare(&mut self, module: &Module, other: &O, scratch: &mut Scratch) + fn prepare(&mut self, module: &M, other: &O, scratch: &mut Scratch) where O: LWEToGLWESwitchingKeyToRef, - Module: LWEToGLWESwitchingKeyPrepare, + M: LWEToGLWESwitchingKeyPrepare, { module.prepare_lwe_to_glwe_switching_key(self, other, scratch); } diff --git a/poulpy-core/src/lib.rs b/poulpy-core/src/lib.rs index 70035af..b0c5a38 100644 --- a/poulpy-core/src/lib.rs +++ b/poulpy-core/src/lib.rs @@ -22,4 +22,4 @@ pub use encryption::SIGMA; pub use scratch::*; -pub mod tests; +// pub mod tests; diff --git a/poulpy-core/src/noise/gglwe_ct.rs b/poulpy-core/src/noise/gglwe_ct.rs index ae40bf4..c924192 100644 --- a/poulpy-core/src/noise/gglwe_ct.rs +++ b/poulpy-core/src/noise/gglwe_ct.rs @@ -5,7 +5,7 @@ use poulpy_hal::{ VecZnxSubScalarInplace, }, layouts::{Backend, DataRef, Module, ScalarZnx, ScratchOwned, ZnxZero}, - oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl}, + oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl}, }; use crate::layouts::{GGLWE, GGLWEInfos, GLWE, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared}; @@ -30,13 +30,13 @@ impl GGLWE { + VecZnxBigNormalize + VecZnxNormalizeTmpBytes + VecZnxSubScalarInplace, - B: Backend + TakeVecZnxDftImpl + TakeVecZnxBigImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, + B: Backend + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, { let dsize: usize = self.dsize().into(); let base2k: usize = self.base2k().into(); let mut scratch: ScratchOwned = ScratchOwned::alloc(GLWE::decrypt_scratch_space(module, self)); - let mut pt: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(self); + let mut pt: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(module, self); (0..self.rank_in().into()).for_each(|col_i| { (0..self.dnum().into()).for_each(|row_i| { diff --git a/poulpy-core/src/noise/ggsw_ct.rs b/poulpy-core/src/noise/ggsw_ct.rs index 93302e3..4f4c4f4 100644 --- a/poulpy-core/src/noise/ggsw_ct.rs +++ b/poulpy-core/src/noise/ggsw_ct.rs @@ -6,7 +6,7 @@ use poulpy_hal::{ VecZnxSubInplace, }, layouts::{Backend, DataRef, Module, ScalarZnx, ScratchOwned, VecZnxBig, VecZnxDft, ZnxZero}, - oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl}, + oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl}, }; use crate::layouts::{GGSW, GGSWInfos, GLWE, GLWEInfos, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared}; @@ -36,14 +36,14 @@ impl GGSW { + VecZnxIdftApplyTmpA + VecZnxAddScalarInplace + VecZnxSubInplace, - B: Backend + TakeVecZnxDftImpl + TakeVecZnxBigImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, + B: Backend + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, F: Fn(usize) -> f64, { let base2k: usize = self.base2k().into(); let dsize: usize = self.dsize().into(); - let mut pt: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(self); - let mut pt_have: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(self); + let mut pt: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(module, self); + let mut pt_have: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(module, self); let mut pt_dft: VecZnxDft, B> = module.vec_znx_dft_alloc(1, self.size()); let mut pt_big: VecZnxBig, B> = module.vec_znx_big_alloc(1, self.size()); @@ -109,13 +109,13 @@ impl GGSW { + VecZnxIdftApplyTmpA + VecZnxAddScalarInplace + VecZnxSubInplace, - B: Backend + TakeVecZnxDftImpl + TakeVecZnxBigImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, + B: Backend + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, { let base2k: usize = self.base2k().into(); let dsize: usize = self.dsize().into(); - let mut pt: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(self); - let mut pt_have: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(self); + let mut pt: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(module, self); + let mut pt_have: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(module, self); let mut pt_dft: VecZnxDft, B> = module.vec_znx_dft_alloc(1, self.size()); let mut pt_big: VecZnxBig, B> = module.vec_znx_big_alloc(1, self.size()); diff --git a/poulpy-core/src/noise/glwe_ct.rs b/poulpy-core/src/noise/glwe_ct.rs index 76eaa19..3242d91 100644 --- a/poulpy-core/src/noise/glwe_ct.rs +++ b/poulpy-core/src/noise/glwe_ct.rs @@ -1,11 +1,11 @@ use poulpy_hal::{ api::{ - ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, TakeVecZnxBig, TakeVecZnxDft, VecZnxBigAddInplace, - VecZnxBigAddSmallInplace, VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, - VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSubInplace, + ScratchOwnedAlloc, ScratchOwnedBorrow, SvpApplyDftToDftInplace, VecZnxBigAddInplace, VecZnxBigAddSmallInplace, + VecZnxBigBytesOf, VecZnxBigNormalize, VecZnxDftApply, VecZnxDftBytesOf, VecZnxIdftApplyConsume, VecZnxNormalizeInplace, + VecZnxNormalizeTmpBytes, VecZnxSubInplace, }, layouts::{Backend, DataRef, Module, Scratch, ScratchOwned}, - oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl}, + oep::{ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl}, }; use crate::layouts::{GLWE, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared}; @@ -30,9 +30,9 @@ impl GLWE { + VecZnxBigAddInplace + VecZnxBigAddSmallInplace + VecZnxBigNormalize, - Scratch: TakeVecZnxDft + TakeVecZnxBig, + Scratch:, { - let mut pt_have: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(self); + let mut pt_have: GLWEPlaintext> = GLWEPlaintext::alloc_from_infos(module, self); self.decrypt(module, &mut pt_have, sk_prepared, scratch); module.vec_znx_sub_inplace(&mut pt_have.data, 0, &pt_want.data, 0); module.vec_znx_normalize_inplace(self.base2k().into(), &mut pt_have.data, 0, scratch); @@ -59,7 +59,7 @@ impl GLWE { + VecZnxNormalizeTmpBytes + VecZnxSubInplace + VecZnxNormalizeInplace, - B: Backend + TakeVecZnxDftImpl + TakeVecZnxBigImpl + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, + B: Backend + ScratchOwnedAllocImpl + ScratchOwnedBorrowImpl, { let mut scratch: ScratchOwned = ScratchOwned::alloc(GLWE::decrypt_scratch_space(module, self)); let noise_have: f64 = self.noise(module, sk_prepared, pt_want, scratch.borrow()); diff --git a/poulpy-core/src/scratch.rs b/poulpy-core/src/scratch.rs index 6cfc130..8a9e78e 100644 --- a/poulpy-core/src/scratch.rs +++ b/poulpy-core/src/scratch.rs @@ -1,13 +1,13 @@ use poulpy_hal::{ - api::{ScratchAvailable, ScratchTakeBasic}, - layouts::{Backend, Module, Scratch}, + api::{ModuleN, ScratchAvailable, ScratchTakeBasic, SvpPPolBytesOf, VecZnxDftBytesOf, VmpPMatBytesOf}, + layouts::{Backend, Scratch}, }; use crate::{ dist::Distribution, layouts::{ - AutomorphismKey, Degree, GGLWE, GGLWEInfos, GGSW, GGSWInfos, GLWE, GLWEInfos, GLWEPlaintext, GLWEPublicKey, GLWESecret, - GLWESwitchingKey, GetDegree, Rank, TensorKey, + AutomorphismKey, GGLWE, GGLWEInfos, GGSW, GGSWInfos, GLWE, GLWEInfos, GLWEPlaintext, GLWEPublicKey, GLWESecret, + GLWESwitchingKey, Rank, TensorKey, prepared::{ AutomorphismKeyPrepared, GGLWEPrepared, GGSWPrepared, GLWEPublicKeyPrepared, GLWESecretPrepared, GLWESwitchingKeyPrepared, TensorKeyPrepared, @@ -17,12 +17,14 @@ use crate::{ pub trait ScratchTakeCore where - Self: ScratchTakeBasic + ScratchAvailable, + Self: ScratchTakeBasic + ScratchAvailable, { - fn take_glwe_ct(&mut self, module: &Module, infos: &A) -> (GLWE<&mut [u8]>, &mut Self) + fn take_glwe_ct(&mut self, module: &M, infos: &A) -> (GLWE<&mut [u8]>, &mut Self) where A: GLWEInfos, + M: ModuleN, { + assert_eq!(module.n() as u32, infos.n()); let (data, scratch) = self.take_vec_znx(module, (infos.rank() + 1).into(), infos.size()); ( GLWE { @@ -34,25 +36,28 @@ where ) } - fn take_glwe_ct_slice(&mut self, size: usize, infos: &A) -> (Vec>, &mut Self) + fn take_glwe_ct_slice(&mut self, module: &M, size: usize, infos: &A) -> (Vec>, &mut Self) where A: GLWEInfos, + M: ModuleN, { - let mut scratch: &mut Scratch = self; + let mut scratch: &mut Self = self; let mut cts: Vec> = Vec::with_capacity(size); for _ in 0..size { - let (ct, new_scratch) = scratch.take_glwe_ct(infos); + let (ct, new_scratch) = scratch.take_glwe_ct(module, infos); scratch = new_scratch; cts.push(ct); } (cts, scratch) } - fn take_glwe_pt(&mut self, infos: &A) -> (GLWEPlaintext<&mut [u8]>, &mut Self) + fn take_glwe_pt(&mut self, module: &M, infos: &A) -> (GLWEPlaintext<&mut [u8]>, &mut Self) where A: GLWEInfos, + M: ModuleN, { - let (data, scratch) = self.take_vec_znx(infos.n().into(), 1, infos.size()); + assert_eq!(module.n() as u32, infos.n()); + let (data, scratch) = self.take_vec_znx(module, 1, infos.size()); ( GLWEPlaintext { k: infos.k(), @@ -63,12 +68,14 @@ where ) } - fn take_gglwe(&mut self, infos: &A) -> (GGLWE<&mut [u8]>, &mut Self) + fn take_gglwe(&mut self, module: &M, infos: &A) -> (GGLWE<&mut [u8]>, &mut Self) where A: GGLWEInfos, + M: ModuleN, { + assert_eq!(module.n() as u32, infos.n()); let (data, scratch) = self.take_mat_znx( - infos.n().into(), + module, infos.dnum().0.div_ceil(infos.dsize().0) as usize, infos.rank_in().into(), (infos.rank_out() + 1).into(), @@ -85,12 +92,14 @@ where ) } - fn take_gglwe_prepared(&mut self, infos: &A) -> (GGLWEPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_prepared(&mut self, module: &M, infos: &A) -> (GGLWEPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos, + M: ModuleN + VmpPMatBytesOf, { + assert_eq!(module.n() as u32, infos.n()); let (data, scratch) = self.take_vmp_pmat( - infos.n().into(), + module, infos.dnum().into(), infos.rank_in().into(), (infos.rank_out() + 1).into(), @@ -107,12 +116,14 @@ where ) } - fn take_ggsw(&mut self, infos: &A) -> (GGSW<&mut [u8]>, &mut Self) + fn take_ggsw(&mut self, module: &M, infos: &A) -> (GGSW<&mut [u8]>, &mut Self) where A: GGSWInfos, + M: ModuleN, { + assert_eq!(module.n() as u32, infos.n()); let (data, scratch) = self.take_mat_znx( - infos.n().into(), + module, infos.dnum().into(), (infos.rank() + 1).into(), (infos.rank() + 1).into(), @@ -129,12 +140,14 @@ where ) } - fn take_ggsw_prepared(&mut self, infos: &A) -> (GGSWPrepared<&mut [u8], B>, &mut Self) + fn take_ggsw_prepared(&mut self, module: &M, infos: &A) -> (GGSWPrepared<&mut [u8], B>, &mut Self) where A: GGSWInfos, + M: ModuleN + VmpPMatBytesOf, { + assert_eq!(module.n() as u32, infos.n()); let (data, scratch) = self.take_vmp_pmat( - infos.n().into(), + module, infos.dnum().into(), (infos.rank() + 1).into(), (infos.rank() + 1).into(), @@ -151,25 +164,33 @@ where ) } - fn take_ggsw_prepared_slice(&mut self, size: usize, infos: &A) -> (Vec>, &mut Self) + fn take_ggsw_prepared_slice( + &mut self, + module: &M, + size: usize, + infos: &A, + ) -> (Vec>, &mut Self) where A: GGSWInfos, + M: ModuleN + VmpPMatBytesOf, { - let mut scratch: &mut Scratch = self; + let mut scratch: &mut Self = self; let mut cts: Vec> = Vec::with_capacity(size); for _ in 0..size { - let (ct, new_scratch) = scratch.take_ggsw_prepared(infos); + let (ct, new_scratch) = scratch.take_ggsw_prepared(module, infos); scratch = new_scratch; cts.push(ct) } (cts, scratch) } - fn take_glwe_pk(&mut self, infos: &A) -> (GLWEPublicKey<&mut [u8]>, &mut Self) + fn take_glwe_pk(&mut self, module: &M, infos: &A) -> (GLWEPublicKey<&mut [u8]>, &mut Self) where A: GLWEInfos, + M: ModuleN, { - let (data, scratch) = self.take_vec_znx(infos.n().into(), (infos.rank() + 1).into(), infos.size()); + assert_eq!(module.n() as u32, infos.n()); + let (data, scratch) = self.take_vec_znx(module, (infos.rank() + 1).into(), infos.size()); ( GLWEPublicKey { k: infos.k(), @@ -181,11 +202,13 @@ where ) } - fn take_glwe_pk_prepared(&mut self, infos: &A) -> (GLWEPublicKeyPrepared<&mut [u8], B>, &mut Self) + fn take_glwe_pk_prepared(&mut self, module: &M, infos: &A) -> (GLWEPublicKeyPrepared<&mut [u8], B>, &mut Self) where A: GLWEInfos, + M: ModuleN + VecZnxDftBytesOf, { - let (data, scratch) = self.take_vec_znx_dft(infos.n().into(), (infos.rank() + 1).into(), infos.size()); + assert_eq!(module.n() as u32, infos.n()); + let (data, scratch) = self.take_vec_znx_dft(module, (infos.rank() + 1).into(), infos.size()); ( GLWEPublicKeyPrepared { k: infos.k(), @@ -197,8 +220,11 @@ where ) } - fn take_glwe_secret(&mut self, n: Degree, rank: Rank) -> (GLWESecret<&mut [u8]>, &mut Self) { - let (data, scratch) = self.take_scalar_znx(n.into(), rank.into()); + fn take_glwe_secret(&mut self, module: &M, rank: Rank) -> (GLWESecret<&mut [u8]>, &mut Self) + where + M: ModuleN, + { + let (data, scratch) = self.take_scalar_znx(module, rank.into()); ( GLWESecret { data, @@ -208,8 +234,11 @@ where ) } - fn take_glwe_secret_prepared(&mut self, n: Degree, rank: Rank) -> (GLWESecretPrepared<&mut [u8], B>, &mut Self) { - let (data, scratch) = self.take_svp_ppol(n.into(), rank.into()); + fn take_glwe_secret_prepared(&mut self, module: &M, rank: Rank) -> (GLWESecretPrepared<&mut [u8], B>, &mut Self) + where + M: ModuleN + SvpPPolBytesOf, + { + let (data, scratch) = self.take_svp_ppol(module, rank.into()); ( GLWESecretPrepared { data, @@ -219,11 +248,13 @@ where ) } - fn take_glwe_switching_key(&mut self, infos: &A) -> (GLWESwitchingKey<&mut [u8]>, &mut Self) + fn take_glwe_switching_key(&mut self, module: &M, infos: &A) -> (GLWESwitchingKey<&mut [u8]>, &mut Self) where A: GGLWEInfos, + M: ModuleN, { - let (data, scratch) = self.take_gglwe(infos); + assert_eq!(module.n() as u32, infos.n()); + let (data, scratch) = self.take_gglwe(module, infos); ( GLWESwitchingKey { key: data, @@ -234,11 +265,17 @@ where ) } - fn take_gglwe_switching_key_prepared(&mut self, infos: &A) -> (GLWESwitchingKeyPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_switching_key_prepared( + &mut self, + module: &M, + infos: &A, + ) -> (GLWESwitchingKeyPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos, + M: ModuleN + VmpPMatBytesOf, { - let (data, scratch) = self.take_gglwe_prepared(infos); + assert_eq!(module.n() as u32, infos.n()); + let (data, scratch) = self.take_gglwe_prepared(module, infos); ( GLWESwitchingKeyPrepared { key: data, @@ -249,26 +286,36 @@ where ) } - fn take_gglwe_automorphism_key(&mut self, infos: &A) -> (AutomorphismKey<&mut [u8]>, &mut Self) + fn take_gglwe_automorphism_key(&mut self, module: &M, infos: &A) -> (AutomorphismKey<&mut [u8]>, &mut Self) where A: GGLWEInfos, + M: ModuleN, { - let (data, scratch) = self.take_glwe_switching_key(infos); + assert_eq!(module.n() as u32, infos.n()); + let (data, scratch) = self.take_glwe_switching_key(module, infos); (AutomorphismKey { key: data, p: 0 }, scratch) } - fn take_gglwe_automorphism_key_prepared(&mut self, infos: &A) -> (AutomorphismKeyPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_automorphism_key_prepared( + &mut self, + module: &M, + infos: &A, + ) -> (AutomorphismKeyPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos, + M: ModuleN + VmpPMatBytesOf, { - let (data, scratch) = self.take_gglwe_switching_key_prepared(infos); + assert_eq!(module.n() as u32, infos.n()); + let (data, scratch) = self.take_gglwe_switching_key_prepared(module, infos); (AutomorphismKeyPrepared { key: data, p: 0 }, scratch) } - fn take_tensor_key(&mut self, infos: &A) -> (TensorKey<&mut [u8]>, &mut Self) + fn take_tensor_key(&mut self, module: &M, infos: &A) -> (TensorKey<&mut [u8]>, &mut Self) where A: GGLWEInfos, + M: ModuleN, { + assert_eq!(module.n() as u32, infos.n()); assert_eq!( infos.rank_in(), infos.rank_out(), @@ -277,28 +324,30 @@ where let mut keys: Vec> = Vec::new(); let pairs: usize = (((infos.rank_out().0 + 1) * infos.rank_out().0) >> 1).max(1) as usize; - let mut scratch: &mut Scratch = self; + let mut scratch: &mut Self = self; let mut ksk_infos: crate::layouts::GGLWECiphertextLayout = infos.gglwe_layout(); ksk_infos.rank_in = Rank(1); if pairs != 0 { - let (gglwe, s) = scratch.take_glwe_switching_key(&ksk_infos); + let (gglwe, s) = scratch.take_glwe_switching_key(module, &ksk_infos); scratch = s; keys.push(gglwe); } for _ in 1..pairs { - let (gglwe, s) = scratch.take_glwe_switching_key(&ksk_infos); + let (gglwe, s) = scratch.take_glwe_switching_key(module, &ksk_infos); scratch = s; keys.push(gglwe); } (TensorKey { keys }, scratch) } - fn take_gglwe_tensor_key_prepared(&mut self, infos: &A) -> (TensorKeyPrepared<&mut [u8], B>, &mut Self) + fn take_gglwe_tensor_key_prepared(&mut self, module: &M, infos: &A) -> (TensorKeyPrepared<&mut [u8], B>, &mut Self) where A: GGLWEInfos, + M: ModuleN + VmpPMatBytesOf, { + assert_eq!(module.n() as u32, infos.n()); assert_eq!( infos.rank_in(), infos.rank_out(), @@ -308,18 +357,18 @@ where let mut keys: Vec> = Vec::new(); let pairs: usize = (((infos.rank_out().0 + 1) * infos.rank_out().0) >> 1).max(1) as usize; - let mut scratch: &mut Scratch = self; + let mut scratch: &mut Self = self; let mut ksk_infos: crate::layouts::GGLWECiphertextLayout = infos.gglwe_layout(); ksk_infos.rank_in = Rank(1); if pairs != 0 { - let (gglwe, s) = scratch.take_gglwe_switching_key_prepared(&ksk_infos); + let (gglwe, s) = scratch.take_gglwe_switching_key_prepared(module, &ksk_infos); scratch = s; keys.push(gglwe); } for _ in 1..pairs { - let (gglwe, s) = scratch.take_gglwe_switching_key_prepared(&ksk_infos); + let (gglwe, s) = scratch.take_gglwe_switching_key_prepared(module, &ksk_infos); scratch = s; keys.push(gglwe); } @@ -327,4 +376,4 @@ where } } -impl ScratchTakeCore for Scratch where Self: ScratchTakeBasic + ScratchAvailable {} +impl ScratchTakeCore for Scratch where Self: ScratchTakeBasic + ScratchAvailable {} diff --git a/poulpy-hal/src/api/module.rs b/poulpy-hal/src/api/module.rs index 6e5faed..3dd6176 100644 --- a/poulpy-hal/src/api/module.rs +++ b/poulpy-hal/src/api/module.rs @@ -4,3 +4,7 @@ use crate::layouts::Backend; pub trait ModuleNew { fn new(n: u64) -> Self; } + +pub trait ModuleN { + fn n(&self) -> usize; +} diff --git a/poulpy-hal/src/api/scratch.rs b/poulpy-hal/src/api/scratch.rs index c1bd869..ee4a080 100644 --- a/poulpy-hal/src/api/scratch.rs +++ b/poulpy-hal/src/api/scratch.rs @@ -1,6 +1,6 @@ use crate::{ - api::{SvpPPolBytesOf, VecZnxBigBytesOf, VecZnxDftBytesOf, VmpPMatBytesOf}, - layouts::{Backend, MatZnx, Module, ScalarZnx, Scratch, SvpPPol, VecZnx, VecZnxBig, VecZnxDft, VmpPMat}, + api::{ModuleN, SvpPPolBytesOf, VecZnxBigBytesOf, VecZnxDftBytesOf, VmpPMatBytesOf}, + layouts::{Backend, MatZnx, ScalarZnx, Scratch, SvpPPol, VecZnx, VecZnxBig, VecZnxDft, VmpPMat}, }; /// Allocates a new [crate::layouts::ScratchOwned] of `size` aligned bytes. @@ -28,11 +28,14 @@ pub trait TakeSlice { fn take_slice(&mut self, len: usize) -> (&mut [T], &mut Self); } -pub trait ScratchTakeBasic +pub trait ScratchTakeBasic where Self: TakeSlice, { - fn take_scalar_znx(&mut self, module: &Module, cols: usize) -> (ScalarZnx<&mut [u8]>, &mut Self) { + fn take_scalar_znx(&mut self, module: &M, cols: usize) -> (ScalarZnx<&mut [u8]>, &mut Self) + where + M: ModuleN, + { let (take_slice, rem_slice) = self.take_slice(ScalarZnx::bytes_of(module.n(), cols)); ( ScalarZnx::from_data(take_slice, module.n(), cols), @@ -40,15 +43,18 @@ where ) } - fn take_svp_ppol(&mut self, module: &Module, cols: usize) -> (SvpPPol<&mut [u8], B>, &mut Self) + fn take_svp_ppol(&mut self, module: &M, cols: usize) -> (SvpPPol<&mut [u8], B>, &mut Self) where - Module: SvpPPolBytesOf, + M: SvpPPolBytesOf + ModuleN, { let (take_slice, rem_slice) = self.take_slice(module.bytes_of_svp_ppol(cols)); (SvpPPol::from_data(take_slice, module.n(), cols), rem_slice) } - fn take_vec_znx(&mut self, module: &Module, cols: usize, size: usize) -> (VecZnx<&mut [u8]>, &mut Self) { + fn take_vec_znx(&mut self, module: &M, cols: usize, size: usize) -> (VecZnx<&mut [u8]>, &mut Self) + where + M: ModuleN, + { let (take_slice, rem_slice) = self.take_slice(VecZnx::bytes_of(module.n(), cols, size)); ( VecZnx::from_data(take_slice, module.n(), cols, size), @@ -56,9 +62,9 @@ where ) } - fn take_vec_znx_big(&mut self, module: &Module, cols: usize, size: usize) -> (VecZnxBig<&mut [u8], B>, &mut Self) + fn take_vec_znx_big(&mut self, module: &M, cols: usize, size: usize) -> (VecZnxBig<&mut [u8], B>, &mut Self) where - Module: VecZnxBigBytesOf, + M: VecZnxBigBytesOf + ModuleN, { let (take_slice, rem_slice) = self.take_slice(module.bytes_of_vec_znx_big(cols, size)); ( @@ -67,9 +73,9 @@ where ) } - fn take_vec_znx_dft(&mut self, module: &Module, cols: usize, size: usize) -> (VecZnxDft<&mut [u8], B>, &mut Self) + fn take_vec_znx_dft(&mut self, module: &M, cols: usize, size: usize) -> (VecZnxDft<&mut [u8], B>, &mut Self) where - Module: VecZnxDftBytesOf, + M: VecZnxDftBytesOf + ModuleN, { let (take_slice, rem_slice) = self.take_slice(module.bytes_of_vec_znx_dft(cols, size)); @@ -79,15 +85,15 @@ where ) } - fn take_vec_znx_dft_slice( + fn take_vec_znx_dft_slice( &mut self, - module: &Module, + module: &M, len: usize, cols: usize, size: usize, ) -> (Vec>, &mut Self) where - Module: VecZnxDftBytesOf, + M: VecZnxDftBytesOf + ModuleN, { let mut scratch: &mut Self = self; let mut slice: Vec> = Vec::with_capacity(len); @@ -99,13 +105,10 @@ where (slice, scratch) } - fn take_vec_znx_slice( - &mut self, - module: &Module, - len: usize, - cols: usize, - size: usize, - ) -> (Vec>, &mut Self) { + fn take_vec_znx_slice(&mut self, module: &M, len: usize, cols: usize, size: usize) -> (Vec>, &mut Self) + where + M: ModuleN, + { let mut scratch: &mut Self = self; let mut slice: Vec> = Vec::with_capacity(len); for _ in 0..len { @@ -116,16 +119,16 @@ where (slice, scratch) } - fn take_vmp_pmat( + fn take_vmp_pmat( &mut self, - module: &Module, + module: &M, rows: usize, cols_in: usize, cols_out: usize, size: usize, ) -> (VmpPMat<&mut [u8], B>, &mut Self) where - Module: VmpPMatBytesOf, + M: VmpPMatBytesOf + ModuleN, { let (take_slice, rem_slice) = self.take_slice(module.bytes_of_vmp_pmat(rows, cols_in, cols_out, size)); ( @@ -134,14 +137,17 @@ where ) } - fn take_mat_znx( + fn take_mat_znx( &mut self, - module: &Module, + module: &M, rows: usize, cols_in: usize, cols_out: usize, size: usize, - ) -> (MatZnx<&mut [u8]>, &mut Self) { + ) -> (MatZnx<&mut [u8]>, &mut Self) + where + M: ModuleN, + { let (take_slice, rem_slice) = self.take_slice(MatZnx::bytes_of(module.n(), rows, cols_in, cols_out, size)); ( MatZnx::from_data(take_slice, module.n(), rows, cols_in, cols_out, size), diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs index 938c45e..ba0d38f 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/bdd_2w_to_1w.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use poulpy_core::layouts::prepared::GGSWCiphertextPreparedToRef; +use poulpy_core::layouts::prepared::GGSWPreparedToRef; use poulpy_hal::layouts::{Backend, DataMut, DataRef, Module, Scratch}; use crate::tfhe::bdd_arithmetic::{ @@ -60,15 +60,11 @@ pub fn eval_bdd_2w_to_1w> = a + let inputs: Vec<&dyn GGSWPreparedToRef> = a .blocks .iter() - .map(|x| x as &dyn GGSWCiphertextPreparedToRef) - .chain( - b.blocks - .iter() - .map(|x| x as &dyn GGSWCiphertextPreparedToRef), - ) + .map(|x| x as &dyn GGSWPreparedToRef) + .chain(b.blocks.iter().map(|x| x as &dyn GGSWPreparedToRef)) .collect_vec(); // Evaluates out[i] = circuit[i](a, b) diff --git a/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs b/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs index 7706237..245fe03 100644 --- a/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs +++ b/poulpy-schemes/src/tfhe/bdd_arithmetic/eval.rs @@ -3,7 +3,7 @@ use poulpy_core::{ GLWEExternalProductInplace, GLWEOperations, TakeGLWESlice, layouts::{ GLWE, GLWEToMut, LWEInfos, - prepared::{GGSWCiphertextPreparedToRef, GGSWPrepared}, + prepared::{GGSWPrepared, GGSWPreparedToRef}, }, }; use poulpy_hal::{ @@ -39,7 +39,7 @@ where &self, module: &Module, out: &mut [GLWE], - inputs: &[&dyn GGSWCiphertextPreparedToRef], + inputs: &[&dyn GGSWPreparedToRef], scratch: &mut Scratch, ) where O: DataMut; @@ -55,7 +55,7 @@ where &self, module: &Module, out: &mut [GLWE], - inputs: &[&dyn GGSWCiphertextPreparedToRef], + inputs: &[&dyn GGSWPreparedToRef], scratch: &mut Scratch, ) where O: DataMut,