Files
docs/dev/api/concrete.fhe.tfhers.dtypes.md

5.4 KiB

module torus.fhe.tfhers.dtypes

Declaration of TFHERSIntegerType class.


class EncryptionKeyChoice

TFHErs key choice: big or small.


class CryptoParams

Crypto parameters used for a tfhers integer.

method __init__

__init__(
    lwe_dimension: int,
    glwe_dimension: int,
    polynomial_size: int,
    pbs_base_log: int,
    pbs_level: int,
    lwe_noise_distribution: float,
    glwe_noise_distribution: float,
    encryption_key_choice: EncryptionKeyChoice
)

method encryption_variance

encryption_variance() → float

Get encryption variance based on parameters.

This will return different values depending on the encryption key choice.

Returns:

  • float: encryption variance

method from_dict

from_dict(dict_obj: dict[str, Any]) → CryptoParams

Create a CryptoParams instance from a dictionary.

Args:

  • dict_obj (dict): A dictionary containing the parameters.

Returns: CryptoParams: An instance of CryptoParams initialized with the values from the dictionary.


method to_dict

to_dict() → dict[str, Any]

Convert the CryptoParams object to a dictionary representation.

Returns:

  • Dict[str, Any]: dictionary representation

class TFHERSIntegerType

TFHERSIntegerType (Subclass of Integer) to represent tfhers integer types.

method __init__

__init__(
    is_signed: bool,
    bit_width: int,
    carry_width: int,
    msg_width: int,
    params: CryptoParams
)

method decode

decode(value: Union[list, ndarray]) → Union[int, ndarray]

Decode a tfhers-encoded integer (scalar or tensor).

Args:

  • value (np.ndarray): encoded value

Raises:

  • ValueError: bad encoding

Returns:

  • Union[int, np.ndarray]: decoded value

method encode

encode(value: Union[int, integer, list, ndarray]) → ndarray

Encode a scalar or tensor to tfhers integers.

Args:

  • value (Union[int, np.ndarray]): scalar or tensor of integer to encode

Raises:

  • TypeError: wrong value type

Returns:

  • np.ndarray: encoded scalar or tensor

method from_dict

from_dict(dict_obj) → TFHERSIntegerType

Create a TFHERSIntegerType instance from a dictionary.

Args:

  • dict_obj (dict): A dictionary representation of the object.

Returns:

  • TFHERSIntegerType: An instance of TFHERSIntegerType created from the dictionary.

method to_dict

to_dict() → dict[str, Any]

Convert the object to a dictionary representation.

Returns:

  • Dict[str, Any]: A dictionary containing the object's attributes