Skip to main content

poulpy_hal/api/
module.rs

1use crate::layouts::{Backend, MatZnx, ScalarZnx, VecZnx};
2
3/// Instantiate a new [crate::layouts::Module].
4pub trait ModuleNew<B: Backend> {
5    fn new(n: u64) -> Self;
6}
7
8/// Query the ring degree `N` of a [`Module`](crate::layouts::Module).
9pub trait ModuleN {
10    fn n(&self) -> usize;
11}
12
13/// Query `log2(N)` with a default implementation derived from [`ModuleN::n`].
14pub trait ModuleLogN
15where
16    Self: ModuleN,
17{
18    fn log_n(&self) -> usize {
19        (u64::BITS - (self.n() as u64 - 1).leading_zeros()) as usize
20    }
21}
22
23/// Allocates backend-owned [`ScalarZnx`](crate::layouts::ScalarZnx) layouts.
24pub trait ScalarZnxAlloc<B: Backend>: ModuleN {
25    fn scalar_znx_alloc(&self, cols: usize) -> ScalarZnx<B::OwnedBuf>;
26}
27
28/// Allocates backend-owned [`VecZnx`](crate::layouts::VecZnx) layouts.
29pub trait VecZnxAlloc<B: Backend>: ModuleN {
30    fn vec_znx_alloc(&self, cols: usize, size: usize) -> VecZnx<B::OwnedBuf>;
31    fn vec_znx_alloc_with_max_size(&self, cols: usize, size: usize, max_size: usize) -> VecZnx<B::OwnedBuf>;
32}
33
34/// Allocates backend-owned [`MatZnx`](crate::layouts::MatZnx) layouts.
35pub trait MatZnxAlloc<B: Backend>: ModuleN {
36    fn mat_znx_alloc(&self, rows: usize, cols_in: usize, cols_out: usize, size: usize) -> MatZnx<B::OwnedBuf>;
37}