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