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