use backend::hal::{ api::{VmpPMatAlloc, VmpPMatAllocBytes, VmpPMatPrepare}, layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, VmpPMat}, }; use crate::layouts::{Infos, LWESwitchingKey, prepared::GGLWESwitchingKeyExec}; #[derive(PartialEq, Eq)] pub struct LWESwitchingKeyExec(pub(crate) GGLWESwitchingKeyExec); impl Infos for LWESwitchingKeyExec { 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 LWESwitchingKeyExec { 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 LWESwitchingKeyExec, B> { pub fn alloc(module: &Module, n: usize, basek: usize, k: usize, rows: usize) -> Self where Module: VmpPMatAlloc, { Self(GGLWESwitchingKeyExec::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, { GGLWESwitchingKeyExec::, B>::bytes_of(module, n, basek, k, rows, digits, 1, 1) } pub fn from(module: &Module, other: &LWESwitchingKey, scratch: &mut Scratch) -> Self where Module: VmpPMatAlloc + VmpPMatPrepare, { let mut ksk_exec: LWESwitchingKeyExec, B> = Self::alloc( module, other.0.n(), other.0.basek(), other.0.k(), other.0.rows(), ); ksk_exec.prepare(module, other, scratch); ksk_exec } } impl LWESwitchingKeyExec { pub fn prepare(&mut self, module: &Module, other: &LWESwitchingKey, scratch: &mut Scratch) where DataOther: DataRef, Module: VmpPMatPrepare, { self.0.prepare(module, &other.0, scratch); } }