arnaucube
arnaucube/poulpyPublic Self-hosted repository
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        Self {
32            inner: ZnxBase::from_bytes_borrow(
33                module.n(),
34                SCALAR_ZNX_DFT_ROWS,
35                cols,
36                SCALAR_ZNX_DFT_SIZE,
37                bytes,
38            ),
39            _marker: PhantomData,
40        }
41    }
42
43    fn bytes_of(module: &Module<B>, _rows: usize, cols: usize, _size: usize) -> usize {
44        debug_assert_eq!(
45            _rows, SCALAR_ZNX_DFT_ROWS,
46            "rows != {} not supported for ScalarZnxDft",
47            SCALAR_ZNX_DFT_ROWS
48        );
49        debug_assert_eq!(
50            _size, SCALAR_ZNX_DFT_SIZE,
51            "rows != {} not supported for ScalarZnxDft",
52            SCALAR_ZNX_DFT_SIZE
53        );
54        unsafe { svp::bytes_of_svp_ppol(module.ptr) as usize * cols }
55    }
56}
57
58impl ZnxLayout for ScalarZnxDft<FFT64> {
59    type Scalar = f64;
60}
61
62impl ZnxSliceSize for ScalarZnxDft<FFT64> {
63    fn sl(&self) -> usize {
64        self.n()
65    }
66}