PTileTensor#
- class PTileTensor#
A plaintext tile tensor. A tile tensor is an data structure for storing tensors (multiply dimensional arrays, e.g., vectors, matrices, or higher dimensional arrays) in a set of fixed size tiles, in this case plaintexts.
- get_chain_index(self: pyhelayers.PTileTensor) int #
Returns chain index of tiles. They are maintained to have equal chain index.
- get_reduce_chain_index(self: pyhelayers.PTileTensor) pyhelayers.PTileTensor #
Returns the result of reducing chain indexes of every PTile.
- get_set_chain_index(*args, **kwargs)#
Overloaded function.
get_set_chain_index(self: pyhelayers.PTileTensor, other: pyhelayers.PTileTensor) -> pyhelayers.PTileTensor
Returns the result of Calling corresponding function for every PTile.
- param other:
PTileTensor to get chain index from.
- type other:
PTileTensor
get_set_chain_index(self: pyhelayers.PTileTensor, chain_index: int) -> pyhelayers.PTileTensor
Returns the result of Calling corresponding function for every PTile.
- param chain_index:
The required chain index.
- type chain_index:
int
- reduce_chain_index(self: pyhelayers.PTileTensor) None #
Calls corresponding function for every PTile.
- set_chain_index(*args, **kwargs)#
Overloaded function.
set_chain_index(self: pyhelayers.PTileTensor, other: pyhelayers.PTileTensor) -> None
Calls corresponding function for every PTile.
- param other:
PTileTensor to get chain index from.
- type other:
PTileTensor
set_chain_index(self: pyhelayers.PTileTensor, chain_index: int) -> None
Calls corresponding function for every PTile.
- param chain_index:
The required chain index.
- type chain_index:
int
-
class PTileTensor : public helayers::TileTensor#
An encoded tile tensor.
A tile tensor is a data structure for storing tensors (multiply dimensional arrays, e.g., vectors, matrices, or higher dimensional arrays) in a set of fixed size tiles, in this case PTile-s (encoded data).
Public Types
-
typedef boost::numeric::ublas::first_order tensorFormat#
Defines flattening convention of the external tensor to be first-order.
-
typedef boost::numeric::ublas::tensor<PTile, tensorFormat> ExternalTensorType#
Underlying type used to store the external tensor.
Public Functions
-
PTileTensor(const HeContext &he)#
Construct an empty PTileTensor object.
- Parameters:
he – The HE context
-
PTileTensor(const PTileTensor &src)#
Copy constructor.
- Parameters:
src – [in] object to copy
-
PTileTensor(const HeContext &he, const TTShape &s)#
Construct an object of a certain chape.
- Parameters:
he – [in] the context
s – [in] shape of new object
-
~PTileTensor()#
-
PTileTensor &operator=(const PTileTensor &src)#
Copy other tile tensor to this one.
- Parameters:
src – [in] object to copy
-
inline virtual const PTile &getTileAt(const std::vector<DimInt> &inds) const override#
Returns the tile specified by the given indices.
- Parameters:
inds – Indices of tiles. Their number should match the number of dimensions, except trailing trivial dimensions where the external size is 1 which may be omitted.
-
virtual const PTile &getTileByFlatIndex(DimInt i) const override#
Returns the i’th tile in a flattened order according to the first-order convention.
- Parameters:
ind – Index of tile
-
virtual PTile *getTileByFlatIndexLazy(DimInt ind, const std::vector<int> &mask = {}) const override#
Returns a single tile of this tile tensor.
This method is only applicable in the below two cases: (1) if isSleeping() is true, and the lazy mode is LAZY_ENCODING, i.e., a lazy-encoded tile tensor not being in a packed state. (2) if isSleeping() is false, and lazyGpu mode is enabled. In this case, the tile will be moved to the GPU. For both cases 1 and 2 above, the returned tile is a pointer that should be deleted by the caller.
- Parameters:
flatIndex – Flat index of tile.
mask – Optional mask to multiply tile with. Default: none (empty). Not applicable for case (2) above.
- Returns:
A caller-owned pointer to tile.
-
void setChainIndex(const PTileTensor &other)#
Calls setChainIndex for every CTile.
- Parameters:
other – Other tile tensor to match chain index
-
void setChainIndex(int chainIndex)#
Calls setChainIndex for every CTile.
- Parameters:
chainIndex – value of chain index
-
virtual int getChainIndex() const override#
Returns chain index of tiles.
They are maintained to have equal chain index.
-
PTileTensor getReduceChainIndex() const#
Returns result after calling reduceChainIndex()
-
PTileTensor getSetChainIndex(const PTileTensor &other) const#
Returns result after calling setChainIndex()
- Parameters:
other – Other tile tensor to match chain index
-
PTileTensor getSetChainIndex(int chainIndex) const#
Returns result after calling setChainIndex()
- Parameters:
chainIndex – value of chain index
-
virtual void debugPrint(const std::string &title = "", Verbosity verbosity = VERBOSITY_REGULAR, std::ostream &out = std::cout) const override#
Prints the content of this object.
- Parameters:
title – Text to add to the print
verbosity – Verbosity level
out – Output stream
-
virtual double assertIntegrity(double epsilon = 1e-6) const override#
Validates the integrity of the tile tensor.
Used for internal checks only. Returns the maximal diff found. If uninitialized, returns 0
- Parameters:
epsilon – Tolerance for diffs.
- Throws:
runtime_error – if test fails
-
virtual CTileTensor getMultiply(const CTileTensor &other) const override#
Returns the result of elementwise multiplication of this and other CTileTensor.
Relies on CTile::multiply.
- Parameters:
other – [in] other CTileTensor to multiply.
-
virtual CTileTensor getMultiplyRaw(const CTileTensor &other) const override#
Returns the result of elementwise multiplication of this and other CTileTensor.
Relies on CTile::multiplyRaw.
- Parameters:
other – [in] other CTileTensor to multiply.
-
virtual CTileTensor getAdd(const CTileTensor &other) const override#
Returns the result of elementwise add of this and other CTileTensor.
Relies on CTile::add.
- Parameters:
other – [in] other CTileTensor to add.
-
virtual CTileTensor getAddRaw(const CTileTensor &other) const override#
Returns the result of elementwise add of this and other CTileTensor.
Relies on CTile::addRaw.
- Parameters:
other – [in] other CTileTensor to add.
-
virtual void addTo(CTileTensor &other) const override#
Equivalent to other.add(*this)
- Parameters:
other – [in] other CTileTensor to add.
-
virtual void addToRaw(CTileTensor &other) const override#
See addTo()
-
virtual void subFrom(CTileTensor &other) const override#
Equivalent to other.sub(*this)
- Parameters:
other – [in] other CTileTensor to subtract from.
-
virtual void subFromRaw(CTileTensor &other) const override#
See subFrom()
-
virtual void multiplyTo(CTileTensor &other) const override#
Equivalent to other.multiply(*this)
- Parameters:
other – [in] other CTileTensor to multiply to
-
virtual void multiplyToRaw(CTileTensor &other) const override#
See multiplyTo()
-
virtual CTileTensor getMultiplyAndSum(const CTileTensor &other, int dim) const override#
Returns the result of elementwise multiplication of this and other and summing over specified dim.
See CTileTensor::multiplyAndSum for usage examples.
- Parameters:
other – Other encrypted tile tensor
dim – Dimension to sum over
-
PTileTensor getSlice(DimInt dim, DimInt startIndex, DimInt sliceDepth = 1) const#
Returns a slice of the tensor in specific dimension.
Result has the same number of dimensions as the original tensor. For dim with tile size of 1, getSlice is supported for every valid startIndex and sliceDepthThe. For a non-interleaved dim with tile size > 1, getSlice is supported only for startIndex which is a multiple of the tile size. For interleaved dim with tile size > 1, getSlice is supported only for startIndex 0.
- Parameters:
dim – The dimension to slice along. Specifying negative value will count from the last dim backwards (-1 for the last dim, -2 for the previous one etc.).
startIndex – The index to start slicing at along the dimension
sliceDepth – The depth/size of the slice along the dimension
- Throws:
invalid_argument – If the given dimension is greater or equal to the total number of dimensions in this TileTensor
invalid_argument – If startIndex + sliceDepth is greater than the original size of the given dimension.
invalid_argument – If the tile size of the given dimension is different than 1.
-
virtual void multiplyAndSumTo(CTileTensor &other, int dim) const override#
Equivalent to other.multiplyPlainAndSum(*this, dim)
- Parameters:
other – Other encrypted tile tensor
dim – Dimension to sum over
-
inline virtual int32_t getContextId() const override#
Returns the contextId of the HeContext this object was initialized with.
This contextId can be used, for example, to verify HeContext match when loading a saved Saveable object. Returning -1 signals no HeContext.
-
virtual void sleep(bool shouldSaveToFile = false) override#
Clears data if lazyMode is LAZY_ENCODING or LAZY_LOADING, also saves data to disk if lazyMode is LAZY_LOADING and shouldSaveToFile flag is true, and does nothing otherwise.
- Parameters:
shouldSaveToFile – Whether to also save data to disk if lazyMode is LAZY_LOADING.
-
virtual void wakeup() override#
Encodes data if lazyMode is LAZY_ENCODING, loads data if lazyMode is LAZY_LOADING, and does nothing otherwise.
-
void setRawData(const DoubleTensor &newRawData)#
-
void clearRawData()#
-
void setRawDataComplex(const ComplexTensor &newRawData)#
Public Static Functions
-
static inline bool doesExternalFirstDimRunFirst()#
Returns whether we use the first-order convention for the external tensor.
-
static PTileTensor internalCreateFromPTileVector(const HeContext &he, const TTShape &shape, const std::vector<PTile> &tilesVec)#
Creates a PTileTensor from the given vector of PTiles.
This method is for implementing operators that modify PTileTensor objects, and requires careful testing. Use assertIntegrity() in tests to make sure the result is in a consistent state.
“tilesVec” vector is expected to have a first-order orientation. The created PTileTensor will have the given shape, which is assumed to be complete (i.e. with all original sizes set).
- Parameters:
he – The HeContext to initialize the created PTileTensor with.
shape – The shape of the resulting PTileTensor.
tilesVec – The vector of PTiles, in first-order orientation.
- Throws:
invalid_argument – If “shape” doesn’t satisfy the above assumptions.
-
typedef boost::numeric::ublas::first_order tensorFormat#