CTileTensor#

class CTileTensor#

An encrypted 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 ciphertexts.

add(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor) None#

Elementwise add with other CTileTensor. Relies on CTile::add.

Parameters:

other (CTileTensor) – other CTileTensor to add.

add_dim(self: pyhelayers.CTileTensor, place: int = -1) None#

Adds a dim with original size and tile size 1 to this tensor at given place. :param place: Place of the new dimension, default is last. :type place: int

add_plain(self: pyhelayers.CTileTensor, other: pyhelayers.PTileTensor) None#

Elementwise add with other (plaintext) PTileTensor. Relies on CTile::add_plain.

Parameters:

other (PTileTensor) – other PTileTensor to add.

add_plain_raw(self: pyhelayers.CTileTensor, other: pyhelayers.PTileTensor) None#

Elementwise add with other (plaintext) PTileTensor. Relies on CTile::add_plain_raw.

Parameters:

other (PTileTensor) – other PTileTensor to add.

add_raw(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor) None#

Elementwise add with other CTileTensor. Relies on CTile::add_raw.

Parameters:

other (CTileTensor) – other CTileTensor to add.

add_scalar(self: pyhelayers.CTileTensor, scalar: float, keep_unknowns_clear: bool = False) None#

adds a double scalar value to all elements of this tensor.

Parameters:
  • scalar (double) – double value to add.

  • keep_unknowns_clear (boolean) – the default is ‘false’.

adjust_chain_index(self: pyhelayers.CTileTensor, chain_index: int) None#

Calls corresponding function for every CTile.

Parameters:

chain_index (int) – The required chain index.

clear_unknowns(self: pyhelayers.CTileTensor) None#

Clears all unknowns from this tile tensor.

duplicate_over_dim(self: pyhelayers.CTileTensor, dim: int) None#

Cause a dimension to become duplicated

Parameters:

dim (int) – The dimension to duplicate.

flatten(*args, **kwargs)#

Overloaded function.

  1. flatten(self: pyhelayers.CTileTensor, start_dim: int, end_dim: int) -> None

    Flattens consecutive fully-duplicated dimensions into a single fully-duplicated dimension. The Flattened dimension will have tile size equals to the product of tile sizes of all the flattened dimensions, and will be considered interleaved if and only if all the flattened dimensions are.

    param start_dim:

    The first dimension to be flattened.

    type start_dim:

    int

    param end_dim:

    The dimension in which to end the flattening (exclusive). Flatten(a, b) will flatten dimensions [a,b).

    type end_dim:

    int

    raises RuntimeError:

    If the specified dimensions do not exist, or are not fully duplicated, or if startDim >= endDim.

  2. flatten(self: pyhelayers.CTileTensor, start_dim: int, end_dim: int) -> pyhelayers.CTileTensor

    Returns the result of Flattening consecutive fully-duplicated dimensions into a single fully-duplicated dimension. See also CTileTensor::flatten.

    param start_dim:

    The first dimension to be flattened.

    type start_dim:

    int

    param end_dim:

    The dimension in which to end the flattening (exclusive). Flatten(a, b) will flatten dimensions [a,b).

    type end_dim:

    int

    raises RuntimeError:

    If the specified dimensions do not exist, or are not fully duplicated, or if startDim >= endDim.

get_add_plain(self: pyhelayers.CTileTensor, plain: pyhelayers.PTileTensor) pyhelayers.CTileTensor#

Returns the result of elementwise add of this and other PTileTensor. Relies on CTile::addPlain.

Parameters:

plain (PTileTensor) – Other PTileTensor to add.

get_add_plain_raw(self: pyhelayers.CTileTensor, plain: pyhelayers.PTileTensor) pyhelayers.CTileTensor#

Returns the result of elementwise add of this and other PTileTensor. Relies on CTile::addPlainRaw.

Parameters:

plain (PTileTensor) – Other PTileTensor to add.

