poulpy/base2k/src/scalar_znx_dft.rs
base2k/src/scalar_znx_dft.rsRaw
1use std::marker::PhantomData;
2
3use crate::ffi::svp;
4use crate::znx_base::{ZnxAlloc, ZnxBase, ZnxInfos, ZnxLayout, ZnxSliceSize};
5use crate::{Backend, FFT64, GetZnxBase, Module};
6
7pub const SCALAR_ZNX_DFT_ROWS: usize = 1;
8pub const SCALAR_ZNX_DFT_SIZE: usize = 1;
9
10pub struct ScalarZnxDft<B: Backend> {
11 pub inner: ZnxBase,
12 _marker: PhantomData<B>,
13}
14
15impl<B: Backend> GetZnxBase for ScalarZnxDft<B> {
16 fn znx(&self) -> &ZnxBase {
17 &self.inner
18 }
19
20 fn znx_mut(&mut self) -> &mut ZnxBase {
21 &mut self.inner
22 }
23}
24
25impl<B: Backend> ZnxInfos for ScalarZnxDft<B> {}
26
27impl<B: Backend> ZnxAlloc<B> for ScalarZnxDft<B> {
28 type Scalar = u8;
29
30 fn from_bytes_borrow(module: &Module<B>, _rows: usize, cols: usize, _size: usize, bytes: &mut [u8]) -> Self {
31 debug_assert_eq!(bytes.len(), Self::bytes_of(module, _rows, cols, _size));
32 Self {
33 inner: ZnxBase::from_bytes_borrow(
34 module.n(),
35 SCALAR_ZNX_DFT_ROWS,
36 cols,
37 SCALAR_ZNX_DFT_SIZE,
38 bytes,
39 ),
40 _marker: PhantomData,
41 }
42 }
43
44 fn bytes_of(module: &Module<B>, _rows: usize, cols: usize, _size: usize) -> usize {
45 debug_assert_eq!(
46 _rows, SCALAR_ZNX_DFT_ROWS,
47 "rows != {} not supported for ScalarZnxDft",
48 SCALAR_ZNX_DFT_ROWS
49 );
50 debug_assert_eq!(
51 _size, SCALAR_ZNX_DFT_SIZE,
52 "rows != {} not supported for ScalarZnxDft",
53 SCALAR_ZNX_DFT_SIZE
54 );
55 unsafe { svp::bytes_of_svp_ppol(module.ptr) as usize * cols }
56 }
57}
58
59impl ZnxLayout for ScalarZnxDft<FFT64> {
60 type Scalar = f64;
61}
62
63impl ZnxSliceSize for ScalarZnxDft<FFT64> {
64 fn sl(&self) -> usize {
65 self.n() * self.cols()
66 }
67}