Tensor Classes
Base Tensor
- class openfhe_numpy.tensor.tensor.BaseTensor[source]
-
- abstract clone(data=None)[source]
- Return type:
BaseTensor
[TypeVar
(T
)]- Parameters:
data (T | None)
- class openfhe_numpy.tensor.tensor.FHETensor(data, original_shape, batch_size, new_shape, order=ArrayEncodingType.ROW_MAJOR, is_padded=True)[source]
Bases:
BaseTensor
[T
],Generic
[T
]Concrete base class for tensors in FHE computation.
- Parameters:
data (T) – Underlying encrypted or encoded data.
original_shape (Tuple[int, int]) – Shape before any padding.
batch_size (int) – Total number of packed slots.
new_shape (Tuple[int, int]) – Since the shape may change after some operations, we need to store the new information.
order (int) – Packing order: only support row-major or column-major.
is_padded (bool)
- __init__(data, original_shape, batch_size, new_shape, order=ArrayEncodingType.ROW_MAJOR, is_padded=True)[source]
- property size
- property dtype
- property data: T
Underlying encrypted/plaintext payload.
- property info: Dict[str, Any]
Tuple of shape and encoding metadata.
- Returns:
Contains [None, original_shape, batch_size, ncols, order]
- Return type:
Tuple
- clone(data=None)[source]
Copy the tensor, optionally replacing the data payload.
- Return type:
BaseTensor
[TypeVar
(T
)]- Parameters:
data (T | None)
Ciphertext Array
- class openfhe_numpy.tensor.ctarray.CTArray(data, original_shape, batch_size, new_shape, order=ArrayEncodingType.ROW_MAJOR, is_padded=True)[source]
Bases:
FHETensor
[Ciphertext
]Encrypted tensor class for OpenFHE ciphertexts. This class represents encrypted tensors.
Examples
>>> # Create and encrypt a matrix >>> cc, keys = gen_crypto_context(4) >>> matrix = np.array([[1, 2], [3, 4]]) >>> encrypted = onp.array(cc, matrix, slots, keys.publicKey) >>> result = encrypted + encrypted # or add(encrypted, encrypted) >>> decrypted = result.decrypt(keys.secretKey)
- Parameters:
- tensor_priority = 10
- decrypt(secret_key, unpack_type=UnpackType.ORIGINAL, new_shape=None)[source]
Decrypt ciphertext using given secret key with flexible formatting options.
- Parameters:
secret_key (openfhe.PrivateKey) – Secret key used for decryption
unpack_type (UnpackType) – Formatting option to apply: - UnpackType.RAW: Return raw decrypted data without reshaping - UnpackType.RESHAPE: Reshape to original dimensions - UnpackType.ROUND: Reshape and round values to integers - UnpackType.AUTO: Auto-detect best format based on data
new_shape (tuple or int, optional) – Custom shape to reshape the output array to If None, uses the tensor’s original shape
- Returns:
Decrypted data with requested formatting applied
- Return type:
np.ndarray