PTileTensor#
- class PTileTensor#
A plaintext tile tensor. A tile tensor is an data structure for storing tensors (multipy 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 (multipy 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:
i – Index of 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 previoud 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.
-
virtual void sleep() override#
If Ptiles, if lazyMode is LAZY_ENCODING, clear all the tiles.
-
virtual void wakeup() override#
If Ptiles, encodes data if lazyMode is LAZY_ENCODING, and does nothing else.
-
void setRawData(const DoubleTensor &newRawData)#
-
virtual void setLazyChainIndex(int newChainIndex) override#
-
virtual int getNumUsedTiles() const override#
Returns the number of tiles this tile tensor uses.
Public Static Functions
-
static inline bool doesExternalFirstDimRunFirst()#
Returns whether we use the first-order convention for the external tensor.
-
static PTileTensor createFromPTileVector(const HeContext &he, const TTShape &shape, const std::vector<PTile> &tilesVec)#
Creates a PTileTensor from the given vector of PTiles.
“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), not to contain any duplicated dims and to have all unused slots unknown.
- 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#