1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::math::random::{Gaussian, RandomGenerable, RandomGenerator};
use crate::math::tensor::Tensor;
use crate::math::torus::UnsignedTorus;
use concrete_commons::dispersion::DispersionParameter;
pub struct SecretRandomGenerator(RandomGenerator);
impl SecretRandomGenerator {
pub fn new(seed: Option<u128>) -> SecretRandomGenerator {
SecretRandomGenerator(RandomGenerator::new(seed))
}
pub fn remaining_bytes(&self) -> Option<usize> {
self.0.remaining_bytes()
}
pub fn is_bounded(&self) -> bool {
self.0.is_bounded()
}
pub(crate) fn random_binary_tensor<Scalar>(&mut self, length: usize) -> Tensor<Vec<Scalar>>
where
Scalar: UnsignedTorus,
{
self.0.random_uniform_binary_tensor(length)
}
pub(crate) fn random_ternary_tensor<Scalar>(&mut self, length: usize) -> Tensor<Vec<Scalar>>
where
Scalar: UnsignedTorus,
{
self.0.random_uniform_ternary_tensor(length)
}
pub(crate) fn random_uniform_tensor<Scalar>(&mut self, length: usize) -> Tensor<Vec<Scalar>>
where
Scalar: UnsignedTorus,
{
self.0.random_uniform_tensor(length)
}
pub(crate) fn random_gaussian_tensor<Scalar>(&mut self, length: usize) -> Tensor<Vec<Scalar>>
where
(Scalar, Scalar): RandomGenerable<Gaussian<f64>>,
Scalar: UnsignedTorus,
{
self.0
.random_gaussian_tensor(length, 0.0, Scalar::GAUSSIAN_KEY_LOG_STD.get_standard_dev())
}
}