use crate::hal::{ api::{ ScratchAvailable, ScratchFromBytes, ScratchOwnedAlloc, ScratchOwnedBorrow, TakeLike, TakeMatZnx, TakeScalarZnx, TakeSlice, TakeSvpPPol, TakeVecZnx, TakeVecZnxBig, TakeVecZnxDft, TakeVecZnxDftSlice, TakeVecZnxSlice, TakeVmpPMat, }, layouts::{Backend, DataRef, MatZnx, ScalarZnx, Scratch, ScratchOwned, SvpPPol, VecZnx, VecZnxBig, VecZnxDft, VmpPMat}, oep::{ ScratchAvailableImpl, ScratchFromBytesImpl, ScratchOwnedAllocImpl, ScratchOwnedBorrowImpl, TakeLikeImpl, TakeMatZnxImpl, TakeScalarZnxImpl, TakeSliceImpl, TakeSvpPPolImpl, TakeVecZnxBigImpl, TakeVecZnxDftImpl, TakeVecZnxDftSliceImpl, TakeVecZnxImpl, TakeVecZnxSliceImpl, TakeVmpPMatImpl, }, }; impl ScratchOwnedAlloc for ScratchOwned where B: Backend + ScratchOwnedAllocImpl, { fn alloc(size: usize) -> Self { B::scratch_owned_alloc_impl(size) } } impl ScratchOwnedBorrow for ScratchOwned where B: Backend + ScratchOwnedBorrowImpl, { fn borrow(&mut self) -> &mut Scratch { B::scratch_owned_borrow_impl(self) } } impl ScratchFromBytes for Scratch where B: Backend + ScratchFromBytesImpl, { fn from_bytes(data: &mut [u8]) -> &mut Scratch { B::scratch_from_bytes_impl(data) } } impl ScratchAvailable for Scratch where B: Backend + ScratchAvailableImpl, { fn available(&self) -> usize { B::scratch_available_impl(self) } } impl TakeSlice for Scratch where B: Backend + TakeSliceImpl, { fn take_slice(&mut self, len: usize) -> (&mut [T], &mut Self) { B::take_slice_impl(self, len) } } impl TakeScalarZnx for Scratch where B: Backend + TakeScalarZnxImpl, { fn take_scalar_znx(&mut self, n: usize, cols: usize) -> (ScalarZnx<&mut [u8]>, &mut Self) { B::take_scalar_znx_impl(self, n, cols) } } impl TakeSvpPPol for Scratch where B: Backend + TakeSvpPPolImpl, { fn take_svp_ppol(&mut self, n: usize, cols: usize) -> (SvpPPol<&mut [u8], B>, &mut Self) { B::take_svp_ppol_impl(self, n, cols) } } impl TakeVecZnx for Scratch where B: Backend + TakeVecZnxImpl, { fn take_vec_znx(&mut self, n: usize, cols: usize, size: usize) -> (VecZnx<&mut [u8]>, &mut Self) { B::take_vec_znx_impl(self, n, cols, size) } } impl TakeVecZnxSlice for Scratch where B: Backend + TakeVecZnxSliceImpl, { fn take_vec_znx_slice(&mut self, len: usize, n: usize, cols: usize, size: usize) -> (Vec>, &mut Self) { B::take_vec_znx_slice_impl(self, len, n, cols, size) } } impl TakeVecZnxBig for Scratch where B: Backend + TakeVecZnxBigImpl, { fn take_vec_znx_big(&mut self, n: usize, cols: usize, size: usize) -> (VecZnxBig<&mut [u8], B>, &mut Self) { B::take_vec_znx_big_impl(self, n, cols, size) } } impl TakeVecZnxDft for Scratch where B: Backend + TakeVecZnxDftImpl, { fn take_vec_znx_dft(&mut self, n: usize, cols: usize, size: usize) -> (VecZnxDft<&mut [u8], B>, &mut Self) { B::take_vec_znx_dft_impl(self, n, cols, size) } } impl TakeVecZnxDftSlice for Scratch where B: Backend + TakeVecZnxDftSliceImpl, { fn take_vec_znx_dft_slice( &mut self, len: usize, n: usize, cols: usize, size: usize, ) -> (Vec>, &mut Self) { B::take_vec_znx_dft_slice_impl(self, len, n, cols, size) } } impl TakeVmpPMat for Scratch where B: Backend + TakeVmpPMatImpl, { fn take_vmp_pmat( &mut self, n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize, ) -> (VmpPMat<&mut [u8], B>, &mut Self) { B::take_vmp_pmat_impl(self, n, rows, cols_in, cols_out, size) } } impl TakeMatZnx for Scratch where B: Backend + TakeMatZnxImpl, { fn take_mat_znx( &mut self, n: usize, rows: usize, cols_in: usize, cols_out: usize, size: usize, ) -> (MatZnx<&mut [u8]>, &mut Self) { B::take_mat_znx_impl(self, n, rows, cols_in, cols_out, size) } } impl<'a, B: Backend, D> TakeLike<'a, B, ScalarZnx> for Scratch where B: TakeLikeImpl<'a, B, ScalarZnx, Output = ScalarZnx<&'a mut [u8]>>, D: DataRef, { type Output = ScalarZnx<&'a mut [u8]>; fn take_like(&'a mut self, template: &ScalarZnx) -> (Self::Output, &'a mut Self) { B::take_like_impl(self, template) } } impl<'a, B: Backend, D> TakeLike<'a, B, SvpPPol> for Scratch where B: TakeLikeImpl<'a, B, SvpPPol, Output = SvpPPol<&'a mut [u8], B>>, D: DataRef, { type Output = SvpPPol<&'a mut [u8], B>; fn take_like(&'a mut self, template: &SvpPPol) -> (Self::Output, &'a mut Self) { B::take_like_impl(self, template) } } impl<'a, B: Backend, D> TakeLike<'a, B, VecZnx> for Scratch where B: TakeLikeImpl<'a, B, VecZnx, Output = VecZnx<&'a mut [u8]>>, D: DataRef, { type Output = VecZnx<&'a mut [u8]>; fn take_like(&'a mut self, template: &VecZnx) -> (Self::Output, &'a mut Self) { B::take_like_impl(self, template) } } impl<'a, B: Backend, D> TakeLike<'a, B, VecZnxBig> for Scratch where B: TakeLikeImpl<'a, B, VecZnxBig, Output = VecZnxBig<&'a mut [u8], B>>, D: DataRef, { type Output = VecZnxBig<&'a mut [u8], B>; fn take_like(&'a mut self, template: &VecZnxBig) -> (Self::Output, &'a mut Self) { B::take_like_impl(self, template) } } impl<'a, B: Backend, D> TakeLike<'a, B, VecZnxDft> for Scratch where B: TakeLikeImpl<'a, B, VecZnxDft, Output = VecZnxDft<&'a mut [u8], B>>, D: DataRef, { type Output = VecZnxDft<&'a mut [u8], B>; fn take_like(&'a mut self, template: &VecZnxDft) -> (Self::Output, &'a mut Self) { B::take_like_impl(self, template) } } impl<'a, B: Backend, D> TakeLike<'a, B, MatZnx> for Scratch where B: TakeLikeImpl<'a, B, MatZnx, Output = MatZnx<&'a mut [u8]>>, D: DataRef, { type Output = MatZnx<&'a mut [u8]>; fn take_like(&'a mut self, template: &MatZnx) -> (Self::Output, &'a mut Self) { B::take_like_impl(self, template) } } impl<'a, B: Backend, D> TakeLike<'a, B, VmpPMat> for Scratch where B: TakeLikeImpl<'a, B, VmpPMat, Output = VmpPMat<&'a mut [u8], B>>, D: DataRef, { type Output = VmpPMat<&'a mut [u8], B>; fn take_like(&'a mut self, template: &VmpPMat) -> (Self::Output, &'a mut Self) { B::take_like_impl(self, template) } }