poulpy_hal/delegates/
scratch.rs

1use crate::{
2    api::{
3        ScratchAvailable, ScratchFromBytes, ScratchOwnedAlloc, ScratchOwnedBorrow, TakeMatZnx, TakeScalarZnx, TakeSlice,
4        TakeSvpPPol, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, TakeVecZnxDftSlice, TakeVecZnxSlice, TakeVmpPMat,
5    },
6    layouts::{Backend, MatZnx, ScalarZnx, Scratch, ScratchOwned, SvpPPol, VecZnx, VecZnxBig, VecZnxDft, VmpPMat},
7    oep::{
8        ScratchAvailableImpl, ScratchFromBytesImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeMatZnxImpl,
9        TakeScalarZnxImpl, TakeSliceImpl, TakeSvpPPolImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxDftSliceImpl,
10        TakeVecZnxImpl, TakeVecZnxSliceImpl, TakeVmpPMatImpl,
11    },
12};
13
14impl<B> ScratchOwnedAlloc<B> for ScratchOwned<B>
15where
16    B: Backend + ScratchOwnedAllocImpl<B>,
17{
18    fn alloc(size: usize) -> Self {
19        B::scratch_owned_alloc_impl(size)
20    }
21}
22
23impl<B> ScratchOwnedBorrow<B> for ScratchOwned<B>
24where
25    B: Backend + ScratchOwnedBorrowImpl<B>,
26{
27    fn borrow(&mut self) -> &mut Scratch<B> {
28        B::scratch_owned_borrow_impl(self)
29    }
30}
31
32impl<B> ScratchFromBytes<B> for Scratch<B>
33where
34    B: Backend + ScratchFromBytesImpl<B>,
35{
36    fn from_bytes(data: &mut [u8]) -> &mut Scratch<B> {
37        B::scratch_from_bytes_impl(data)
38    }
39}
40
41impl<B> ScratchAvailable for Scratch<B>
42where
43    B: Backend + ScratchAvailableImpl<B>,
44{
45    fn available(&self) -> usize {
46        B::scratch_available_impl(self)
47    }
48}
49
50impl<B> TakeSlice for Scratch<B>
51where
52    B: Backend + TakeSliceImpl<B>,
53{
54    fn take_slice<T>(&mut self, len: usize) -> (&mut [T], &mut Self) {
55        B::take_slice_impl(self, len)
56    }
57}
58
59impl<B> TakeScalarZnx for Scratch<B>
60where
61    B: Backend + TakeScalarZnxImpl<B>,
62{
63    fn take_scalar_znx(&mut self, n: usize, cols: usize) -> (ScalarZnx<&mut [u8]>, &mut Self) {
64        B::take_scalar_znx_impl(self, n, cols)
65    }
66}
67
68impl<B> TakeSvpPPol<B> for Scratch<B>
69where
70    B: Backend + TakeSvpPPolImpl<B>,
71{
72    fn take_svp_ppol(&mut self, n: usize, cols: usize) -> (SvpPPol<&mut [u8], B>, &mut Self) {
73        B::take_svp_ppol_impl(self, n, cols)
74    }
75}
76
77impl<B> TakeVecZnx for Scratch<B>
78where
79    B: Backend + TakeVecZnxImpl<B>,
80{
81    fn take_vec_znx(&mut self, n: usize, cols: usize, size: usize) -> (VecZnx<&mut [u8]>, &mut Self) {
82        B::take_vec_znx_impl(self, n, cols, size)
83    }
84}
85
86impl<B> TakeVecZnxSlice for Scratch<B>
87where
88    B: Backend + TakeVecZnxSliceImpl<B>,
89{
90    fn take_vec_znx_slice(&mut self, len: usize, n: usize, cols: usize, size: usize) -> (Vec<VecZnx<&mut [u8]>>, &mut Self) {
91        B::take_vec_znx_slice_impl(self, len, n, cols, size)
92    }
93}
94
95impl<B> TakeVecZnxBig<B> for Scratch<B>
96where
97    B: Backend + TakeVecZnxBigImpl<B>,
98{
99    fn take_vec_znx_big(&mut self, n: usize, cols: usize, size: usize) -> (VecZnxBig<&mut [u8], B>, &mut Self) {
100        B::take_vec_znx_big_impl(self, n, cols, size)
101    }
102}
103
104impl<B> TakeVecZnxDft<B> for Scratch<B>
105where
106    B: Backend + TakeVecZnxDftImpl<B>,
107{
108    fn take_vec_znx_dft(&mut self, n: usize, cols: usize, size: usize) -> (VecZnxDft<&mut [u8], B>, &mut Self) {
109        B::take_vec_znx_dft_impl(self, n, cols, size)
110    }
111}
112
113impl<B> TakeVecZnxDftSlice<B> for Scratch<B>
114where
115    B: Backend + TakeVecZnxDftSliceImpl<B>,
116{
117    fn take_vec_znx_dft_slice(
118        &mut self,
119        len: usize,
120        n: usize,
121        cols: usize,
122        size: usize,
123    ) -> (Vec<VecZnxDft<&mut [u8], B>>, &mut Self) {
124        B::take_vec_znx_dft_slice_impl(self, len, n, cols, size)
125    }
126}
127
128impl<B> TakeVmpPMat<B> for Scratch<B>
129where
130    B: Backend + TakeVmpPMatImpl<B>,
131{
132    fn take_vmp_pmat(
133        &mut self,
134        n: usize,
135        rows: usize,
136        cols_in: usize,
137        cols_out: usize,
138        size: usize,
139    ) -> (VmpPMat<&mut [u8], B>, &mut Self) {
140        B::take_vmp_pmat_impl(self, n, rows, cols_in, cols_out, size)
141    }
142}
143
144impl<B> TakeMatZnx for Scratch<B>
145where
146    B: Backend + TakeMatZnxImpl<B>,
147{
148    fn take_mat_znx(
149        &mut self,
150        n: usize,
151        rows: usize,
152        cols_in: usize,
153        cols_out: usize,
154        size: usize,
155    ) -> (MatZnx<&mut [u8]>, &mut Self) {
156        B::take_mat_znx_impl(self, n, rows, cols_in, cols_out, size)
157    }
158}