pub struct FftSetup { /* private fields */ }Expand description
Owned FFTSetup handle backed by the Swift bridge.
Implementations§
Source§impl FftSetup
impl FftSetup
Sourcepub fn new(log2n: usize, radix: i32) -> Option<Self>
pub fn new(log2n: usize, radix: i32) -> Option<Self>
Examples found in repository?
examples/01_vdsp_fft.rs (line 34)
6fn main() {
7 let added = add_f32(&[1.0, 2.0, 3.0], &[4.0, 5.0, 6.0]).expect("vector add failed");
8 assert!(added
9 .iter()
10 .zip([5.0_f32, 7.0, 9.0])
11 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
12
13 let added64 = add_f64(&[1.0, 2.0, 3.0], &[4.0, 5.0, 6.0]).expect("vector add f64 failed");
14 assert!(added64
15 .iter()
16 .zip([5.0_f64, 7.0, 9.0])
17 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-12));
18
19 let dot = dot_f32(&[1.0, 2.0, 3.0], &[4.0, 5.0, 6.0]).expect("dot product failed");
20 assert!((dot - 32.0).abs() < 1.0e-6);
21
22 let dot64 = dot_f64(&[1.0, 2.0, 3.0], &[4.0, 5.0, 6.0]).expect("dot product f64 failed");
23 assert!((dot64 - 32.0).abs() < 1.0e-12);
24
25 let hamm = hamming_window(8, 0);
26 let hamm64 = hamming_window_f64(8, 0);
27 let blk = blackman_window(8, 0);
28 let blk64 = blackman_window_f64(8, 0);
29 assert_eq!(hamm.len(), 8);
30 assert_eq!(hamm64.len(), 8);
31 assert_eq!(blk.len(), 8);
32 assert_eq!(blk64.len(), 8);
33
34 let setup = FftSetup::new(2, fft_radix::RADIX2).expect("failed to create FFT setup");
35 let mut real = vec![1.0_f32, 0.0, 0.0, 0.0];
36 let mut imag = vec![0.0_f32; 4];
37 setup
38 .fft_zip(&mut real, &mut imag, 2, fft_direction::FORWARD)
39 .expect("fft failed");
40
41 for value in &real {
42 assert!(
43 (*value - 1.0).abs() < 1.0e-5,
44 "unexpected FFT real output: {real:?}"
45 );
46 }
47 for value in &imag {
48 assert!(value.abs() < 1.0e-5, "unexpected FFT imag output: {imag:?}");
49 }
50
51 println!(
52 "vdsp smoke passed: added={added:?} added64={added64:?} dot={dot} dot64={dot64} fft_real={real:?}"
53 );
54}Sourcepub fn fft_zip(
&self,
real: &mut [f32],
imag: &mut [f32],
log2n: usize,
direction: i32,
) -> Result<()>
pub fn fft_zip( &self, real: &mut [f32], imag: &mut [f32], log2n: usize, direction: i32, ) -> Result<()>
Examples found in repository?
examples/01_vdsp_fft.rs (line 38)
6fn main() {
7 let added = add_f32(&[1.0, 2.0, 3.0], &[4.0, 5.0, 6.0]).expect("vector add failed");
8 assert!(added
9 .iter()
10 .zip([5.0_f32, 7.0, 9.0])
11 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-6));
12
13 let added64 = add_f64(&[1.0, 2.0, 3.0], &[4.0, 5.0, 6.0]).expect("vector add f64 failed");
14 assert!(added64
15 .iter()
16 .zip([5.0_f64, 7.0, 9.0])
17 .all(|(actual, expected)| (*actual - expected).abs() < 1.0e-12));
18
19 let dot = dot_f32(&[1.0, 2.0, 3.0], &[4.0, 5.0, 6.0]).expect("dot product failed");
20 assert!((dot - 32.0).abs() < 1.0e-6);
21
22 let dot64 = dot_f64(&[1.0, 2.0, 3.0], &[4.0, 5.0, 6.0]).expect("dot product f64 failed");
23 assert!((dot64 - 32.0).abs() < 1.0e-12);
24
25 let hamm = hamming_window(8, 0);
26 let hamm64 = hamming_window_f64(8, 0);
27 let blk = blackman_window(8, 0);
28 let blk64 = blackman_window_f64(8, 0);
29 assert_eq!(hamm.len(), 8);
30 assert_eq!(hamm64.len(), 8);
31 assert_eq!(blk.len(), 8);
32 assert_eq!(blk64.len(), 8);
33
34 let setup = FftSetup::new(2, fft_radix::RADIX2).expect("failed to create FFT setup");
35 let mut real = vec![1.0_f32, 0.0, 0.0, 0.0];
36 let mut imag = vec![0.0_f32; 4];
37 setup
38 .fft_zip(&mut real, &mut imag, 2, fft_direction::FORWARD)
39 .expect("fft failed");
40
41 for value in &real {
42 assert!(
43 (*value - 1.0).abs() < 1.0e-5,
44 "unexpected FFT real output: {real:?}"
45 );
46 }
47 for value in &imag {
48 assert!(value.abs() < 1.0e-5, "unexpected FFT imag output: {imag:?}");
49 }
50
51 println!(
52 "vdsp smoke passed: added={added:?} added64={added64:?} dot={dot} dot64={dot64} fft_real={real:?}"
53 );
54}Trait Implementations§
Auto Trait Implementations§
impl Freeze for FftSetup
impl RefUnwindSafe for FftSetup
impl Unpin for FftSetup
impl UnsafeUnpin for FftSetup
impl UnwindSafe for FftSetup
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