Struct rustfft::FftPlanner

source ·
pub struct FftPlanner<T: FftNum> { /* private fields */ }
Expand description

The FFT planner creates new FFT algorithm instances.

RustFFT has several FFT algorithms available. For a given FFT size, the FftPlanner decides which of the available FFT algorithms to use and then initializes them.

// Perform a forward Fft of size 1234
use std::sync::Arc;
use rustfft::{FftPlanner, num_complex::Complex};

let mut planner = FftPlanner::new();
let fft = planner.plan_fft_forward(1234);

let mut buffer = vec![Complex{ re: 0.0f32, im: 0.0f32 }; 1234];
fft.process(&mut buffer);

// The FFT instance returned by the planner has the type `Arc<dyn Fft<T>>`,
// where T is the numeric type, ie f32 or f64, so it's cheap to clone
let fft_clone = Arc::clone(&fft);

If you plan on creating multiple FFT instances, it is recommended to reuse the same planner for all of them. This is because the planner re-uses internal data across FFT instances wherever possible, saving memory and reducing setup time. (FFT instances created with one planner will never re-use data and buffers with FFT instances created by a different planner)

Each FFT instance owns Arcs to its internal data, rather than borrowing it from the planner, so it’s perfectly safe to drop the planner after creating Fft instances.

In the constructor, the FftPlanner will detect available CPU features. If AVX, SSE, Neon, or WASM SIMD are available, it will set itself up to plan FFTs with the fastest available instruction set. If no SIMD instruction sets are available, the planner will seamlessly fall back to planning non-SIMD FFTs.

If you’d prefer not to compute a FFT at all if a certain SIMD instruction set isn’t available, or otherwise specify your own custom fallback, RustFFT exposes dedicated planners for each instruction set:

If you’d prefer to opt out of SIMD algorithms, consider creating a FftPlannerScalar instead.

Implementations§

source§

impl<T: FftNum> FftPlanner<T>

source

pub fn new() -> Self

Creates a new FftPlanner instance.

source

pub fn plan_fft( &mut self, len: usize, direction: FftDirection ) -> Arc<dyn Fft<T>>

Returns a Fft instance which computes FFTs of size len.

If the provided direction is FftDirection::Forward, the returned instance will compute forward FFTs. If it’s FftDirection::Inverse, it will compute inverse FFTs.

If this is called multiple times, the planner will attempt to re-use internal data between calls, reducing memory usage and FFT initialization time.

source

pub fn plan_fft_forward(&mut self, len: usize) -> Arc<dyn Fft<T>>

Returns a Fft instance which computes forward FFTs of size len

If this is called multiple times, the planner will attempt to re-use internal data between calls, reducing memory usage and FFT initialization time.

source

pub fn plan_fft_inverse(&mut self, len: usize) -> Arc<dyn Fft<T>>

Returns a Fft instance which computes inverse FFTs of size len

If this is called multiple times, the planner will attempt to re-use internal data between calls, reducing memory usage and FFT initialization time.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for FftPlanner<T>

§

impl<T> Send for FftPlanner<T>

§

impl<T> !Sync for FftPlanner<T>

§

impl<T> Unpin for FftPlanner<T>
where T: Unpin,

§

impl<T> !UnwindSafe for FftPlanner<T>

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>,

§

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>,

§

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.