Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sin_cos to compute twisties #370

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions sunscreen_tfhe/src/math/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ 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 +347,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
Loading