1use anyhow::Result;
2use poulpy_core::layouts::{GLWEToBackendMut, GLWEToBackendRef};
3use poulpy_hal::layouts::{Backend, Data, Module, ScratchArena};
4
5use crate::layouts::UnnormalizedCKKSCiphertext;
6use crate::leveled::api::{CKKSSubOps, CKKSSubOpsUnnormalized};
7
8use crate::{CKKSCtBounds, CKKSInfos, SetCKKSInfos, oep::CKKSSubImpl};
9
10impl<BE: Backend + CKKSSubImpl<BE>> CKKSSubOps<BE> for Module<BE> {
11 fn ckks_sub_tmp_bytes(&self) -> usize {
12 BE::ckks_sub_tmp_bytes(self)
13 }
14
15 fn ckks_sub_pt_vec_tmp_bytes(&self) -> usize {
16 BE::ckks_sub_pt_vec_tmp_bytes(self)
17 }
18
19 fn ckks_sub_into<Dst, A, B>(&self, dst: &mut Dst, a: &A, b: &B, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
20 where
21 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
22 A: GLWEToBackendRef<BE> + CKKSCtBounds,
23 B: GLWEToBackendRef<BE> + CKKSCtBounds,
24 {
25 BE::ckks_sub_into(self, dst, a, b, scratch)
26 }
27
28 fn ckks_sub_assign<Dst, A>(&self, dst: &mut Dst, a: &A, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
29 where
30 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
31 A: GLWEToBackendRef<BE> + CKKSCtBounds,
32 {
33 BE::ckks_sub_assign(self, dst, a, scratch)
34 }
35
36 fn ckks_sub_one_assign<Dst>(&self, dst: &mut Dst, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
37 where
38 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
39 {
40 BE::ckks_sub_one_assign(self, dst, scratch)
41 }
42
43 fn ckks_sub_pt_vec_into<Dst, A, P>(&self, dst: &mut Dst, a: &A, pt: &P, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
44 where
45 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
46 A: GLWEToBackendRef<BE> + CKKSCtBounds,
47 P: GLWEToBackendRef<BE> + CKKSCtBounds,
48 {
49 BE::ckks_sub_pt_vec_into(self, dst, a, pt, scratch)
50 }
51
52 fn ckks_sub_pt_vec_assign<Dst, P>(&self, dst: &mut Dst, pt: &P, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
53 where
54 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
55 P: GLWEToBackendRef<BE> + CKKSCtBounds,
56 {
57 BE::ckks_sub_pt_vec_assign(self, dst, pt, scratch)
58 }
59
60 fn ckks_sub_pt_const_tmp_bytes(&self) -> usize {
61 BE::ckks_sub_pt_const_tmp_bytes(self)
62 }
63
64 fn ckks_sub_pt_const_into<Dst, A, P>(
65 &self,
66 dst: &mut Dst,
67 a: &A,
68 dst_coeff: usize,
69 pt: &P,
70 pt_coeff: usize,
71 scratch: &mut ScratchArena<'_, BE>,
72 ) -> Result<()>
73 where
74 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
75 A: GLWEToBackendRef<BE> + CKKSCtBounds,
76 P: GLWEToBackendRef<BE> + CKKSCtBounds,
77 {
78 BE::ckks_sub_pt_const_into(self, dst, a, dst_coeff, pt, pt_coeff, scratch)
79 }
80
81 fn ckks_sub_pt_const_assign<Dst, P>(
82 &self,
83 dst: &mut Dst,
84 dst_coeff: usize,
85 pt: &P,
86 pt_coeff: usize,
87 scratch: &mut ScratchArena<'_, BE>,
88 ) -> Result<()>
89 where
90 Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
91 P: GLWEToBackendRef<BE> + CKKSCtBounds,
92 {
93 BE::ckks_sub_pt_const_assign(self, dst, dst_coeff, pt, pt_coeff, scratch)
94 }
95}
96
97impl<BE: Backend + CKKSSubImpl<BE>> CKKSSubOpsUnnormalized<BE> for Module<BE> {
98 fn ckks_sub_into_unnormalized<Dst, A, B>(
99 &self,
100 dst: &mut UnnormalizedCKKSCiphertext<Dst>,
101 a: &A,
102 b: &B,
103 scratch: &mut ScratchArena<'_, BE>,
104 ) -> Result<()>
105 where
106 Dst: Data,
107 UnnormalizedCKKSCiphertext<Dst>: GLWEToBackendMut<BE>,
108 A: GLWEToBackendRef<BE> + CKKSCtBounds,
109 B: GLWEToBackendRef<BE> + CKKSCtBounds,
110 {
111 BE::ckks_sub_into_unnormalized(self, dst, a, b, scratch)
112 }
113
114 fn ckks_sub_assign_unnormalized<Dst, A>(
115 &self,
116 dst: &mut UnnormalizedCKKSCiphertext<Dst>,
117 a: &A,
118 scratch: &mut ScratchArena<'_, BE>,
119 ) -> Result<()>
120 where
121 Dst: Data,
122 UnnormalizedCKKSCiphertext<Dst>: GLWEToBackendMut<BE>,
123 A: GLWEToBackendRef<BE> + CKKSInfos,
124 {
125 BE::ckks_sub_assign_unnormalized(self, dst, a, scratch)
126 }
127
128 fn ckks_sub_pt_vec_into_unnormalized<Dst, A, P>(
129 &self,
130 dst: &mut UnnormalizedCKKSCiphertext<Dst>,
131 a: &A,
132 pt: &P,
133 scratch: &mut ScratchArena<'_, BE>,
134 ) -> Result<()>
135 where
136 Dst: Data,
137 UnnormalizedCKKSCiphertext<Dst>: GLWEToBackendMut<BE>,
138 A: GLWEToBackendRef<BE> + CKKSCtBounds,
139 P: GLWEToBackendRef<BE> + CKKSCtBounds,
140 {
141 BE::ckks_sub_pt_vec_into_unnormalized(self, dst, a, pt, scratch)
142 }
143
144 fn ckks_sub_pt_vec_assign_unnormalized<Dst, P>(
145 &self,
146 dst: &mut UnnormalizedCKKSCiphertext<Dst>,
147 pt: &P,
148 scratch: &mut ScratchArena<'_, BE>,
149 ) -> Result<()>
150 where
151 Dst: Data,
152 UnnormalizedCKKSCiphertext<Dst>: GLWEToBackendMut<BE>,
153 P: GLWEToBackendRef<BE> + CKKSCtBounds,
154 {
155 BE::ckks_sub_pt_vec_assign_unnormalized(self, dst, pt, scratch)
156 }
157
158 fn ckks_sub_pt_const_into_unnormalized<Dst, A, P>(
159 &self,
160 dst: &mut UnnormalizedCKKSCiphertext<Dst>,
161 a: &A,
162 dst_coeff: usize,
163 pt: &P,
164 pt_coeff: usize,
165 scratch: &mut ScratchArena<'_, BE>,
166 ) -> Result<()>
167 where
168 Dst: Data,
169 UnnormalizedCKKSCiphertext<Dst>: GLWEToBackendMut<BE>,
170 A: GLWEToBackendRef<BE> + CKKSCtBounds,
171 P: GLWEToBackendRef<BE> + CKKSCtBounds,
172 {
173 BE::ckks_sub_pt_const_into_unnormalized(self, dst, a, dst_coeff, pt, pt_coeff, scratch)
174 }
175
176 fn ckks_sub_pt_const_assign_unnormalized<Dst, P>(
177 &self,
178 dst: &mut UnnormalizedCKKSCiphertext<Dst>,
179 dst_coeff: usize,
180 pt: &P,
181 pt_coeff: usize,
182 scratch: &mut ScratchArena<'_, BE>,
183 ) -> Result<()>
184 where
185 Dst: Data,
186 UnnormalizedCKKSCiphertext<Dst>: GLWEToBackendMut<BE>,
187 P: GLWEToBackendRef<BE> + CKKSCtBounds,
188 {
189 BE::ckks_sub_pt_const_assign_unnormalized(self, dst, dst_coeff, pt, pt_coeff, scratch)
190 }
191}