Skip to content

Commit

Permalink
Use sin_cos to compute twisties
Browse files Browse the repository at this point in the history
  • Loading branch information
rickwebiii committed Mar 6, 2024
1 parent f773923 commit 1bf5844
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions sunscreen_tfhe/src/math/fft/negacyclic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ where

let two_pi = T::from(PI).unwrap() * T::from(2.0).unwrap();

let w_2n = (Complex::from(two_pi / n_2) * Complex::i()).exp();

let twist = (0..k)
.map(|x| w_2n.powf(T::from(x).unwrap()))
.map(|x| {
let x = T::from(x).unwrap();
let (s, c) = (two_pi * x / n_2).sin_cos();

Complex::new(c, s)
})
.collect::<Vec<_>>();

let twist_inv = twist
Expand All @@ -76,7 +79,7 @@ where
let a_a_inv = a * b;
let err = a_a_inv - Complex::one();

err.re.abs() < T::from(1e-12).unwrap() && err.im.abs() < T::from(1e-12).unwrap()
err.re.abs() < T::from(1e-15).unwrap() && err.im.abs() < T::from(1e-15).unwrap()
}));

Self {
Expand Down
4 changes: 2 additions & 2 deletions sunscreen_tfhe/src/math/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ mod tests {
let a = Polynomial::new(&a);
let b = (0..n)
.map(|_| {
let signed = (rand::thread_rng().next_u64() % 32).reinterpret_as_signed() - 16;
let signed = (rand::thread_rng().next_u64() % (0x1 << 16)).reinterpret_as_signed() - 16;

signed.reinterpret_as_unsigned()
})
Expand All @@ -346,7 +346,7 @@ mod tests {

for (a, e) in actual.coeffs().iter().zip(expected.coeffs().iter()) {
let err = normalized_torus_distance(a, e).abs();
assert!(err < 1e-12);
assert!(err < 1e-9);
}
}
}
Expand Down

0 comments on commit 1bf5844

Please sign in to comment.