get_add_scalar(self: pyhelayers.CTileTensor, val: float) pyhelayers.CTileTensor#

Returns the result of elementwise add of this and the given scalar.

Parameters:

val (double) – Scalar to add.

get_chain_index(self: pyhelayers.CTileTensor) int#

Returns chain index of tiles. They are maintained to have equal chain index.

get_clear_unknowns(self: pyhelayers.CTileTensor) pyhelayers.CTileTensor#

Returns the result of clearing all unknowns.

get_convolution(self: pyhelayers.CTileTensor, filters: pyhelayers.CTileTensor, biases: pyhelayers.CTileTensor, stride_rows: int, stride_cols: int) pyhelayers.CTileTensor#

Returns the result of applying convolution with the given parameters.

Parameters:
  • filters (CTileTensor) – The filters to convolute with.

  • biases (CTileTensor) – The biases to add.

  • stride_rows (int) – Stride rows parameter to use during the convolution.

  • stride_cols (int) – Stride cols parameter to use during the convolution.

get_duplicate_over_dim(self: pyhelayers.CTileTensor, dim: int) pyhelayers.CTileTensor#

Returns the result of duplicating the specified dimension.

Parameters:

dim (int) – The dimension to duplicate.

get_matrix_multiplication(self: pyhelayers.CTileTensor, other: pyhelayers.TileTensor, sum_dim: int) pyhelayers.CTileTensor#

Computes matrix-vector multiplication with other. For non-diagonalized computation, it calls get_multiply_and_sum() (See documentation in get_multiply_and_sum())

For diagonalization, other shape should be diagonalized. For example: Other is a matrix [(d)16/t1,6/t2,1/t3] This is a vector [16/t1*t2,1/t3] Result is [*/t1,6/t2,1/t3]

Constraints: - other should be diagonalized - this should not be diagonalized - this tile size 0 should equal other tileSize0*tileSize1 - this original size 0 should equal other original size 0 - this dims 1..end should be identical to other dims 2..end. (will be extended to support comptability) - sumDim must be 0

Parameters:
  • other – Other tile tensor to multiply with

  • sumDim – Dimension to sum over.

get_multiply_and_sum(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor, sum_dim: int) pyhelayers.CTileTensor#

Returns the result of elementwise multiplication and summation between this and other. See CTileTensor::multiplyAndSum for usage examples.

Parameters:
  • other (CTileTensor) – Other encoded tile tensor.

  • sumDim – Dimension to sum over.

get_multiply_plain(self: pyhelayers.CTileTensor, plain: pyhelayers.PTileTensor) pyhelayers.CTileTensor#

Returns the result of elementwise multiplication of this and other PTileTensor. Relies on CTile::multiplyPlain.

Parameters:

plain (PTileTensor) – Other PTileTensor to multiply by.

get_multiply_plain_and_sum(self: pyhelayers.CTileTensor, other: pyhelayers.PTileTensor, sum_dim: int) pyhelayers.CTileTensor#

Returns the result of elementwise multiplication and summation between this and other. See CTileTensor::multiplyAndSum for usage examples.

Parameters:
  • other (PTileTensor) – Other encoded tile tensor.

  • sumDim – Dimension to sum over.

get_multiply_plain_raw(self: pyhelayers.CTileTensor, plain: pyhelayers.PTileTensor) pyhelayers.CTileTensor#

Returns the result of elementwise multiplication of this and other PTileTensor. Relies on CTile::multiplyPlainRaw.

Parameters:

plain (PTileTensor) – Other PTileTensor to multiply by.

get_multiply_scalar(self: pyhelayers.CTileTensor, val: float) pyhelayers.CTileTensor#

Returns the result of elementwise multiplication of this and the given scalar.

Parameters:

val (double) – Scalar to multiply by.

get_pseudo_rotate_along_dim(self: pyhelayers.CTileTensor, dim: int, offset: int, real_rotate: bool = False) pyhelayers.CTileTensor#

