fhelium.rng.csprng
Csprng
class View source
Csprng(num_coefs: int=2 ** 15, num_channels: Sequence[int]=(8,), num_repeating_channels: int=2, sigma: float=3.19, devices: Sequence[torch.device | str] | None=None, torch_dtype: torch.dtype=torch.int64, seed: Any=None, nonce: Any=None)FHElium adapter around the standalone triton_csprng package.
The adapter supplies CKKS-specific channel and sampling configuration while delegating ChaCha20 stream generation to the standalone package.
Parameters
num_coefs: Coefficients generated per channel.num_channels: Independent channel count per device, or one count to repeat for every device.num_repeating_channels: Channel count reproduced across devices.sigma: Standard deviation for discrete-Gaussian sampling.devices: CPU or CUDA devices that own generator streams. Defaults to every visible CUDA device.torch_dtype: Integral dtype returned to the engine.seed: Optional key material accepted bytriton-csprng. Fixed seed material is appropriate for controlled tests, not an application production-entropy policy.nonce: Optional base nonce accepted bytriton-csprng. The caller owns nonce uniqueness across independent generator instances.
sigma
property
sigma: floatDiscrete-Gaussian standard deviation fixed at construction.
randbytes
method
def randbytes(shares: list[int] | None=None, repeats: int=0, reshape: bool=False) -> list[torch.Tensor]: ...randint
method
def randint(amax: int | list[list[int]], shift: int=0, repeats: int=0) -> list[torch.Tensor]: ...discrete_gaussian
method
def discrete_gaussian(non_repeats: int | list[int]=0, repeats: int=1) -> list[torch.Tensor]: ...randround
method
def randround(coef: torch.Tensor, *, dtype: torch.dtype | None=None) -> torch.Tensor: ...stochastic_round_
function View source
def stochastic_round_(values: torch.Tensor, state: torch.Tensor, *, word_stride: int=1) -> torch.Tensor: ...Round signed values using an advancing ChaCha20 word stream.
word_stride selects every corresponding word of a logically expanded coefficient array and advances over the complete array, including omitted zero coefficients. It does not repeat or reseed the random stream.
state holds the sixteen ChaCha20 state words followed by the position within its current sixteen-word block, all stored as int64. Counter words 12 and 13 and position 16 advance in place. Key and nonce words are retained. The high counter word may equal 2**32 only to mark an exhausted stream.