Skip to main content

FftSetup

Struct FftSetup 

Source
pub struct FftSetup { /* private fields */ }
Expand description

Owned FFTSetup handle backed by the Swift bridge.

Implementations§

Source§

impl FftSetup

Source

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}
Source

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§

Source§

impl Drop for FftSetup

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for FftSetup

Source§

impl Sync for FftSetup

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.