Returns the result of calling psuedoRotateAlongDim. See also pseudo_roate_along_dim().

get_reduce_chain_index(self: pyhelayers.CTileTensor) pyhelayers.CTileTensor#

Returns the result of reducing chain indexes of every CTile.

get_relinearize(self: pyhelayers.CTileTensor) pyhelayers.CTileTensor#

Returns the result of calling relinearize on every CTile.

get_rescale(self: pyhelayers.CTileTensor) pyhelayers.CTileTensor#

Returns the result of calling rescale on every CTile.

get_set_chain_index(*args, **kwargs)#

Overloaded function.

  1. get_set_chain_index(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor) -> pyhelayers.CTileTensor

    Returns the result of Calling corresponding function for every CTile.

    param other:

    CTileTensor to get chain index from.

    type other:

    CTileTensor

  2. get_set_chain_index(self: pyhelayers.CTileTensor, chain_index: int) -> pyhelayers.CTileTensor

    Returns the result of Calling corresponding function for every CTile.

    param chain_index:

    The required chain index.

    type chain_index:

    int

get_slice(self: pyhelayers.CTileTensor, dim: int, start_index: int, slice_depth: int) pyhelayers.CTileTensor#

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 sliceDepth. 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.).

  • start_index – The index to start slicing at along the dimension

  • slice_depth – The depth/size of the slice along the dimension

get_square(self: pyhelayers.CTileTensor) pyhelayers.CTileTensor#

Returns the result of elementwise squaring of this CTileTensor. Relies on CTile::square.

get_square_raw(self: pyhelayers.CTileTensor) pyhelayers.CTileTensor#

Returns the result of elementwise squaring of this CTileTensor. Relies on CTile::squareRaw.

get_sub(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor) pyhelayers.CTileTensor#

Returns the result of elementwise sub of this and other CTileTensor. Relies on CTile::sub.

Parameters:

other (CTileTensor) – Other CTileTensor to sub.

get_sub_plain(self: pyhelayers.CTileTensor, plain: pyhelayers.PTileTensor) pyhelayers.CTileTensor#

Returns the result of elementwise sub of this and other PTileTensor. Relies on CTile::subPlain.

Parameters:

plain (PTileTensor) – Other PTileTensor to sub.

get_sub_plain_raw(self: pyhelayers.CTileTensor, plain: pyhelayers.PTileTensor) pyhelayers.CTileTensor#

Returns the result of elementwise sub of this and other PTileTensor. Relies on CTile::subPlainRaw.

Parameters:

plain (PTileTensor) – Other PTileTensor to sub.

get_sub_raw(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor) pyhelayers.CTileTensor#

Returns the result of elementwise sub of this and other CTileTensor. Relies on CTile::subRaw.

Parameters:

other (CTileTensor) – Other CTileTensor to sub.

get_sum_in_tiles_over_dim(self: pyhelayers.CTileTensor, dim: int) pyhelayers.CTileTensor#

Returns the result of summing inside the tiles over the specified dimension.

Parameters:

dim (int) – The dimension to sum over.

get_sum_over_dim(self: pyhelayers.CTileTensor, dim: int) pyhelayers.CTileTensor#

Returns the result of summing over the specified dimension.

Parameters:

dim (int) – The dimension to sum over.

get_sum_tiles_over_dim(self: pyhelayers.CTileTensor, dim: int) pyhelayers.CTileTensor#

Returns the result of summing tiles over the specified dimension.

Parameters:

dim (int) – The dimension to sum over.

multiply(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor) None#

Elementwise multiplication with other CTileTensor. Relies on CTile::multiply.

Parameters:

other (CTileTensor) – other CTileTensor to multiply by.

multiply_and_sum(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor, sum_dim: int) None#

Performs elementwise multiplication between this and other, then sums over the specified dim. If both are vectors of same length, sum over dim 0 to get inner product.

