1use anyhow::Result;
2use poulpy_core::{
3 GLWEAdd, GLWECopy, GLWEMulConst, GLWEMulPlain, GLWERotate, GLWETensoring,
4 layouts::{GGLWEInfos, GLWEToBackendMut, GLWEToBackendRef, ModuleCoreAlloc, prepared::GLWETensorKeyPreparedToBackendRef},
5};
6use poulpy_hal::{
7 api::{ModuleN, VecZnxCopyBackend},
8 layouts::{Backend, Module, ScratchArena},
9};
10
11use crate::api::CKKSMulOps;
12
13use crate::{CKKSCtBounds, CKKSInfos, SetCKKSInfos, oep::CKKSMulImpl};
14
15impl<BE: Backend + CKKSMulImpl<BE>> CKKSMulOps<BE> for Module<BE>
16where
17 Module<BE>: GLWEAdd<BE>
18 + GLWECopy<BE>
19 + GLWEMulConst<BE>
20 + GLWEMulPlain<BE>
21 + GLWERotate<BE>
22 + GLWETensoring<BE>
23 + ModuleN
24 + ModuleCoreAlloc<OwnedBuf = BE::OwnedBuf>
25 + VecZnxCopyBackend<BE>,
26{
27 fn ckks_mul_tmp_bytes<R, T>(&self, res: &R, tsk: &T) -> usize
28 where
29 R: CKKSCtBounds,
30 T: GGLWEInfos,
31 {
32 BE::ckks_mul_tmp_bytes(self, res, tsk)
33 }
34
35 fn ckks_square_tmp_bytes<R, T>(&self, res: &R, tsk: &T) -> usize
36 where
37 R: CKKSCtBounds,
38 T: GGLWEInfos,
39 {
40 BE::ckks_square_tmp_bytes(self, res, tsk)
41 }
42
43 fn ckks_mul_pt_vec_tmp_bytes<R, A, P>(&self, res: &R, a: &A, b: &P) -> usize
44 where
45 R: CKKSCtBounds,
46 A: CKKSCtBounds,
47 P: CKKSInfos,
48 {
49 let b = b.meta();
50 BE::ckks_mul_pt_vec_tmp_bytes(self, res, a, &b)
51 }
52
53 fn ckks_mul_pt_const_tmp_bytes<R, A, P>(&self, res: &R, a: &A, b: &P) -> usize
54 where
55 R: CKKSCtBounds,
56 A: CKKSCtBounds,
57 P: CKKSInfos,
58 {
59 let b = b.meta();
60 BE::ckks_mul_pt_const_tmp_bytes(self, res, a, &b)
61 }
62
63 fn ckks_mul_into<Dst, A, B, T>(&self, dst: &mut Dst, a: &A, b: &B, tsk: &T, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
64 where
65 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
66 A: GLWEToBackendRef<BE> + CKKSCtBounds,
67 B: GLWEToBackendRef<BE> + CKKSCtBounds,
68 T: GGLWEInfos + GLWETensorKeyPreparedToBackendRef<BE>,
69 {
70 BE::ckks_mul_into(self, dst, a, b, tsk, scratch)
71 }
72
73 fn ckks_mul_assign<Dst, A, T>(&self, dst: &mut Dst, a: &A, tsk: &T, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
74 where
75 Dst: GLWEToBackendMut<BE> + GLWEToBackendRef<BE> + CKKSCtBounds + SetCKKSInfos,
76 A: GLWEToBackendRef<BE> + CKKSCtBounds,
77 T: GGLWEInfos + GLWETensorKeyPreparedToBackendRef<BE>,
78 {
79 BE::ckks_mul_assign(self, dst, a, tsk, scratch)
80 }
81
82 fn ckks_square_into<Dst, A, T>(&self, dst: &mut Dst, a: &A, tsk: &T, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
83 where
84 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
85 A: GLWEToBackendRef<BE> + CKKSCtBounds,
86 T: GGLWEInfos + GLWETensorKeyPreparedToBackendRef<BE>,
87 {
88 BE::ckks_square_into(self, dst, a, tsk, scratch)
89 }
90
91 fn ckks_square_assign<Dst, T>(&self, dst: &mut Dst, tsk: &T, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
92 where
93 Dst: GLWEToBackendMut<BE> + GLWEToBackendRef<BE> + CKKSCtBounds + SetCKKSInfos,
94 T: GGLWEInfos + GLWETensorKeyPreparedToBackendRef<BE>,
95 {
96 BE::ckks_square_assign(self, dst, tsk, scratch)
97 }
98
99 fn ckks_mul_pt_vec_into<Dst, A, P>(&self, dst: &mut Dst, a: &A, pt: &P, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
100 where
101 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
102 A: GLWEToBackendRef<BE> + CKKSCtBounds,
103 P: GLWEToBackendRef<BE> + CKKSCtBounds,
104 {
105 BE::ckks_mul_pt_vec_into(self, dst, a, pt, scratch)
106 }
107
108 fn ckks_mul_pt_vec_assign<Dst, P>(&self, dst: &mut Dst, pt: &P, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
109 where
110 Dst: GLWEToBackendMut<BE> + GLWEToBackendRef<BE> + CKKSCtBounds + SetCKKSInfos,
111 P: GLWEToBackendRef<BE> + CKKSCtBounds,
112 {
113 BE::ckks_mul_pt_vec_assign(self, dst, pt, scratch)
114 }
115
116 fn ckks_mul_pt_const_into<Dst, A, P>(
117 &self,
118 dst: &mut Dst,
119 a: &A,
120 pt: &P,
121 pt_coeff: usize,
122 scratch: &mut ScratchArena<'_, BE>,
123 ) -> Result<()>
124 where
125 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
126 A: GLWEToBackendRef<BE> + CKKSCtBounds,
127 P: GLWEToBackendRef<BE> + CKKSCtBounds,
128 {
129 BE::ckks_mul_pt_const_into(self, dst, a, pt, pt_coeff, scratch)
130 }
131
132 fn ckks_mul_pt_const_assign<Dst, P>(
133 &self,
134 dst: &mut Dst,
135 pt: &P,
136 pt_coeff: usize,
137 scratch: &mut ScratchArena<'_, BE>,
138 ) -> Result<()>
139 where
140 Dst: GLWEToBackendMut<BE> + GLWEToBackendRef<BE> + CKKSCtBounds + SetCKKSInfos,
141 P: GLWEToBackendRef<BE> + CKKSCtBounds,
142 {
143 BE::ckks_mul_pt_const_assign(self, dst, pt, pt_coeff, scratch)
144 }
145}