encode_pytorch_tensor_to_light_plaintext
Engine.encode_pytorch_tensor_to_light_plaintext(tensor, level)- Encodes a PyTorch tensor into a light plaintext format for multiplication.
The tensor's device can be either CPU or CUDA and must match that of the engine.
The message is encoded in segments of length
Engine.slot_count. If the message length is not divisible by the slot count, the remaining slots are padded with zeros during encoding. The recommended range of values to encode is[-1, 1].
- Input:
- tensor: torch.Tensor
- level: optional
- Should be set to the level of the ciphertext that the light plaintext will be multiplied to.
- The level should be an integer greater than or equal to 1.
- Output:
- LightPlaintext
Examples
CPU
import torch
from desilofhe import Engine
engine = Engine()
tensor = torch.tensor([1, 2, 3, 4])
encoded = engine.encode_pytorch_tensor_to_light_plaintext(tensor)
encoded_level_2 = engine.encode_pytorch_tensor_to_light_plaintext(
tensor, level=2
)
GPU