If this is a matrix [a/t1,b/t2] and other is a vector [a/t1,*/t2], sum over dim 0 will produce the matrix-vector multiplication. Similarly for matrix [a/t1,b/t2] and vector [*/t1,b/t2], sum over dim 1.

For matrix-matrix multiplication use for example:

Matrix1 [ a/t1,b/t2,* /t3] and Matrix2 [a/t1,* / t2, c/t3], sum over dim 0.

or:

Matrix1 [ a/t1,b/t2,* /t3] and Matrix2 [* / t1,b / t2, c/t3], sum over dim 1.

Parameters:
  • other (CTileTensor) – Other encrypted tile tensor.

  • sumDim (int) – Dimension to sum over.

multiply_over_dim(*args, **kwargs)#

Overloaded function.

  1. multiply_over_dim(self: pyhelayers.CTileTensor, dim: int) -> None

    Multiplies over a dimension.

    param dim:

    The dimension to multiply over.

    type dim:

    int

  2. multiply_over_dim(self: pyhelayers.CTileTensor, dim: int) -> None

    Multiplies over a dimension.

    param dim:

    The dimension to multiply over.

    type dim:

    int

multiply_plain(self: pyhelayers.CTileTensor, other: pyhelayers.PTileTensor) None#

Elementwise multiply by other (plaintext) PTileTensor. Relies on CTile::multiply_plain.

Parameters:

other (PTileTensor) – other PTileTensor to multiply by.

multiply_plain_and_sum(self: pyhelayers.CTileTensor, other: pyhelayers.PTileTensor, sum_dim: int) None#

Performs elementwise multiplication between this and other, then sums over the specified dim. See CTileTensor::multiplyAndSum for usage examples.

Parameters:
  • other (PTileTensor) – Other encoded tile tensor.

  • sumDim – Dimension to sum over.

multiply_plain_raw(self: pyhelayers.CTileTensor, other: pyhelayers.PTileTensor) None#

Elementwise multiply by other (plaintext) PTileTensor. Relies on CTile::multiply_plain_raw.

Parameters:

other (PTileTensor) – other PTileTensor to multiply by.

multiply_raw(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor) None#

Elementwise multiplication with other CTileTensor. Relies on CTile::multiply_raw.

Parameters:

other (CTileTensor) – other CTileTensor to multiply by.

multiply_scalar(*args, **kwargs)#

Overloaded function.

  1. multiply_scalar(self: pyhelayers.CTileTensor, scalar: int) -> None

    Multiplies all used tensor elements by a given integer scalar. May consume one chain index. This variant doesn’t clear unknowns. Refer to multiply_scalar(double) that does.

    param scalar:

    int value to multiply by.

    type scalar:

    int

  2. multiply_scalar(self: pyhelayers.CTileTensor, scalar: float) -> None

    Multiplies all used tensor elements by a given scalar. Consumes one chain index. As a side effect, unused elements will be zeroed, thus unknown unused elements will be eliminated.

    param scalar:

    double value to multiply by.

    type scalar:

    double

multiply_scalar_raw(self: pyhelayers.CTileTensor, scalar: float) None#

Elementwise multiply_scalar_raw. Relies on CTile.multiply_scalar_raw. This variant doesn’t clear unknowns. Refer to multiply_scalar(double) that does.

Parameters:

scalar (double) – double value to multiply by.

negate(self: pyhelayers.CTileTensor) None#

Elementwise negate. Relies on CTile::negate.

pseudo_rotate_along_dim(self: pyhelayers.CTileTensor, dim: int, offset: int, real_rotate: bool = False) None#

