Encoder#
- class Encoder#
A class used to encode, encrypt, decode and decrypt ciphertexts and plaintexts.
- assert_equals(*args, **kwargs)#
Overloaded function.
assert_equals(self: pyhelayers.Encoder, c: pyhelayers.CTile, title: str, expected_vals: numpy.ndarray[numpy.int32], eps: float = 1e-06, percent: bool = False) -> float
Asserts that “c” and “expected_vals” are considered equal.
"c" and “expected_vals” will be considered equal if when decrypting and decoding “c” into a vector, v, one of the following holds: 1. percent == false and fabs(v[i] - expected_vals[i]) < eps, foreach i. 2. percent == true and fabs(v[i] - expected_vals[i]) / fabs(v[i]) < eps, foreach i.
The maximum found absolute or relative difference (depending on the value of “percent” flag) is returned.
- param c:
The CTile to compare with expectedVals.
- type c:
CTile
- param title:
The title used in case of printing a failure message.
- type title:
string
- param expected_vals:
The vector to compare with “c”.
- type expected_vals:
numpy.array
- param eps:
Comparison tolerance. Defaults to 1e-6.
- type eps:
double
- param percent:
If true, the relative difference between “c” and “expectedVals” is checked. Otherwise, the absolute difference is checked. Defaults to false.
- type percent:
bool
assert_equals(self: pyhelayers.Encoder, c: pyhelayers.CTile, title: str, expected_vals: numpy.ndarray[numpy.float64], eps: float = 1e-06, percent: bool = False) -> float
Asserts that “c” and “expected_vals” are considered equal. “c” and “expected_vals” will be considered equal if when decrypting and decoding “c” into a vector, v, one of the following holds: 1. percent == false and fabs(v[i] - expected_vals[i]) < eps, foreach i. 2. percent == true and fabs(v[i] - expected_vals[i]) / fabs(v[i]) < eps, foreach i. The maximum found absolute or relative difference (depending on the value of “percent” flag) is returned.
- param c:
The CTile to compare with expectedVals.
- type c:
CTile
- param title:
The title used in case of printing a failure message.
- type title:
string
- param expected_vals:
The vector to compare with “c”.
- type expected_vals:
numpy.array
- param eps:
Comparison tolerance. Defaults to 1e-6.
- type eps:
double
- param percent:
If true, the relative difference between “c” and “expectedVals” is checked. Otherwise, the absolute difference is checked. Defaults to false.
- type percent:
bool
assert_equals(self: pyhelayers.Encoder, c: pyhelayers.CTile, title: str, expected_vals: numpy.ndarray[numpy.complex128], eps: float = 1e-06, percent: bool = False) -> float
Asserts that “c” and “expected_vals” are considered equal. “c” and “expected_vals” will be considered equal if when decrypting and decoding “c” into a vector, v, one of the following holds: 1. percent == false and fabs(v[i] - expected_vals[i]) < eps, foreach i. 2. percent == true and fabs(v[i] - expected_vals[i]) / fabs(v[i]) < eps, foreach i. The maximum found absolute or relative difference (depending on the value of “percent” flag) is returned.
- param c:
The CTile to compare with expectedVals.
- type c:
CTile
- param title:
The title used in case of printing a failure message.
- type title:
string
- param expected_vals:
The vector to compare with “c”.
- type expected_vals:
numpy.array
- param eps:
Comparison tolerance. Defaults to 1e-6.
- type eps:
double
- param percent:
If true, the relative difference between “c” and “expectedVals” is checked. Otherwise, the absolute difference is checked. Defaults to false.
- type percent:
bool
- decode_complex(self: pyhelayers.Encoder, src: pyhelayers.PTile) numpy.ndarray[numpy.complex128] #
Decodes the given PTile into an array of doubles.
- Parameters:
src – The PTile to decode.
- Returns:
the decoded array of doubles
- Return type:
numpy.array
- decode_double(self: pyhelayers.Encoder, src: pyhelayers.PTile) numpy.ndarray[numpy.float64] #
Decodes the given PTile into an array of doubles.
- Parameters:
src – The PTile to decode.
- Returns:
the decoded array of doubles
- Return type:
numpy.array
- decode_int(self: pyhelayers.Encoder, src: pyhelayers.PTile) numpy.ndarray[numpy.int32] #
Decodes the given PTile into an array of integers.
- Parameters:
src – The PTile to decode.
- Returns:
the decoded array of integers
- Return type:
numpy.array
- decrypt_decode_complex(self: pyhelayers.Encoder, ctxt: pyhelayers.CTile) numpy.ndarray[numpy.complex128] #
Decrypts and then decodes the given CTile into an array of complex numbers.
- Parameters:
in – The CTile to decrypt and decode.
- Return type:
numpy.array
- decrypt_decode_double(self: pyhelayers.Encoder, ctxt: pyhelayers.CTile) numpy.ndarray[numpy.float64] #
Decrypts and then decodes the given CTile into an array of doubles.
- Parameters:
in – The CTile to decrypt and decode.
- Return type:
numpy.array
- decrypt_decode_int(self: pyhelayers.Encoder, ctxt: pyhelayers.CTile) numpy.ndarray[numpy.int32] #
Decrypts and then decodes the given CTile into an array of integers.
- Parameters:
in – The CTile to decrypt and decode.
- Return type:
numpy.array
- decrypt_decode_tile_double(self: pyhelayers.Encoder, src: pyhelayers.Tile) numpy.ndarray[numpy.float64] #
If “src” is a CTile, decrypts and decodes it into a numpy array of doubles. If “src” is a PTile, decodes it into a numpy array of doubles.
- Parameters:
src (Tile) – The Tile to encrypt.
- Returns:
the decrypt-decode result.
- Return type:
numpy array of doubles
- encode(*args, **kwargs)#
Overloaded function.
encode(self: pyhelayers.Encoder, val: int, chain_index: int = -1) -> pyhelayers.PTile
Encodes the given integer into all slots of a PTile. This is Usually more efficient than regular encoding.
- param val:
The value to encode.
- type val:
int
- param chain_index:
If the HeContext used to create this PTile is a CKKS context, specifies the chain index of the resulting PTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrypted PTile.
- rtype:
PTile
encode(self: pyhelayers.Encoder, val: float, chain_index: int = -1) -> pyhelayers.PTile
Encodes the given double into all slots of a PTile. This is Usually more efficient than regular encoding.
- param val:
The value to encode.
- type val:
Float
- param chain_index:
If the HeContext used to create this PTile is a CKKS context, specifies the chain index of the resulting PTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrypted PTile.
- rtype:
PTile
encode(self: pyhelayers.Encoder, val: complex, chain_index: int = -1) -> pyhelayers.PTile
Encodes the given complex value into all slots of a PTile. This is Usually more effecient than regular encoding. :param val: The value to encode. :type val: complex :param chain_index: If the HeContext used to create this PTile is a
CKKS context, specifies the chain index of the resulting PTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrpyted PTile.
- rtype:
PTile
encode(self: pyhelayers.Encoder, val: List[int], chain_index: int = -1) -> pyhelayers.PTile
Encodes the given list of integers into a PTile. If the length of the given list is less than slot count, the empty slots of the PTile will be set to zero. If the length of the given list is more than slot count, a RuntimeError will be thrown.
- param vals:
The plain integers list to encode.
- type input:
list or numpy.array
- param chain_index:
If the HeContext used to create this PTile is a CKKS context, specifies the chain index of the resulting PTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrypted PTile.
- rtype:
numpy.array
- raises RuntimeError:
If len(vals) is greater than the number of slots.
encode(self: pyhelayers.Encoder, vals: List[float], chain_index: int = -1) -> pyhelayers.PTile
Encodes the given list of doubles into a PTile. If the length of the given list is less than slot count, the empty slots of the PTile will be set to zero. If the length of the given list is more than slot count, a RuntimeError will be thrown.
- param vals:
The plain double list to encode.
- type input:
list or numpy.array
- param chain_index:
If the HeContext used to create this PTile is a CKKS context, specifies the chain index of the resulting PTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrypted PTile.
- rtype:
PTile
- raises RuntimeError:
If len(vals) is greater than the number of slots.
encode(self: pyhelayers.Encoder, vals: List[complex], chain_index: int = -1) -> pyhelayers.PTile
Encodes the given list of complex numbers into a PTile. If the length of the given list is less than slot count, the empty slots of the PTile will be set to zero. If the length of the given list is more than slot count, a RuntimeError will be thrown.
- param vals:
The plain list of complex numbers to encode.
- type input:
list or numpy.array
- param chain_index:
If the HeContext used to create this PTile is a CKKS context, specifies the chain index of the resulting PTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrypted PTile.
- rtype:
PTile
- raises RuntimeError:
If len(vals) is greater than the number of slots.
- encode_encrypt(*args, **kwargs)#
Overloaded function.
encode_encrypt(self: pyhelayers.Encoder, val: int, chain_index: int = -1) -> pyhelayers.CTile
Encodes and then encrypts the given int into all slots of a CTile. :param val: The value to encode and encrypt. :type val: int :param chain_index: If the HeContext used to create this CTile is a
CKKS context, specifies the chain index of the resulting CTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrpyted CTile.
- rtype:
CTile
encode_encrypt(self: pyhelayers.Encoder, val: float, chain_index: int = -1) -> pyhelayers.CTile
Encodes and then encrypts the given float into all slots of a CTile. :param val: The value to encode and encrypt. :type val: float :param chain_index: If the HeContext used to create this CTile is a
CKKS context, specifies the chain index of the resulting CTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrpyted CTile.
- rtype:
CTile
encode_encrypt(self: pyhelayers.Encoder, val: complex, chain_index: int = -1) -> pyhelayers.CTile
Encodes and then encrypts the given complex value into all slots of a CTile. :param val: The value to encode and encrypt. :type val: complex :param chain_index: If the HeContext used to create this CTile is a
CKKS context, specifies the chain index of the resulting CTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrpyted CTile.
- rtype:
CTile
encode_encrypt(self: pyhelayers.Encoder, vals: List[int], chain_index: int = -1) -> pyhelayers.CTile
Encodes and then encrypts the given list of integers into a CTile. if the length of the given list is less than slot count, the empty slots of the CTile will be set to zero. If the length of the given list is more than slot count, a RuntimeError will be thrown.
- param vals:
The plain integers list to encrypt.
- type vals:
list or numpy.array
- param chain_index:
If the HeContext used to create this CTile is a CKKS context, specifies the chain index of the resulting CTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrypted CTile.
- rtype:
CTile
- raises RuntimeError:
If len(vals) is greater than the number of slots.
encode_encrypt(self: pyhelayers.Encoder, vals: List[float], chain_index: int = -1) -> pyhelayers.CTile
Encodes and then encrypts the given list of doubles into a CTile. if the length of the given list is less than slot count, the empty slots of the CTile will be set to zero. If the length of the given list is more than slot count, a RuntimeError will be thrown.
- param vals:
The plain doubles list to encrypt.
- type vals:
list or numpy.array
- param chain_index:
If the HeContext used to create this CTile is a CKKS context, specifies the chain index of the resulting CTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrypted CTile.
- rtype:
CTile
- raises RuntimeError:
If len(vals) is greater than the number of slots.
encode_encrypt(self: pyhelayers.Encoder, vals: List[complex], chain_index: int = -1) -> pyhelayers.CTile
Encodes and then encrypts the given list of complex numbers into a CTile. if the length of the given list is less than slot count, the empty slots of the CTile will be set to zero. If the length of the given list is more than slot count, a RuntimeError will be thrown.
- param vals:
The plain list of complex numbers to encrypt.
- type vals:
list or numpy.array
- param chain_index:
If the HeContext used to create this CTile is a CKKS context, specifies the chain index of the resulting CTile. Otherwise, this parameter is ignored. Defaults to -1.
- type chainIndex:
int
- return:
The encrypted CTile.
- rtype:
CTile
- raises RuntimeError:
If len(vals) is greater than the number of slots.
- encrypt_tile(self: pyhelayers.Encoder, src: pyhelayers.Tile) pyhelayers.CTile #
If “src” is a PTile, encrypts it and returns the resulting CTile. If “src” is a CTile, returns a copy of it.
- Parameters:
src (Tile) – The Tile to encrypt.
- Returns:
The encrypted CTile.
- Return type:
- get_decrypt_added_noise_enabled(self: pyhelayers.Encoder) bool #
Returns a boolean indicating whether to enable the decrypt added noise.
- get_decrypt_added_noise_precision(self: pyhelayers.Encoder) int #
Returns an integer indicating precision to be preserved.
- Raises:
RuntimeError – If the undelying library does not support decrypt added noise.
- get_default_device(self: pyhelayers.Encoder) Tuple[pyhelayers.DeviceType, int] #
Returns the default device of the ciphertexts and plaintexts generated using this HeContext.
- Return type:
DeviceType, int
- get_default_scale(self: pyhelayers.Encoder, chain_index: int) float #
Returns the scale used by the encoder as set by setDefaultScale. If no default was previously set, return the default scale define by the HeContext object.
- Parameters:
chain_index – The chain index, may affect the scale used by the scheme’s default if no other default scale was set.
- Returns:
The default scale
- Return type:
double
- print_error_stats(self: pyhelayers.Encoder, actual_c: pyhelayers.CTile, expected_z: numpy.ndarray[numpy.float64], as_csv: bool = False) str #
Prints statistical information relating to the difference between “actual_c” and “expected_z”.
- Parameters:
actual_c – The CTile to decode-decrypt and to compare to expected_z.
expected_z (numpy.array) – The vector of doubles to compare actual_c with.
as_csv (bool) – Whether to print the stats as CSV. Defaults to false.
- restore_default_scale(self: pyhelayers.Encoder) None #
Restores the default scale to the default scale defined by the HeContext object.
- set_decrypt_added_noise_enabled(self: pyhelayers.Encoder, val: bool) None #
Allows to determine whether to enable the decrypt added noise. The default behaviour for libraries that supports this feature is to have it enabled. Decrypt added noise is relevant to CKKS scheme for the purpose of ensuring security. reference: “On the Security of Homomorphic Encryption on Approximate Numbers”, Baiyu Li and Daniele Micciancio, https://eprint.iacr.org/2020/1533.pdf.
- Parameters:
val (bool) – A boolean indicating whether to enable the decrypt added noise.
- set_decrypt_added_noise_precision(self: pyhelayers.Encoder, arg0: int) None #
Allows to set the level of precision to be preserved in the process of adding decrypt noise, if the decrypt added noise is enabled. If decrypt added noise is not enabled, this value is ignored.
- Parameters:
val – An integer indicating precision to be preserved.
- Raises:
RuntimeError – If the undelying library does not support decrypt added noise.
- set_default_device(self: pyhelayers.Encoder, type: pyhelayers.DeviceType, device_id: int = 0) None #
Sets the default device of the ciphertexts and plaintexts generated using this HeContext.
- Parameters:
type – the new default device type.
device_id – the new default device ID.
- set_default_scale(self: pyhelayers.Encoder, scale: float) None #
Default scale is a parameter relevant to CKKS-like schemes. It is the scale used to encode values into plaintext/ciphertext. If left unset, the encoder will use the scheme’s default. After setting, the encoder will use the given value. setDefaultScale sets the scale that the encoder will use henceforth.
- Parameters:
scale (double) – The new default scale.
-
class Encoder#
A class used to encode, encrypt, decode and decrypt ciphertexts and plaintexts.
Public Functions
-
Encoder(const HeContext &he)#
Constructs a ready to use object.
- Parameters:
he – [in] the underlying context.
-
~Encoder()#
-
Encoder &operator=(const Encoder &src) = delete#
Assignment deleted. Construct new objects when needed.
-
void setDefaultDevice(DeviceType type, int deviceId)#
Sets the default device of ciphertext or plaintexts that are encrypted or encoded using this Encoder.
- Parameters:
type – [in] The device type.
deviceId – [in] The device ID.
-
std::pair<DeviceType, int> getDefaultDevice() const#
Returns the default device used by the encoder as set by setDefaultDevice.
If no default was previously set, returns the default scale defined by the HeContext object.
-
void setDefaultScale(double scale)#
Default scale is a parameter relevant to CKKS-like schemes.
It is the scale used to encode values into plaintext/ciphertext. If left unset, the encoder will use the scheme’s default. After setting, the encoder will use the given value. setDefaultScale sets the scale that the encoder will use henceforth.
- Parameters:
scale – [in] The new default scale.
-
double getDefaultScale(int chainIndex = -1) const#
Returns the scale used by the encoder as set by setDefaultScale.
If no default was previously set, returns the default scale defined by the HeContext object.
- Parameters:
chainIndex – [in] The chain index, may affect the scale used by the scheme’s default if no other default scale was set.
-
void restoreDefaultScale()#
Restores the default scale to the default scale defined by the HeContext object.
-
void setDecryptAddedNoiseEnabled(bool val)#
Allows to determine whether to enable the decrypt added noise.
The default behaviour for libraries that supports this feature is to have it enabled. Decrypt added noise is relevant to CKKS scheme for the purpose of ensuring security. reference: “On the Security of Homomorphic Encryption on Approximate
Numbers”, Baiyu Li and Daniele Micciancio,
https://eprint.iacr.org/2020/1533.pdf- Parameters:
val – [in] A boolean indicating whether to enable the decrypt added noise.
-
bool getDecryptAddedNoiseEnabled() const#
Returns a boolean indicating whether to enable the decrypt added noise.
-
void setDecryptAddedNoisePrecision(int val)#
Allows to set the level of precision to be preserved in the process of adding decrypt noise, if the decrypt added noise is enabled.
If decrypt added noise is not enabled, this value is ignored.
- Parameters:
val – [in] An integer indicating precision to be preserved.
- Throws:
runtime_error – If the undelying library does not support decrypt added noise
-
int getDecryptAddedNoisePrecision() const#
Returns an integer indicating precision to be preserved.
- Throws:
runtime_error – If the undelying library does not support decrypt added noise
-
void encode(PTile &res, int val, int chainIndex = -1) const#
Encodes the given int into all slots of a PTile.
This is usually more efficient than regular encoding.
-
void encode(PTile &res, double val, int chainIndex = -1) const#
Encodes the given double into all slots of a PTile.
This is usually more efficient than regular encoding.
-
void encode(PTile &res, const std::complex<double> &val, int chainIndex = -1) const#
Encodes the given complex into all slots of a PTile.
-
void encode(PTile &res, const std::vector<int> &vals, int chainIndex = -1) const#
Encodes the given vector of integers into a PTile.
If the size of the given vector is less than slot count, the empty slots of the PTile will be set to zero. If the size of the given vector is more than slot count, a runtime_error will be thrown.
-
void encode(PTile &res, const std::vector<long> &vals, int chainIndex = -1) const#
Encodes the given vector of longs into a PTile.
If the size of the given vector is less than slot count, the empty slots of the PTile will be set to zero. If the size of the given vector is more than slot count, a runtime_error will be thrown.
-
void encode(PTile &res, const std::vector<double> &vals, int chainIndex = -1) const#
Encodes the given vector of doubles into a PTile.
If the size of the given vector is less than slot count, the empty slots of the PTile will be set to zero. If the size of the given vector is more than slot count, a runtime_error will be thrown.
-
void encode(PTile &res, const std::vector<std::complex<double>> &vals, int chainIndex = -1) const#
Encodes the given vector of complex numbers into a PTile.
If the size of the given vector is less than slot count, the empty slots of the PTile will be set to zero. If the size of the given vector is more than slot count, a runtime_error will be thrown.
-
void encode(PTile &res, const MTile &m, int chainIndex = -1) const#
Encodes the given MTile into a PTile.
-
std::vector<int> decodeInt(const PTile &src) const#
Decodes the value of the given PTile into a vector of ints.
If the underlying FHE scheme is a scheme that supports floating point values, then “src” is first decrypted into a vector of doubles and then rounded to the nearest integers.
- Parameters:
src – [in] The PTile to decode.
-
std::vector<long> decodeLong(const PTile &src) const#
Decodes the value of the given PTile into a vector of longs.
If the underlying FHE scheme is a scheme that supports floating point values, then “src” is first decrypted into a vector of doubles and then rounded to the nearest integers.
- Parameters:
src – [in] The PTile to decode.
-
std::vector<double> decodeDouble(const PTile &src) const#
Decodes the value of the given PTile into a vector of doubles.
- Parameters:
src – [in] The PTile to decode.
-
std::vector<std::complex<double>> decodeComplex(const PTile &src) const#
Decodes the value of the given PTile into a vector of complex<double>.
- Parameters:
src – [in] The PTile to decode.
-
void encryptTile(CTile &res, const Tile &t) const#
If “t” is a PTile, encrypts it into “res” CTile.
If “t” is a CTile, copies it into “res” CTile.
- Parameters:
res – The resulting CTile.
t – The Tile to encrypt.
-
void encodeEncrypt(CTile &res, int val, int chainIndex = -1) const#
Encodes and then encrypts the given int into all slots of a CTile.
-
void encodeEncrypt(CTile &res, double val, int chainIndex = -1) const#
Encodes and then encrypts the given double into all slots of a CTile.
-
void encodeEncrypt(CTile &res, const std::complex<double> &val, int chainIndex = -1) const#
Encodes and then encrypts the given complex value into all slots of a CTile.
-
void encodeEncrypt(CTile &res, const std::vector<int> &vals, int chainIndex = -1) const#
Encodes and then encrypts the given vector into a CTile.
if the size of the given vector is less than slot count, the empty slots of the CTile will be set to zero. If the size of the given vector is more than slot count, a runtime_error will be thrown.
-
void encodeEncrypt(CTile &res, const std::vector<long> &vals, int chainIndex = -1) const#
Encodes and then encrypts the given vector into a CTile.
if the size of the given vector is less than slot count, the empty slots of the CTile will be set to zero. If the size of the given vector is more than slot count, a runtime_error will be thrown.
-
void encodeEncrypt(CTile &res, const std::vector<double> &vals, int chainIndex = -1) const#
Encodes and then encrypts the given vector into a CTile.
if the size of the given vector is less than slot count, the empty slots of the CTile will be set to zero. If the size of the given vector is more than slot count, a runtime_error will be thrown.
-
void encodeEncrypt(CTile &res, const std::vector<std::complex<double>> &vals, int chainIndex = -1) const#
Encodes and then encrypts the given vector into a CTile.
if the size of the given vector is less than slot count, the empty slots of the CTile will be set to zero. If the size of the given vector is more than slot count, a runtime_error will be thrown.
- Parameters:
- Throws:
runtime_error – If vals.size() > slot count
runtime_error – If the underlying FHE scheme is a scheme that does not support complex values (such as BGV, for example).
-
std::vector<int> decryptDecodeInt(const CTile &src) const#
Decodes and then decrypts the given CTile into a vector of ints.
If the underlying FHE scheme is a scheme that supports floating point values, then “src” is first decrypted into a vector of doubles and then rounded to the nearest integers.
- Parameters:
src – [in] The CTile to decode and decrypt.
-
std::vector<long> decryptDecodeLong(const CTile &src) const#
Decodes and then decrypts the given CTile into a vector of ints.
If the underlying FHE scheme is a scheme that supports floating point values, then “src” is first decrypted into a vector of doubles and then rounded to the nearest integers.
- Parameters:
src – [in] The CTile to decode and decrypt.
-
std::vector<double> decryptDecodeDouble(const CTile &src) const#
Decodes and then decrypts the given CTile into a vector of doubles.
- Parameters:
src – [in] The CTile to decode and decrypt.
-
std::vector<double> decryptDecodeTileDouble(const Tile &t) const#
If “t” is a CTile, decrypts and decodes it into a vector of doubles.
If “t” is a PTile, decodes it into a vector of doubles.
- Parameters:
t – The Tile to decode and decrypt.
-
std::vector<std::complex<double>> decryptDecodeComplex(const CTile &src) const#
Decodes and then decrypts the given CTile into a vector of complex<double>.
- Parameters:
src – [in] The CTile to decode and decrypt.
-
void printErrorStats(CTile &actualC, std::vector<double> expectedZ, std::ostream &out = std::cout, bool asCsv = false) const#
Prints statistical information relating to the difference between “actualC” and “expectedZ”.
- Parameters:
actualC – [in] The CTile to decode-decrypt and to compare to expectedZ.
expectedZ – [in] The vector of doubles to compare actualC with.
out – [in] The ostream to print to.
asCsv – [in] When true, prints a concise comma separated list of numbers.
-
int validateChainIndex(int chainIndex) const#
checks whether a chain index is valid.
- Parameters:
chainIndex – [in] To check its validity.
-
double assertEquals(const CTile &c, const std::string &title, const std::vector<int> &expectedVals, double eps = 1e-6, bool percent = false) const#
Asserts that “c” and “expectedVals” are considered equal.
“c” and “expectedVals” will be considered equal if when decrypting and decoding “c” into a vector, v, one of the following holds:
percent == false and fabs(v[i] - expectedVals[i]) < eps, foreach i.
percent == true and fabs(v[i] - expectedVals[i]) / fabs(v[i]) < eps, foreach i. The maximum found absolute or relative difference (depending on the value of “percent” flag) is returned.
- Parameters:
c – [in] The CTile to compare with expectedVals
title – [in] The title used in case of printing a failure message.
expectedVals – [in] The vector to compare with “c”.
eps – [in] Comparison tolerance
percent – [in] If true, the relative difference between “c” and “expectedVals” is checked. Otherwise, the absolute difference is checked.
-
double assertEquals(const CTile &c, const std::string &title, const std::vector<long> &expectedVals, double eps = 1e-6, bool percent = false) const#
Asserts that “c” and “expectedVals” are considered equal.
“c” and “expectedVals” will be considered equal if when decrypting and decoding “c” into a vector, v, one of the following holds:
percent == false and fabs(v[i] - expectedVals[i]) < eps, foreach i.
percent == true and fabs(v[i] - expectedVals[i]) / fabs(v[i]) < eps, foreach i. The maximum found absolute or relative difference (depending on the value of “percent” flag) is returned.
- Parameters:
c – [in] The CTile to compare with expectedVals
title – [in] The title used in case of printing a failure message.
expectedVals – [in] The vector to compare with “c”.
eps – [in] Comparison tolerance
percent – [in] If true, the relative difference between “c” and “expectedVals” is checked. Otherwise, the absolute difference is checked.
-
double assertEquals(const CTile &c, const std::string &title, const std::vector<double> &expectedVals, double eps = 1e-6, bool percent = false) const#
Asserts that “c” and “expectedVals” are considered equal.
“c” and “expectedVals” will be considered equal if when decrypting and decoding “c” into a vector, v, one of the following holds:
percent == false and fabs(v[i] - expectedVals[i]) < eps, foreach i.
percent == true and fabs(v[i] - expectedVals[i]) / fabs(v[i]) < eps, foreach i. The maximum found absolute or relative difference (depending on the value of “percent” flag) is returned.
- Parameters:
c – [in] The CTile to compare with expectedVals
title – [in] The title used in case of printing a failure message.
expectedVals – [in] The vector to compare with “c”.
eps – [in] Comparison tolerance
percent – [in] If true, the relative difference between “c” and “expectedVals” is checked. Otherwise, the absolute difference is checked.
-
double assertEquals(const CTile &c, const std::string &title, const std::vector<std::complex<double>> &expectedVals, double eps = 1e-6, bool percent = false) const#
Asserts that “c” and “expectedVals” are considered equal.
“c” and “expectedVals” will be considered equal if when decrypting and decoding “c” into a vector, v, one of the following holds:
percent == false and fabs(v[i] - expectedVals[i]) < eps, foreach i.
percent == true and fabs(v[i] - expectedVals[i]) / fabs(v[i]) < eps, foreach i. The maximum found absolute or relative difference (depending on the value of “percent” flag) is returned.
- Parameters:
c – [in] The CTile to compare with expectedVals
title – [in] The title used in case of printing a failure message.
expectedVals – [in] The vector to compare with “c”.
eps – [in] Comparison tolerance
percent – [in] If true, the relative difference between “c” and “expectedVals” is checked. Otherwise, the absolute difference is checked.
-
inline const AbstractEncoder &getImpl() const#
Reserved for debugging and internal use.
-
Encoder(const HeContext &he)#