Skip to main content

poulpy_ckks/delegates/
add.rs

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::{CKKSAddOps, CKKSAddOpsUnnormalized};
7
8use crate::{CKKSCtBounds, CKKSInfos, SetCKKSInfos, oep::CKKSAddImpl};
9
10impl<BE: Backend + CKKSAddImpl<BE>> CKKSAddOps<BE> for Module<BE> {
11    fn ckks_add_tmp_bytes(&self) -> usize {
12        BE::ckks_add_tmp_bytes(self)
13    }
14
15    fn ckks_add_into<Dst, A, B>(&self, dst: &mut Dst, a: &A, b: &B, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
16    where
17        Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
18        A: GLWEToBackendRef<BE> + CKKSCtBounds,
19        B: GLWEToBackendRef<BE> + CKKSCtBounds,
20    {
21        BE::ckks_add_into(self, dst, a, b, scratch)
22    }
23
24    fn ckks_add_assign<Dst, A>(&self, dst: &mut Dst, a: &A, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
25    where
26        Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
27        A: GLWEToBackendRef<BE> + CKKSCtBounds,
28    {
29        BE::ckks_add_assign(self, dst, a, scratch)
30    }
31
32    fn ckks_add_one_assign<Dst>(&self, dst: &mut Dst, scratch: &mut ScratchArena<'_, BE>) -> Result<()>
33    where
34        Dst: GLWEToBackendMut<BE> + CKKSCtBounds + SetCKKSInfos,
35    {
36        BE::ckks_add_one_assign(self, dst, scratch)
37    }
38
39    fn ckks_add_pt_vec_tmp_bytes(&self) -> usize {
40        BE::ckks_add_pt_vec_tmp_bytes(self)
41    }
42
43    fn ckks_add_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_add_pt_vec_into(self, dst, a, pt, scratch)
50    }
51
52    fn ckks_add_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_add_pt_vec_assign(self, dst, pt, scratch)
58    }
59
60    fn ckks_add_pt_const_tmp_bytes(&self) -> usize {
61        BE::ckks_add_pt_const_tmp_bytes(self)
62    }
63
64    fn ckks_add_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_add_pt_const_into(self, dst, a, dst_coeff, pt, pt_coeff, scratch)
79    }
80
81    fn ckks_add_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_add_pt_const_assign(self, dst, dst_coeff, pt, pt_coeff, scratch)
94    }
95}
96
97impl<BE: Backend + CKKSAddImpl<BE>> CKKSAddOpsUnnormalized<BE> for Module<BE> {
98    fn ckks_add_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_add_into_unnormalized(self, dst, a, b, scratch)
112    }
113
114    fn ckks_add_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_add_assign_unnormalized(self, dst, a, scratch)
126    }
127
128    fn ckks_add_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_add_pt_vec_into_unnormalized(self, dst, a, pt, scratch)
142    }
143
144    fn ckks_add_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_add_pt_vec_assign_unnormalized(self, dst, pt, scratch)
156    }
157
158    fn ckks_add_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_add_pt_const_into_unnormalized(self, dst, a, dst_coeff, pt, pt_coeff, scratch)
174    }
175
176    fn ckks_add_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_add_pt_const_assign_unnormalized(self, dst, dst_coeff, pt, pt_coeff, scratch)
190    }
191}