CTile#

class CTile#

A class representing a ciphertext.

It’s called a CTile because from a high-level point of view we’ll usually use several of these combined for holding a more complicated object such as a matrix. For a lower level documentation of different functionalities (such as the effect on chainIndex), see documentation of the underlying encryption scheme.

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

Add content of another ciphertext to this one, elementwise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use add_raw() to get the scheme’s raw addition operation.

Parameters:

other – Other ciphertext to add.

add_plain(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

Add content of another PTile to this one, elementwise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use add_plain_raw() to get the scheme’s raw addition operation.

Parameters:

other – Other PTile to add.

add_plain_raw(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

See add_plain().

Parameters:

other – Other PTile to add.

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

See add().

Parameters:

other – Other ciphertext to add.

add_scalar(*args, **kwargs)#

Overloaded function.

  1. add_scalar(self: pyhelayers.CTile, scalar: complex) -> None

    Adds a complex scalar value to all slots in this ciphertext. :param scalar: value to add. :type scalar: complex

  2. add_scalar(self: pyhelayers.CTile, scalar: float) -> None

    Adds a double scalar value to all slots in this ciphertext.

    param scalar:

    value to add.

    type scalar:

    float

  3. add_scalar(self: pyhelayers.CTile, scalar: int) -> None

    Adds an integer scalar value to all slots in this ciphertext.

    param scalar:

    integer value to add.

    type scalar:

    int

add_tile(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

Calls add(CTile) or add_plain(PTile) depending on argument type.

Parameters:

other – Other object to add.

add_tile_raw(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

See add_tile().

Parameters:

other – Other object to add.

assert_correct_scale(self: pyhelayers.CTile, message: str = '', warn_epsilon: float = 1e-20, error_epsilon: float = 1e-10, fix: bool = True, target_scale: float = -1) None#

Verify this CTile has a correct scale, and optionally correct it.

Parameters:
  • message – Message to include in case of warning or error. Defaults to an empty string

  • warn_epsilon – Warn epsilon. Defaults to 1e-20.

  • error_epsilon – Error epsilon. Defaults to 1e-10.

  • fix – If True the scale is fixed if to target scale. Defaults to True

  • target_scale – The scale to test with and to fix. If set to -1, the usual accurate scale for this level is used. Defaults to -1.

bootstrap(self: pyhelayers.CTile) None#

Bootstrap this CTile, if this is supported by the underlying HeContext. Bootstrapping will raise the chain index of this CTile, allowing more multiplications to be done. However, this operation is likely to be time-consuming, and may add noise to the ciphertext in some schemes (such as CKKS). Bootstrapping is only supported if the HeContext used to create this CTile was initialized to be bootstrappable (see also HeConfigRequirement::bootstrappable). :raises RuntimeError: If the HeContext used to create this CTile is

not bootstrappable.

clear_last_n_slots(self: pyhelayers.CTile, arg0: int) None#

Sets the last n slots of this CTile to 0, by multiplying it with a relevant mask. If n is 0, does nothing.

Parameters:

n – The number of slots to clear.

Raises:

ValueError – If n is negative or greater than the number of slots.

conjugate(self: pyhelayers.CTile) None#

Conjugates contents of this CTile in place, elementwise. For non-complex numbers this has no effect. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use conjugate_raw() to get the scheme’s raw conjugate operation.

conjugate_raw(self: pyhelayers.CTile) None#

See conjugate().

get_conjugate(self: pyhelayers.CTile) pyhelayers.CTile#

Returns the result of conjugating contents of this CTile, elementwise. For non-complex numbers this has no effect. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use conjugateRaw() to get the scheme’s raw conjugate operation.

get_current_device(self: pyhelayers.CTile) Tuple[pyhelayers.DeviceType, int]#

Returns the current device of this CTile.

Return type:

DeviceType, int

get_estimated_memory_usage_bytes(self: pyhelayers.CTile) int#

Returns an estimation of the memory usage, or -1 if not supported.

get_he_context(self: pyhelayers.CTile) pyhelayers.HeContext#

Returns the HE context used to initialize this CTile.

get_multiply(self: pyhelayers.CTile, other: pyhelayers.CTile) pyhelayers.CTile#

Returns the result of multiplication of this and other CTile. Relies on CTile::multiply().

Parameters:

other – Other ciphertext to multiply.

get_size(self: pyhelayers.CTile) int#

Returns the number of polynomials in the ciphertext (as reduced via relinearization).

Return type:

int

inner_sum(*args, **kwargs)#

Overloaded function.

  1. inner_sum(self: pyhelayers.CTile) -> None

    Computes the inner sum of all of the ciphertext’s slots. Performs the computation by repeated rotations and additions, with rotations 1, 2, 4, up to slotCount (exclusive). The result is duplicated in all slots.

  2. inner_sum(self: pyhelayers.CTile, rot1: int, rot2: int, reverse: bool = False) -> None

    Computes the inner sum of some of the ciphertext’s slots. Performs the computation by repeated rotations and additions, with rotations rot1, 2*rot1, 4*rot2, up to rot2 (exclusive). Using this method properly is complicated, and is used by some higher level algorithms.

    param rot1:

    First rotation in the rotate-and-add loop.

    type int1:

    int

    param rot2:

    Last rotation (exclusive) in the rotate-and-add loop.

    type rot2:

    int

    param reverse:

    If true, flips all rotations (left to right and vice versa). Defaults to false.

    type reverse:

    bool

is_empty(self: pyhelayers.CTile) bool#

Returns true if this CTile does not include an encryption of any value, and false otherwise.

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

Multiply another ciphertext with this one, elementwise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use multiplyRaw() to get the scheme’s raw addition operation.

Parameters:

other – Other ciphertext to multiply.

multiply_by_changing_scale(self: pyhelayers.CTile, factor: float) None#

Multiply this ciphertext by a scalar double value, elementwise, by a light-weight scale changing. This multiplies every slot by the given factor. The operation is done by changing the scale meta-data combined with this ciphertext, and is therefore extremely fast. It is not available for all underlying schemes, and also may cause difficulties down the line due to mismatching scales.

Parameters:

factor (float) – factor to multiply with.

Raises:

RuntimeError – If not supported.

multiply_imaginary_unit(self: pyhelayers.CTile) None#

Multiplies all slots in this ciphertext with the imaginary unit (i).

multiply_plain(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

Multiply the content this PTile by another one, elementwise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use multiply_plain_raw() to get the scheme’s raw multiplication operation.

Parameters:

other – Other PTile to multiply.

multiply_plain_raw(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

See multiply_plain().

Parameters:

other – Other PTile to multiply.

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

See multiply().

Parameters:

other – Other ciphertext to multiply.

multiply_scalar(*args, **kwargs)#

Overloaded function.

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

    Multiplies all slots in this ciphertext with an integer scalar value.

    param scalar:

    integer value to multiply.

    type scalar:

    int

  2. multiply_scalar(self: pyhelayers.CTile, scalar: complex) -> None

    Multiplies all slots in this ciphertext with a complex scalar value. :param scalar: value to multiply. :type scalar: complex

  3. multiply_scalar(self: pyhelayers.CTile, scalar: float) -> None

    Multiplies all slots in this ciphertext with a double scalar value.

    param scalar:

    value to multiply.

    type scalar:

    float

multiply_scalar_raw(*args, **kwargs)#

Overloaded function.

  1. multiply_scalar_raw(self: pyhelayers.CTile, scalar: complex) -> None

    See multiply_scalar().

    param scalar:

    value to multiply.

    type scalar:

    complex

  2. multiply_scalar_raw(self: pyhelayers.CTile, scalar: float) -> None

    See multiply_scalar().

    param scalar:

    value to multiply.

    type scalar:

    float

multiply_tile(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

Calls multiply(CTile) or multiply_plain(PTile) depending on argument type.

Parameters:

other – Other object to multiply.

multiply_tile_raw(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

See multiply_tile().

Parameters:

other – Other object to multiply.

negate(self: pyhelayers.CTile) None#

Negates content of this ciphertext.

nullify_imaginary_part(self: pyhelayers.CTile) None#

Nullify the imaginary part of each slot in this ciphertext.

relinearize(self: pyhelayers.CTile) None#

Performs a relinearize operation (reducing ciphertext size after multiplication) The non-raw version of multiplication takes care of this automatically when needed. Ignored if not needed or not supported.

rescale(self: pyhelayers.CTile) None#

Performs a rescale operation (reducing ciphertext modulus bits and attached meta data scale). The non-raw version of multiplication takes care of this automatically. Ignored if not needed or not supported. Note that depending on scheme, this method may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use rescale_raw() to get the scheme’s raw rescale operation.

rescale_raw(self: pyhelayers.CTile) None#

See rescale().

rotate(self: pyhelayers.CTile, n: int) None#

Rotate left. For an offset of n, the element at slots 10 will move to slot 10-n. The first n elements are rotated back to be last.

Parameters:

n – Rotate offset.

square(self: pyhelayers.CTile) None#

squares contents of this CTile in place, elementwise. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use square_raw() to get the scheme’s raw square operation.

square_raw(self: pyhelayers.CTile) None#

See square().

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

Subtract the content of another CTile from this one, element-wise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use sub_raw() to get the scheme’s raw subtraction operation.

Parameters:

other – Other ciphertext to sub.

sub_plain(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

sub content of another PTile to this one, elementwise. Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use sub_plain_raw() to get the scheme’s raw subtraction operation.

Parameters:

other – Other PTile to sub.

sub_plain_raw(self: pyhelayers.CTile, other: pyhelayers.PTile) None#

See sub_plain().

Parameters:

other – Other PTile to sub.

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

See sub().

Parameters:

other – Other ciphertext to sub.

sub_tile(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

Calls sub(CTile) or sub_plain(PTile) depending on argument type.

Parameters:

other – Other object to subtract.

sub_tile_raw(self: pyhelayers.CTile, other: pyhelayers.Tile) None#

See sub_tile().

Parameters:

other – Other object to subtract.

sum_exp_by_squaring_left_to_right(self: pyhelayers.CTile, n: int) None#

Sums n slots of this ciphertext. After summing, slot i will contain the sum of slots i, i+1, i+2, …, i+n-1, where indices are cyclic, i.e., roll back to the start if run out over the edge. Summation is done similar to left-to-right repeated squaring algorithm.

Parameters:

n – number of elements to summarize.

sum_exp_by_squaring_right_to_left(self: pyhelayers.CTile, n: int) None#

Sums n slots of this ciphertext. After summing, slot i will contain the sum of slots i, i+1, i+2, …, i+n-1, where indices are cyclic, i.e., roll back to the start if run out over the edge. Summation is done similar to right-to-left repeated squaring algorithm.

Parameters:

n – number of elements to summarize.

to_device(self: pyhelayers.CTile, type: pyhelayers.DeviceType, device_id: int = 0) None#

Move this CTile to another device.

Parameters:
  • type – The device type to move to.

  • device_id – The device ID to move to. Device ID can be from 0 to n-1,

where n is the the number of devices of the specified type.