Used to perform operations on bitwise CTiles. More...
#include <BitwiseEvaluator.h>
Public Member Functions | |
BitwiseEvaluator (HeContext &he) | |
Constructs a ready to use object. More... | |
CTile getMSB (const CTile &c) const | |
Returns the MSB of c. More... | |
CTile getFlippedMSB (const CTile &c) const | |
Returns The NOT of the MSB of c. More... | |
void setIsSigned (CTile &c, bool val) const | |
Sets c to be signed if val is true, and unsigned otherwise. More... | |
bool getIsSigned (const CTile &c) const | |
Returns true if c is signed and false otherwise. More... | |
CTile hamming (const CTile &c, int from=0, int to=-1) const | |
std::vector< CTile > split (const CTile &c) const | |
Returns a vector of the bits of "c". More... | |
CTile combine (const std::vector< CTile > cs, int from=0, int to=-1, int bitsPerElement=1) const | |
Combines the given bitwise CTiles into one. More... | |
CTile isEqual (const CTile &c1, const CTile &c2) const | |
Checks whether c1 == c2. More... | |
CTile multiply (const CTile &c1, const CTile &c2, int targetBits=-1) const | |
Returns first "targetBits" LSBs of c1*c2. More... | |
CTile add (const CTile &c1, const CTile &c2, int targetBits=-1) const | |
Returns the first "targetBits" LSBs of c1 + c2. More... | |
CTile sub (const CTile &c1, const CTile &c2, int targetBits=-1) const | |
Returns the first "targetBits" LSBs of c1 - c2. More... | |
CTile multiplyBit (const CTile &c, const CTile &bit) const | |
Returns the result of multiplying all bits of c by the given "bit". More... | |
CTile bitwiseXor (const CTile &c1, const CTile &c2) const | |
Bitwise xor between c1 and c2. More... | |
int getNumBits (const CTile &c) const | |
Returns the number of bits of c. More... | |
void setNumBits (CTile &c, int bits) const | |
Updates c to contain "bits" bits. More... | |
int getDefaultNumBits () const | |
Returns the default number of bits to a CTile. More... | |
void debugPrintWithBinary (const CTile &c, const std::string &title, int maxElements=4, int verbose=0, std::ostream &out=std::cout) const | |
Prints debug info. More... | |
double getScale (const CTile &c) const | |
Returns the scale of c. More... | |
CTile max (const CTile &c1, const CTile &c2) const | |
Returns max(c1, c2). More... | |
CTile min (const CTile &c1, const CTile &c2) const | |
Returns min(c1, c2). More... | |
CTile isGreater (const CTile &c1, const CTile &c2) const | |
Checks whether c1 < c2. More... | |
CTile isLess (const CTile &c1, const CTile &c2) const | |
Checks whether c1 > c2. More... | |
CTile isGreaterEqual (const CTile &c1, const CTile &c2) const | |
Checks whether c1 >= c2. More... | |
CTile isLessEqual (const CTile &c1, const CTile &c2) const | |
Checks whether c1 <= c2. More... | |
Detailed Description
Used to perform operations on bitwise CTiles.
Can only be constructed by bitwise HeContext.
Constructor & Destructor Documentation
◆ BitwiseEvaluator()
helayers::BitwiseEvaluator::BitwiseEvaluator | ( | HeContext & | he | ) |
Constructs a ready to use object.
- Parameters
-
[in] he the underlying context.
Member Function Documentation
◆ add()
CTile helayers::BitwiseEvaluator::add | ( | const CTile & | c1, |
const CTile & | c2, | ||
int | targetBits = -1 |
||
) | const |
Returns the first "targetBits" LSBs of c1 + c2.
If one of c1 or c2 is signed, the returned CTile will be signed. Otherwise, the returned CTile will be unsigned.
- Parameters
-
[in] c1,c2 To add [in] targetBits The number of the bits of the result. If -1, the result will contain. max(getNumBits(c1) + getNumBits(c2) + 1) bits.
- Exceptions
-
runtime_error If the scales of c1 and c2 are different.
◆ bitwiseXor()
Bitwise xor between c1 and c2.
I c1 is signed, the result will be signed. Otherwise, the result will be unsigned.
- Parameters
-
[in] c1,c2 To perform bitwise xor between.
◆ combine()
CTile helayers::BitwiseEvaluator::combine | ( | const std::vector< CTile > | cs, |
int | from = 0 , |
||
int | to = -1 , |
||
int | bitsPerElement = 1 |
||
) | const |
Combines the given bitwise CTiles into one.
Combines all the bitwise CTiles in cs[from] until cs[to] (inclusive) into one bitwise CTile containing the first "bitsPerElement" LSB bits of each ciphertext. The LSB of the result is the first bit of cs[from]. If "to" is -1, then all the ciphertexts in cs[from] until cs.end() are taken.
- Parameters
-
[in] cs The bitwise CTiles to combine [in] from The index to start combining from. [in] out The index to combine until. [in] bitsPerElement How many bits to take from each CTile in "cs".
◆ debugPrintWithBinary()
void helayers::BitwiseEvaluator::debugPrintWithBinary | ( | const CTile & | c, |
const std::string & | title, | ||
int | maxElements = 4 , |
||
int | verbose = 0 , |
||
std::ostream & | out = std::cout |
||
) | const |
Prints debug info.
- Parameters
-
[in] c The CTile to print debug info about. [in] title The title used to display the debug message. [in] maxElements Maximal number of slots to debug-print. [in] verbose Verbose used while printing. [in,out] out The ostream to print to.
◆ getDefaultNumBits()
int helayers::BitwiseEvaluator::getDefaultNumBits | ( | ) | const |
Returns the default number of bits to a CTile.
This default number is taken from the HeContext this BitwiseEvaluator was initialized with.
◆ getFlippedMSB()
◆ getIsSigned()
bool helayers::BitwiseEvaluator::getIsSigned | ( | const CTile & | c | ) | const |
Returns true if c is signed and false otherwise.
- Parameters
-
[in] c To check whether it is signed.
◆ getMSB()
◆ getNumBits()
int helayers::BitwiseEvaluator::getNumBits | ( | const CTile & | c | ) | const |
Returns the number of bits of c.
- Parameters
-
[in] c To check its number of bits.
◆ getScale()
double helayers::BitwiseEvaluator::getScale | ( | const CTile & | c | ) | const |
Returns the scale of c.
- Parameters
-
[in] c To get its scale.
◆ isEqual()
Checks whether c1 == c2.
Returns (an encryption of) 1 if c1 == c2, and (an encryption of) 0 otherwise. The result is returned is one-bit, unsigned, bitwise CTile.
- Parameters
-
[in] c1,c2 To evaluate c1 == c2 on.
◆ isGreater()
Checks whether c1 < c2.
Returns (an encryption of) 1 if c1 < c2, and (an encryption of) 0 otherwise. The result is returned is one-bit, unsigned, bitwise CTile.
- Parameters
-
[in] c1,c2 To evaluate c1 < c2 on.
◆ isGreaterEqual()
Checks whether c1 >= c2.
Returns (an encryption of) 1 if c1 >= c2, and (an encryption of) 0 otherwise. The result is returned is one-bit, unsigned, bitwise CTile.
- Parameters
-
[in] c1,c2 To evaluate c1 >= c2 on.
◆ isLess()
Checks whether c1 > c2.
Returns (an encryption of) 1 if c1 > c2, and (an encryption of) 0 otherwise. The result is returned is one-bit, unsigned, bitwise CTile.
- Parameters
-
[in] c1,c2 To evaluate c1 > c2 on.
◆ isLessEqual()
Checks whether c1 <= c2.
Returns (an encryption of) 1 if c1 <= c2, and (an encryption of) 0 otherwise. The result is returned is one-bit, unsigned, bitwise CTile.
- Parameters
-
[in] c1,c2 To evaluate c1 <= c2 on.
◆ max()
Returns max(c1, c2).
- Parameters
-
[in] c1,c2 To compute their maximum.
◆ min()
Returns min(c1, c2).
- Parameters
-
[in] c1,c2 To compute their maximum.
◆ multiply()
CTile helayers::BitwiseEvaluator::multiply | ( | const CTile & | c1, |
const CTile & | c2, | ||
int | targetBits = -1 |
||
) | const |
Returns first "targetBits" LSBs of c1*c2.
If one of c1 or c2 is signed, the returned CTile will be signed. Otherwise, the returned CTile will be unsigned. The scale of the result is set to the product of c1's and c2's scales.
- Parameters
-
[in] c1,c2 To multiply. [in] targetBits The number of the bits of the result. If -1, the result will contain getNumBits(c1) + getNumBits(c2) bits.
◆ multiplyBit()
Returns the result of multiplying all bits of c by the given "bit".
- Parameters
-
[in] c To multiply its bits by the given bit. [in] bit To multiply c by.
◆ setIsSigned()
void helayers::BitwiseEvaluator::setIsSigned | ( | CTile & | c, |
bool | val | ||
) | const |
Sets c to be signed if val is true, and unsigned otherwise.
Note that changing c from signed to unsigned (or converse) will cause its value to change accordingly. The value of a signed CTile is interpreted using 2's complement method, and the value of an unsigned CTile is interpreted as an ordinary binary number.
- Parameters
-
[in] c To set to signed/unsigned. [in] val Whether to set c to signed or unsigned.
◆ setNumBits()
void helayers::BitwiseEvaluator::setNumBits | ( | CTile & | c, |
int | bits | ||
) | const |
Updates c to contain "bits" bits.
If getNumBits(c) > bits, then MSBs of c are removed until it contains only "bits" bits. If getNumBits(c) < bits and c is signed, then the MSB of c is added to c until it contains "bits" bits. If getNumBits(c) < bits and c is unsigned, then 0 is added to c until it contains "bits" bits.
- Parameters
-
[in,out] c The CTile to update to contain "bits" bit. [in] bits The number of bits c will contain.
◆ split()
◆ sub()
CTile helayers::BitwiseEvaluator::sub | ( | const CTile & | c1, |
const CTile & | c2, | ||
int | targetBits = -1 |
||
) | const |
Returns the first "targetBits" LSBs of c1 - c2.
If one of c1 or c2 is signed, the returned CTile will be signed. Otherwise, the returned CTile will be unsigned.
- Parameters
-
[in] c1,c2 To subtract. [in] targetBits The number of the bits of the result. If -1, the result will contain getNumBits(c1) bits.
- Exceptions
-
runtime_error If the scales of c1 and c2 are different.
The documentation for this class was generated from the following files:
- /opt/IBM/FHE-distro/ML-HElib/src/helayers/hebase/BitwiseEvaluator.h
- /opt/IBM/FHE-distro/ML-HElib/src/helayers/hebase/BitwiseEvaluator.cpp