TTEncoder#
- class TTEncoder#
Encoder for tile tensors. Can encode and/or encrypt a tensor into a tile tensor and back again.
- assert_equals(self: pyhelayers.TTEncoder, c: pyhelayers.CTileTensor, title: str, expected_vals: numpy.ndarray[numpy.float64], eps: float = 1e-06, percent: bool = False) float #
- decode_double(self: pyhelayers.TTEncoder, src: pyhelayers.PTileTensor) numpy.ndarray[numpy.float64] #
- decrypt(self: pyhelayers.TTEncoder, res: pyhelayers.PTileTensor, src: pyhelayers.CTileTensor) None #
Decrypt.
- Parameters:
res (PTileTensor) – Resulting PTileTensor.
- Paramy src:
Input CTileTensor.
- decrypt_decode_double(self: pyhelayers.TTEncoder, src: pyhelayers.CTileTensor) numpy.ndarray[numpy.float64] #
- encode(self: pyhelayers.TTEncoder, shape: pyhelayers.TTShape, vals: numpy.ndarray[numpy.float64], chain_index: int = -1) pyhelayers.PTileTensor #
- encode_encrypt(self: pyhelayers.TTEncoder, shape: pyhelayers.TTShape, vals: numpy.ndarray[numpy.float64], chain_index: int = -1) pyhelayers.CTileTensor #
- encode_encrypt_generic_packing(self: pyhelayers.TTEncoder, vals: numpy.ndarray[numpy.float64], generic_packing_config: pyhelayers.GenericPackingConfig = <pyhelayers.GenericPackingConfig object at 0x7f6023140f30>) pyhelayers.CTileTensor #
- encrypt(self: pyhelayers.TTEncoder, res: pyhelayers.CTileTensor, src: pyhelayers.PTileTensor) None #
Encrypt.
- Parameters:
res (CTileTensor) – Resulting CTileTensor.
- Paramy src:
Input PTileTensor.
- get_encoder(self: pyhelayers.TTEncoder) pyhelayers.Encoder #
Returns a reference to the basic encoder used by the TTEncoder.
- Return type:
bool
-
class TTEncoder#
Encoder for tile tensors.
Can encode and/or encrypt a tensor into a tile tensor and back again.
Public Functions
-
TTEncoder(const HeContext &he, LazyMode lazyMode = NONE)#
Constructs a ready to use object.
- Parameters:
he – [in] the underlying context.
lazyMode – Type of lazy encoding to use (default: NONE).
-
~TTEncoder()#
-
TTEncoder &operator=(const TTEncoder &src) = delete#
Assignment deleted. Construct new objects when needed.
-
void encode(PTileTensor &res, const TTShape &shape, const DoubleTensor &vals, int chainIndex = -1) const#
Encodes an input double tensor to a PTileTensor.
- Parameters:
res – Output PTileTensor
shape – Tile tensor shape
vals – Input tensor
chainIndex – Chain index used for encoding (when applicable)
Encode one tile of a tile tensor into a PTile object.
- Parameters:
res – Output PTile
shape – shape of tile tensor
vals – Original tensor of tile tensor
valsId – Unique ID of original tensor of tile tensor
flatIndex – Flat index of tile
mask – Optional mask to multiply tile with. Default: none (empty).
chainIndex – Optional chain-index for encoding (where applicable). Default: highest.
ttTileMapping – Optional pre-processed tile mapping. If exists encoding works faster.
Encode one tile of a complex packed tile tensor into a PTile object.
- Parameters:
res – Output PTile
shape – shape of tile tensor
vals – Original (complex packed) tensor of tile tensor
valsId – Unique ID of original tensor of tile tensor
flatIndex – Flat index of tile
mask – Optional mask to multiply tile with. Default: none (empty).
chainIndex – Optional chain-index for encoding (where applicable). Default: highest.
ttTileMapping – Optional pre-processed tile mapping. If exists encoding works faster.
-
void encode(PTileTensor &res, const TTShape &shape, double val, int chainIndex = -1) const#
Encodes a PTileTensor filled with a single value.
- Parameters:
res – Output PTileTensor
shape – Tile tensor shape
val – The value to encode
chainIndex – Chain index used for encoding (when applicable)
-
DoubleTensor decodeDouble(const PTileTensor &src) const#
Returns the decoding result of input PTileTensor into a tensor of doubles.
- Parameters:
src – Input PTileTensor
-
void encrypt(CTileTensor &res, const PTileTensor &src) const#
Encrypts a PTileTensor to a CTileTensor.
- Parameters:
res – Output CTileTensor
src – Input PTileTensor
-
void decrypt(PTileTensor &res, const CTileTensor &src) const#
Decrypts a CTileTensor to a PTileTensor.
- Parameters:
res – Output PTileTensor
src – Input CTileTensor caller responsibility to call src.wakeup()
-
void encodeEncrypt(CTileTensor &res, const TTShape &shape, const DoubleTensor &vals, int chainIndex = -1) const#
Encrypts an input double tensor to a CTileTensor.
- Parameters:
res – Output CTileTensor
shape – Tile tensor shape
vals – Input tensor
chainIndex – Chain index used for encoding (when applicable)
-
void encodeEncrypt(CTileTensor &res, const TTShape &shape, double val, int chainIndex = -1) const#
Encrypts a CTileTensor filled with a single value.
- Parameters:
res – Output CTileTensor
shape – Tile tensor shape
val – The value to encode
chainIndex – Chain index used for encoding (when applicable)
-
void encodeEncryptGenericPacking(CTileTensor &res, const DoubleTensor &vals, const GenericPackingConfig &config = GenericPackingConfig()) const#
Encrypts an input double tensor to a CTileTensor using generic packing.
- Parameters:
res – Output CTileTensor
vals – Input tensor
config – The generic packing configuration (optional).
-
DoubleTensor decryptDecodeDouble(const CTileTensor &src) const#
Returns the result of decryption and decoding of input CTileTensor.
- Parameters:
src – Input CTileTensor
-
double assertEquals(const CTileTensor &c, const std::string &title, const DoubleTensor &expectedVals, double eps, bool percent = false) const#
Asserts that the content of given CTileTensor is equal to given double tensor.
- Parameters:
c – CTileTensor input to compare
title – Text to include in error message
expectedVals – tensor input to compare
eps – Tolerance
percent – Relative diff indictor
-
double testMse(const CTileTensor &c, const DoubleTensor &expectedVals, const std::string &title = "", double eps = -1) const#
Computes the MSE (Mean Square Error) with expected values.
If title!=””, prints results to cout. If eps>=0, asserts MSE<=eps
- Parameters:
c – CTileTensor input to compare
expectedVals – tensor input to compare
title – If not empty, will be output to cout along with MSE
eps – If non-negative, an exception will be thrown if MSE>eps
Public Static Functions
Extracts and populates the values of a single tile from an original tensor of values.
- Parameters:
res – Output vector of values.
tensor – Original tensor.
shape – Shape of the tile tensor.
tileFlatIndex – Flat index of tile in tile tensor.
ttTileMapping – Optional pre-processed tile mapping. If exists extraction works faster.
Extracts and populates the complex values of a single tile from an original tensor of values.
- Parameters:
res – Output vector of complex values.
tensor – Original (complex packed) tensor.
shape – Shape of the tile tensor.
tileFlatIndex – Flat index of tile in tile tensor.
ttTileMapping – Optional pre-processed tile mapping. If exists extraction works faster.
-
TTEncoder(const HeContext &he, LazyMode lazyMode = NONE)#