tableLookup.h
1 /* Copyright (C) 2012-2020 IBM Corp.
2  * This program is Licensed under the Apache License, Version 2.0
3  * (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software
7  * distributed under the License is distributed on an "AS IS" BASIS,
8  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9  * See the License for the specific language governing permissions and
10  * limitations under the License. See accompanying LICENSE file.
11  */
12 #ifndef HELIB_TABLELOOKUP_H
13 #define HELIB_TABLELOOKUP_H
14 
18 #include <functional>
19 #include <helib/EncryptedArray.h>
20 #include <helib/CtPtrs.h>
21 
22 namespace helib {
23 
24 // inline void convert(Ctxt& a, const Ctxt& b) { a=b; }
25 
29 void computeAllProducts(CtPtrs& products,
30  const CtPtrs& array,
31  std::vector<zzX>* unpackSlotEncoding = nullptr);
32 
36 void tableLookup(Ctxt& out,
37  const std::vector<zzX>& table,
38  const CtPtrs& idx,
39  std::vector<zzX>* unpackSlotEncoding = nullptr);
40 
44 void tableWriteIn(const CtPtrs& table,
45  const CtPtrs& idx,
46  std::vector<zzX>* unpackSlotEncoding = nullptr);
47 
86 void buildLookupTable(std::vector<zzX>& T, // encoded result is returned in T
87  std::function<double(double)> f,
88  long nbits_in, // number of precision bits
89  long scale_in, // scaling factor
90  long sign_in, // 1: 2's complement signed, 0: unsigned
91  long nbits_out,
92  long scale_out,
93  long sign_out,
94  const EncryptedArray& ea);
95 
96 } // namespace helib
97 
98 #endif // ifndef HELIB_TABLELOOKUP_H
void buildLookupTable(std::vector< zzX > &T, std::function< double(double)> f, long nbits_in, long scale_in, long sign_in, long nbits_out, long scale_out, long sign_out, const EncryptedArray &ea)
Built a table-lookup for a function in fixed-point representation.
Definition: tableLookup.cpp:139
Definition: apiAttributes.h:21
void computeAllProducts(CtPtrs &products, const CtPtrs &array, std::vector< zzX > *unpackSlotEncoding=nullptr)
Definition: tableLookup.cpp:37
void tableWriteIn(const CtPtrs &table, const CtPtrs &idx, std::vector< zzX > *unpackSlotEncoding=nullptr)
Definition: tableLookup.cpp:109
void tableLookup(Ctxt &out, const std::vector< zzX > &table, const CtPtrs &idx, std::vector< zzX > *unpackSlotEncoding=nullptr)
Definition: tableLookup.cpp:83
PtrVector< Ctxt > CtPtrs
Definition: CtPtrs.h:25