pub struct Dft { /* private fields */ }Expand description
A planned DFT of length n (n must divide p − 1).
Implementations§
Source§impl Dft
impl Dft
Sourcepub fn new(n: usize) -> Self
pub fn new(n: usize) -> Self
§Panics
If n does not divide p − 1 (no primitive n-th root in F_p).
Examples found in repository?
examples/bench.rs (line 27)
15fn main() {
16 println!("{:<26} {:>10} {:>10} {:>10}", "transform", "n", "1 thread", "auto");
17 for log in [16, 20, 22] {
18 let n = 1usize << log;
19 let mut x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
20 let (p1, pa) = (Ntt::new(n).with_threads(1), Ntt::new(n));
21 let a = time(|| p1.forward(&mut x));
22 let b = time(|| pa.forward(&mut x));
23 println!("{:<26} {:>10} {:>10.2} {:>10.2}", "Ntt", n, a, b);
24 }
25 for n in [65535usize, 255 * 4096, 65537 * 15] {
26 let x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
27 let (p1, pa) = (Dft::new(n).with_threads(1), Dft::new(n));
28 let a = time(|| { p1.forward(&x); });
29 let b = time(|| { pa.forward(&x); });
30 println!("{:<26} {:>10} {:>10.2} {:>10.2}", format!("Dft {:?}", pa.factors()), n, a, b);
31 }
32 for n in [100_000usize, 1_000_000] {
33 let q = Fp::new(3);
34 let x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
35 let c = ChirpZ::new(n, n, q);
36 println!("{:<26} {:>10} {:>10} {:>10.2}", "ChirpZ (q=3)", n, "-", time(|| { c.apply(&x); }));
37 let ic = InverseChirpZ::new(n, q);
38 println!("{:<26} {:>10} {:>10} {:>10.2}", "InverseChirpZ (q=3)", n, "-", time(|| { ic.apply(&x); }));
39 }
40}Sourcepub fn with_threads(self, threads: usize) -> Self
pub fn with_threads(self, threads: usize) -> Self
Set the number of threads (0 = automatic, the default; 1 = single-threaded).
Examples found in repository?
examples/bench.rs (line 27)
15fn main() {
16 println!("{:<26} {:>10} {:>10} {:>10}", "transform", "n", "1 thread", "auto");
17 for log in [16, 20, 22] {
18 let n = 1usize << log;
19 let mut x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
20 let (p1, pa) = (Ntt::new(n).with_threads(1), Ntt::new(n));
21 let a = time(|| p1.forward(&mut x));
22 let b = time(|| pa.forward(&mut x));
23 println!("{:<26} {:>10} {:>10.2} {:>10.2}", "Ntt", n, a, b);
24 }
25 for n in [65535usize, 255 * 4096, 65537 * 15] {
26 let x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
27 let (p1, pa) = (Dft::new(n).with_threads(1), Dft::new(n));
28 let a = time(|| { p1.forward(&x); });
29 let b = time(|| { pa.forward(&x); });
30 println!("{:<26} {:>10} {:>10.2} {:>10.2}", format!("Dft {:?}", pa.factors()), n, a, b);
31 }
32 for n in [100_000usize, 1_000_000] {
33 let q = Fp::new(3);
34 let x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
35 let c = ChirpZ::new(n, n, q);
36 println!("{:<26} {:>10} {:>10} {:>10.2}", "ChirpZ (q=3)", n, "-", time(|| { c.apply(&x); }));
37 let ic = InverseChirpZ::new(n, q);
38 println!("{:<26} {:>10} {:>10} {:>10.2}", "InverseChirpZ (q=3)", n, "-", time(|| { ic.apply(&x); }));
39 }
40}pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn factors(&self) -> &[usize]
pub fn factors(&self) -> &[usize]
The coprime factors used by Good–Thomas.
Examples found in repository?
examples/bench.rs (line 30)
15fn main() {
16 println!("{:<26} {:>10} {:>10} {:>10}", "transform", "n", "1 thread", "auto");
17 for log in [16, 20, 22] {
18 let n = 1usize << log;
19 let mut x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
20 let (p1, pa) = (Ntt::new(n).with_threads(1), Ntt::new(n));
21 let a = time(|| p1.forward(&mut x));
22 let b = time(|| pa.forward(&mut x));
23 println!("{:<26} {:>10} {:>10.2} {:>10.2}", "Ntt", n, a, b);
24 }
25 for n in [65535usize, 255 * 4096, 65537 * 15] {
26 let x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
27 let (p1, pa) = (Dft::new(n).with_threads(1), Dft::new(n));
28 let a = time(|| { p1.forward(&x); });
29 let b = time(|| { pa.forward(&x); });
30 println!("{:<26} {:>10} {:>10.2} {:>10.2}", format!("Dft {:?}", pa.factors()), n, a, b);
31 }
32 for n in [100_000usize, 1_000_000] {
33 let q = Fp::new(3);
34 let x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
35 let c = ChirpZ::new(n, n, q);
36 println!("{:<26} {:>10} {:>10} {:>10.2}", "ChirpZ (q=3)", n, "-", time(|| { c.apply(&x); }));
37 let ic = InverseChirpZ::new(n, q);
38 println!("{:<26} {:>10} {:>10} {:>10.2}", "InverseChirpZ (q=3)", n, "-", time(|| { ic.apply(&x); }));
39 }
40}Sourcepub fn forward(&self, x: &[Fp]) -> Vec<Fp>
pub fn forward(&self, x: &[Fp]) -> Vec<Fp>
y_k = Σ_j x_j ω^{jk}, ω = Fp::root_of_unity(n).
Examples found in repository?
examples/bench.rs (line 28)
15fn main() {
16 println!("{:<26} {:>10} {:>10} {:>10}", "transform", "n", "1 thread", "auto");
17 for log in [16, 20, 22] {
18 let n = 1usize << log;
19 let mut x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
20 let (p1, pa) = (Ntt::new(n).with_threads(1), Ntt::new(n));
21 let a = time(|| p1.forward(&mut x));
22 let b = time(|| pa.forward(&mut x));
23 println!("{:<26} {:>10} {:>10.2} {:>10.2}", "Ntt", n, a, b);
24 }
25 for n in [65535usize, 255 * 4096, 65537 * 15] {
26 let x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
27 let (p1, pa) = (Dft::new(n).with_threads(1), Dft::new(n));
28 let a = time(|| { p1.forward(&x); });
29 let b = time(|| { pa.forward(&x); });
30 println!("{:<26} {:>10} {:>10.2} {:>10.2}", format!("Dft {:?}", pa.factors()), n, a, b);
31 }
32 for n in [100_000usize, 1_000_000] {
33 let q = Fp::new(3);
34 let x: Vec<Fp> = (0..n as u64).map(Fp::new).collect();
35 let c = ChirpZ::new(n, n, q);
36 println!("{:<26} {:>10} {:>10} {:>10.2}", "ChirpZ (q=3)", n, "-", time(|| { c.apply(&x); }));
37 let ic = InverseChirpZ::new(n, q);
38 println!("{:<26} {:>10} {:>10} {:>10.2}", "InverseChirpZ (q=3)", n, "-", time(|| { ic.apply(&x); }));
39 }
40}Sourcepub fn forward_in_place(&self, x: &mut [Fp])
pub fn forward_in_place(&self, x: &mut [Fp])
In-place forward transform. Uses one internal buffer of n elements
when n has more than one coprime factor.
Sourcepub fn inverse_in_place(&self, x: &mut [Fp])
pub fn inverse_in_place(&self, x: &mut [Fp])
In-place inverse transform.
Sourcepub fn forward_batch(&self, data: &mut [Fp])
pub fn forward_batch(&self, data: &mut [Fp])
Forward-transform every length-n row of data, rows in parallel.
Sourcepub fn inverse_batch(&self, data: &mut [Fp])
pub fn inverse_batch(&self, data: &mut [Fp])
Inverse-transform every length-n row of data, rows in parallel.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Dft
impl Freeze for Dft
impl Move for Dft
impl RefUnwindSafe for Dft
impl Send for Dft
impl Sync for Dft
impl Unpin for Dft
impl UnsafeUnpin for Dft
impl UnwindSafe for Dft
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more