use poulpy_backend::hal::{ api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPrepare}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat}, }; use crate::layouts::{ GGLWEAutomorphismKey, Infos, prepared::{GGLWESwitchingKeyPrepared, Prepare, PrepareAlloc}, }; #[derive(PartialEq, Eq)] pub struct GGLWEAutomorphismKeyPrepared { pub(crate) key: GGLWESwitchingKeyPrepared, pub(crate) p: i64, } impl GGLWEAutomorphismKeyPrepared, B> { pub fn alloc(module: &Module, n: usize, basek: usize, k: usize, rows: usize, digits: usize, rank: usize) -> Self where Module: VmpPMatAlloc, { GGLWEAutomorphismKeyPrepared::, B> { key: GGLWESwitchingKeyPrepared::alloc(module, n, basek, k, rows, digits, rank, rank), p: 0, } } pub fn bytes_of(module: &Module, n: usize, basek: usize, k: usize, rows: usize, digits: usize, rank: usize) -> usize where Module: VmpPMatAllocBytes, { GGLWESwitchingKeyPrepared::bytes_of(module, n, basek, k, rows, digits, rank, rank) } } impl Infos for GGLWEAutomorphismKeyPrepared { type Inner = VmpPMat; fn inner(&self) -> &Self::Inner { self.key.inner() } fn basek(&self) -> usize { self.key.basek() } fn k(&self) -> usize { self.key.k() } } impl GGLWEAutomorphismKeyPrepared { pub fn p(&self) -> i64 { self.p } pub fn digits(&self) -> usize { self.key.digits() } pub fn rank(&self) -> usize { self.key.rank() } pub fn rank_in(&self) -> usize { self.key.rank_in() } pub fn rank_out(&self) -> usize { self.key.rank_out() } } impl Prepare> for GGLWEAutomorphismKeyPrepared where Module: VmpPrepare, { fn prepare(&mut self, module: &Module, other: &GGLWEAutomorphismKey, scratch: &mut Scratch) { self.key.prepare(module, &other.key, scratch); self.p = other.p; } } impl PrepareAlloc, B>> for GGLWEAutomorphismKey where Module: VmpPMatAlloc + VmpPrepare, { fn prepare_alloc(&self, module: &Module, scratch: &mut Scratch) -> GGLWEAutomorphismKeyPrepared, B> { let mut atk_prepared: GGLWEAutomorphismKeyPrepared, B> = GGLWEAutomorphismKeyPrepared::alloc( module, self.n(), self.basek(), self.k(), self.rows(), self.digits(), self.rank(), ); atk_prepared.prepare(module, self, scratch); atk_prepared } }