Applies a “pseudo rotation” on this CTileTensor by the given offset along dimension “dim”. If “realRotate” is true, the function verifies that a real rotate is performed, meaning that the values that fall out of one end must cycle back to the other end. If “realRotate” is false, a pseudo rotation is performed, meaning that the values that fall out of one end are not guaranteed to cycle back to the other end. To Perform a real rotation, “dim” must be the first non-trivial dimension and it mustn’t contain any unused slots. In both cases (a real or a pseudo rotate), if the external size of “dim” is not 1, then “dim” must be interleaved. If the external size of “dim” is 1, the rotation works and will have the same effect regardless of the interleaved flag being on or off. :param dim: The dimension to rotate along. :type dim: int :param offset: The rotation offset. :type offset: int :param real_rotate: If true, the function asserts that a true

rotation is performed.

Raises:

ValueError – If the rotated dimension does not satisfy the

above requirements.

re_encrypt(self: pyhelayers.CTileTensor) None#

Decrypt the CTileTensor and encrypts it again to bring it to top chain index.

reduce_chain_index(self: pyhelayers.CTileTensor) None#

Calls corresponding function for every CTile.

relinearize(self: pyhelayers.CTileTensor) None#

Calls corresponding function for every CTile

relinearize_and_rescale(self: pyhelayers.CTileTensor) None#

Calls corresponding function for every CTile

rescale(self: pyhelayers.CTileTensor) None#

Calls corresponding function for every CTile

rotate_along_dim(self: pyhelayers.CTileTensor, dim: int, rot: int) None#

Rotates this CTileTensor along the specified dimension (index (i+rot) % originalSize moves to i). The elements that fall out of one end cycle back in the other end. If the external size of “dim” is not 1, then “dim” must be interleaved. If the external size of “dim” is 1, the rotation works and will have the same effect regardless of the interleaved flag being on or off. For the rotation to succeed, “dim” must be the first non-trivial” dimension, and it must not contain any unused slots.

Parameters:
  • dim (int) – The dimension to rotate along.

  • rot (int) – The rotation offset.

Raises:

ValueError – If the rotated dimension does not satisfy the

above requirements.

set_chain_index(*args, **kwargs)#

Overloaded function.

  1. set_chain_index(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor) -> None

    Calls corresponding function for every CTile.

    param other:

    CTileTensor to get chain index from.

    type other:

    CTileTensor

  2. set_chain_index(self: pyhelayers.CTileTensor, chain_index: int) -> None

    Calls corresponding function for every CTile.

    param chain_index:

    The required chain index.

    type chain_index:

    int

square(self: pyhelayers.CTileTensor) None#

Elementwise square. Relies on CTile::square.

square_raw(self: pyhelayers.CTileTensor) None#

Elementwise square. Relies on CTile::squareRaw.

sub(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor) None#

Elementwise sub with other CTileTensor. Relies on CTile::sub.

Parameters:

other (CTileTensor) – other CTileTensor to subtract.

sub_plain(self: pyhelayers.CTileTensor, other: pyhelayers.PTileTensor) None#

Elementwise sub with other (plaintext) PTileTensor. Relies on CTile::sub_plain.

Parameters:

other (PTileTensor) – other PTileTensor to subtract.

sub_plain_raw(self: pyhelayers.CTileTensor, other: pyhelayers.PTileTensor) None#

Elementwise sub with other (plaintext) PTileTensor. Relies on CTile::sub_plain_raw.

Parameters:

other (PTileTensor) – other PTileTensor to subtract.

sub_raw(self: pyhelayers.CTileTensor, other: pyhelayers.CTileTensor) None#

Elementwise sub with other CTileTensor. Relies on CTile::sub_raw.

Parameters:

other (CTileTensor) – other CTileTensor to subtract.

sum_in_tiles_over_dim(self: pyhelayers.CTileTensor, dim: int) None#

Sums inside tiles over a dimension.

Parameters:

dim (int) – The dimension to sum inside tiles over it.

sum_over_dim(self: pyhelayers.CTileTensor, dim: int) None#

Sums over a dimension.

Parameters:

dim (int) – The dimension to sum over.

sum_tiles_over_dim(self: pyhelayers.CTileTensor, dim: int) None#

Sums tile over a dimension.

Parameters:

dim (int) – The dimension to sum over.